6161InstallMethod(Decode, " method for linear code, codeword" , true ,
6262 [ IsLinearCode, IsCodeword] , 0 ,
6363function (C, v )
64- local c, S, syn, index, corr, Gt, i, x, F;
64+ local ok, c, S, syn, index, corr, Gt, i, x, F;
6565 if v in C then
6666 return InformationWord(C,v);
6767 fi ;
@@ -72,10 +72,16 @@ function(C, v)
7272 F := LeftActingDomain(C);
7373 S := SyndromeTable(C);
7474 syn := Syndrome(C, c);
75- index := 0 ;
76- repeat
77- index := index + 1 ;
78- until S[ index][ 2 ] = syn;
75+ ok := false ;
76+ for index in [ 1 .. Length(S)] do
77+ if IsBound (S[ index] ) and S[ index][ 2 ] = syn then
78+ ok := true ;
79+ break ;
80+ fi ;
81+ od ;
82+ if not ok then # this should never happen!
83+ Error(" In Decodeword: index not found" );
84+ fi ;
7985# This is a hack. The subtraction operation for codewords is causing an error
8086# and rather than trying to understand the method selection process, I'm brute-
8187# forcing things...
@@ -135,7 +141,7 @@ end);
135141InstallMethod(Decodeword, " method for linear code, codeword" , true ,
136142 [ IsLinearCode, IsCodeword] , 0 ,
137143function (C, v )
138- local c, c0, S, syn, index, corr, Gt, i, x, F;
144+ local ok, c, c0, S, syn, index, corr, Gt, i, x, F;
139145 if v in C then
140146 return v;
141147 fi ;
@@ -153,10 +159,16 @@ function(C, v)
153159 F := LeftActingDomain(C);
154160 S := SyndromeTable(C);
155161 syn := Syndrome(C, c);
156- index := 0 ;
157- repeat
158- index := index + 1 ;
159- until S[ index][ 2 ] = syn;
162+ ok := false ;
163+ for index in [ 1 .. Length(S)] do
164+ if IsBound (S[ index] ) and S[ index][ 2 ] = syn then
165+ ok := true ;
166+ break ;
167+ fi ;
168+ od ;
169+ if not ok then # this should never happen!
170+ Error(" In Decodeword: index not found" );
171+ fi ;
160172 corr := VectorCodeword(c - S[ index][ 1 ] ); # correct codeword
161173 return Codeword(corr,F);
162174end );
0 commit comments