@@ -1718,7 +1718,7 @@ def _syndrome(self, r):
1718
1718
1719
1719
def _forney_formula (self , error_evaluator , error_locator ):
1720
1720
r"""
1721
- Returns the error vector computed through Forney's formula.
1721
+ Returns the error vector computed through Forney's formula as a list .
1722
1722
1723
1723
INPUT:
1724
1724
@@ -1737,7 +1737,7 @@ def _forney_formula(self, error_evaluator, error_locator):
1737
1737
sage: R.<x> = F[]
1738
1738
sage: evaluator, locator = R(10), R([10, 10])
1739
1739
sage: D._forney_formula(evaluator, locator)
1740
- ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)
1740
+ [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
1741
1741
"""
1742
1742
C = self .code ()
1743
1743
alphas = C .evaluation_points ()
@@ -1754,7 +1754,7 @@ def _forney_formula(self, error_evaluator, error_locator):
1754
1754
else :
1755
1755
e .append (zero )
1756
1756
1757
- return vector ( F , e )
1757
+ return e
1758
1758
1759
1759
def decode_to_code (self , r ):
1760
1760
r"""
@@ -1775,31 +1775,59 @@ def decode_to_code(self, r):
1775
1775
1776
1776
EXAMPLES::
1777
1777
1778
- sage: F = GF(11 )
1779
- sage: n, k = 10, 5
1778
+ sage: F = GF(59 )
1779
+ sage: n, k = 40, 12
1780
1780
sage: C = codes.GeneralizedReedSolomonCode(F.list()[1:n+1], k)
1781
1781
sage: D = codes.decoders.GRSKeyEquationSyndromeDecoder(C)
1782
- sage: r = vector(F, (8, 2, 6, 10, 6, 10, 7, 6, 7, 2))
1783
- sage: D.decode_to_code(r)
1784
- (8, 2, 6, 10, 6, 10, 7, 6, 7, 1)
1782
+ sage: c = C.random_element()
1783
+ sage: Chan = channels.StaticErrorRateChannel(C.ambient_space(), D.decoding_radius())
1784
+ sage: y = Chan(c)
1785
+ sage: c == D.decode_to_code(y)
1786
+ True
1787
+
1788
+ TESTS:
1789
+
1790
+ If one tries to decode a word with too many errors, it returns
1791
+ an exception::
1792
+
1793
+ sage: Chan = channels.StaticErrorRateChannel(C.ambient_space(), D.decoding_radius()+1)
1794
+ sage: y = Chan(c)
1795
+ sage: D.decode_to_message(y)
1796
+ Traceback (most recent call last):
1797
+ ...
1798
+ DecodingError: Decoding failed because the number of errors exceeded the decoding radius
1799
+
1800
+ If one tries to decode something which is not in the ambient space of the code,
1801
+ an exception is raised::
1802
+
1803
+ sage: D.decode_to_code(42)
1804
+ Traceback (most recent call last):
1805
+ ...
1806
+ ValueError: The word to decode has to be in the ambient space of the code
1785
1807
"""
1786
1808
C = self .code ()
1809
+ if r not in C .ambient_space ():
1810
+ raise ValueError ("The word to decode has to be in the ambient space of the code" )
1787
1811
F = C .base_field ()
1788
1812
PolRing = C .base_field ()['x' ]
1789
1813
x = PolRing .gen ()
1790
1814
1791
- if C .length () == C .dimension ():
1792
- return r
1793
- if r in C :
1815
+ if C .length () == C .dimension () or r in C :
1794
1816
return r
1795
1817
1796
- S = PolRing (self .syndrome (r ))
1818
+ S = PolRing (self ._syndrome (r ))
1797
1819
a = x ** (C .minimum_distance () - 1 )
1798
1820
1799
1821
(EEP , ELP ) = self ._partial_xgcd (a , S , PolRing )
1800
1822
1801
- e = self .forney_formula (EEP , ELP )
1802
- return r - e
1823
+ e = self ._forney_formula (EEP , ELP )
1824
+ dec = []
1825
+ for i in range (len (r )):
1826
+ dec .append (r [i ] - e [i ])
1827
+ dec = vector (F , dec )
1828
+ if not dec in C :
1829
+ raise DecodingError ("Decoding failed because the number of errors exceeded the decoding radius" )
1830
+ return dec
1803
1831
1804
1832
def decode_to_message (self , r ):
1805
1833
r"""
@@ -1821,13 +1849,15 @@ def decode_to_message(self, r):
1821
1849
1822
1850
EXAMPLES::
1823
1851
1824
- sage: F = GF(11 )
1825
- sage: n, k = 10, 5
1852
+ sage: F = GF(59 )
1853
+ sage: n, k = 40, 12
1826
1854
sage: C = codes.GeneralizedReedSolomonCode(F.list()[1:n+1], k)
1827
1855
sage: D = codes.decoders.GRSKeyEquationSyndromeDecoder(C)
1828
- sage: r = vector(F, (8, 2, 6, 10, 6, 10, 7, 6, 7, 2))
1829
- sage: D.decode_to_message(r)
1830
- (3, 6, 6, 3, 1)
1856
+ sage: c = C.random_element()
1857
+ sage: Chan = channels.StaticErrorRateChannel(C.ambient_space(), D.decoding_radius())
1858
+ sage: y = Chan(c)
1859
+ sage: D.connected_encoder().unencode(c) == D.decode_to_message(y)
1860
+ True
1831
1861
"""
1832
1862
C = self .code ()
1833
1863
if C .length () == C .dimension ():
0 commit comments