From 6a4b3ec0fb74d0f51a09304edfdf685ca42ef6fc Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 29 Aug 2025 01:05:00 +0200 Subject: [PATCH] Simplify some code --- lib/codecr.gi | 2 +- lib/codecstr.gi | 4 ++-- lib/codegen.gi | 2 +- lib/codeman.gi | 8 ++++---- lib/curves.gi | 8 ++------ lib/decoders.gi | 2 +- lib/matrices.gi | 4 ++-- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/codecr.gi b/lib/codecr.gi index eaf94b4..e34793d 100644 --- a/lib/codecr.gi +++ b/lib/codecr.gi @@ -43,7 +43,7 @@ CalculateLinearCodeCoveringRadius := function( code ) # (old version had line above in place of next 5) H:=CheckMat(code); CLs:=GuavaCosetLeadersMatFFE(H,LeftActingDomain(code)); - wts:=List([1..Length(CLs)],i->WeightVecFFE(CLs[i])); + wts:=List(CLs, WeightVecFFE); rho:=Maximum(wts); return rho; fi; diff --git a/lib/codecstr.gi b/lib/codecstr.gi index a68ca0e..6919017 100644 --- a/lib/codecstr.gi +++ b/lib/codecstr.gi @@ -97,8 +97,8 @@ function(C, D, check) NewH := List( [ 2..Length( H ) ], x -> H[ x ] ); # throw away the first column of H' (it is (1, 0, ..., 0), # the one is already present in the new generator matrix) - NewH := List( [ 1..Length( NewH ) ], x -> List( - [ 2 .. WordLength( D ) ], y -> NewH[ x ][ y ] ) ); + NewH := List( NewH, x -> List( + [ 2 .. WordLength( D ) ], y -> x[ y ] ) ); # fill the lower left part with zeroes Nulmat := List( [ 1 .. Dimension( D ) - 1 ], x -> NullVector( WordLength( C ) , LeftActingDomain(C) ) ); diff --git a/lib/codegen.gi b/lib/codegen.gi index 13f9bbe..7bec9b6 100644 --- a/lib/codegen.gi +++ b/lib/codegen.gi @@ -1903,7 +1903,7 @@ function(n, L, F) fi; p := Characteristic(Field(L)); CC:=CyclotomicCosets(p,q-1); - CCz:=List([1..Length(CC)],i->List(CC[i],j->z^j)); + CCz:=List(CC,cc->List(cc,j->z^j)); ## this is the set of cyclotomic cosets, represented ## as powers of a primitive element z powerlist := []; diff --git a/lib/codeman.gi b/lib/codeman.gi index 2df711e..6fb8c12 100644 --- a/lib/codeman.gi +++ b/lib/codeman.gi @@ -2138,7 +2138,7 @@ __G_BZCode := function(O, I) VectorRep := function(e, F) local a, f, MF; if IsZero(e) then; - return List([1..LogInt(Size(F), Characteristic(F))], i->Zero(GF(Characteristic(F)))); + return List([1..DegreeOverPrimeField(F)], i->Zero(GF(Characteristic(F)))); fi; a := PrimitiveElement(F); f := MinimalPolynomial( GF(Characteristic(F)), a); @@ -2152,17 +2152,17 @@ __G_BZCode := function(O, I) fi; # Make sure list O (outer codes) contains all linear codes - if (PositionNot( List([1..Size(O)], i->IsLinearCode(O[i])), true ) < Size(O)) then + if not ForAll(O, IsLinearCode) then Error("The list O contains non linear code(s)\n"); fi; # Make sure list I (inner codes) contains all linear codes - if (PositionNot( List([1..Size(I)], i->IsLinearCode(I[i])), true ) < Size(I)) then + if not ForAll(I, IsLinearCode) then Error("The list I contains non linear code(s)\n"); fi; # Make sure that all outer codes have the same length - if (PositionNot(List([1..Size(O)], i->CodeLength(O[i])), CodeLength(O[1])) < Size(O)) then + if Length(Set(O, CodeLength)) > 1 then Error("Code lengths of all outer codes are required to be the same\n"); fi; diff --git a/lib/curves.gi b/lib/curves.gi index 771cf66..bfbddb4 100644 --- a/lib/curves.gi +++ b/lib/curves.gi @@ -140,9 +140,7 @@ local partsf,monsf,vars,deg,i,j; partsf:=ConstituentsPolynomial(f); # varsf:=partsf.variables; monsf:=partsf.monomials; - deg:=List([1..Length(monsf)],i-> - List([1..Length(vars)],j-> - [monsf[i],vars[j],DegreeIndeterminate(monsf[i],vars[j])])); + deg:=List(monsf,mon->List(vars,var->[mon,var,DegreeIndeterminate(mon,var)])); return deg; end); @@ -161,9 +159,7 @@ local partsf,monsf,vars,deg,i,j; partsf:=ConstituentsPolynomial(f); # varsf:=partsf.variables; monsf:=partsf.monomials; - deg:=List([1..Length(monsf)],i-> - Sum(List([1..Length(vars)],j-> - DegreeIndeterminate(monsf[i],vars[j])))); + deg:=List(monsf,mon->Sum(vars,var->DegreeIndeterminate(mon,var))); return Maximum(deg); end); diff --git a/lib/decoders.gi b/lib/decoders.gi index a300bad..0f17b6b 100644 --- a/lib/decoders.gi +++ b/lib/decoders.gi @@ -361,7 +361,7 @@ function (C, r) fi; x := Indeterminate(F); if q = 2 then # error locator is not necessary - pol := Sum(List([1..Length(ErrorLocator)], i->x^ErrorLocator[i])); + pol := Sum(List(ErrorLocator, i->x^i)); return Codeword((r - pol) mod (x^n-1), C); else pol := Derivative(sigma); diff --git a/lib/matrices.gi b/lib/matrices.gi index 9b12481..303f866 100644 --- a/lib/matrices.gi +++ b/lib/matrices.gi @@ -321,10 +321,10 @@ function(arg) if Length(arg) = 1 then M:=arg[1]; else - M:=List([1..Length(arg)],i->arg[i]); + M:=arg; fi; n:=Length(M); - if ( n >= Length(M[1]) ) or not ForAll(M, i-> IsLatinSquare(i)) then + if n >= Length(M[1]) or not ForAll(M, IsLatinSquare) then return false; #this is right fi; q2 := Length(M[1])^2;