Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some uses of FOO[Length(FOO)] by Last(FOO) #5655

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hpcgap/lib/cmdleditx.g
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
hist := CommandLineHistory;
if key = 0 then # save line data
# no trailing white space
while Length(l[1]) > 0 and l[1][Length(l[1])] in "\n\r\t " do
while Length(l[1]) > 0 and Last(l[1]) in "\n\r\t " do

Check warning on line 128 in hpcgap/lib/cmdleditx.g

View check run for this annotation

Codecov / codecov/patch

hpcgap/lib/cmdleditx.g#L128

Added line #L128 was not covered by tests
Remove(l[1]);
od;
MaxCommandLineHistory := UserPreference("HistoryMaxLines");
Expand Down
14 changes: 7 additions & 7 deletions lib/ctbl.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@
InstallGlobalFunction( CharacterTable_IsNilpotentFactor, function( tbl, N )
local series;
series:= CharacterTable_UpperCentralSeriesFactor( tbl, N );
return Length( series[ Length( series ) ] ) = NrConjugacyClasses( tbl );
return Length( Last(series) ) = NrConjugacyClasses( tbl );
end );


Expand All @@ -1245,7 +1245,7 @@
function( tbl )
local series;
series:= ClassPositionsOfUpperCentralSeries( tbl );
return Length( series[ Length( series ) ] ) = NrConjugacyClasses( tbl );
return Length( Last(series) ) = NrConjugacyClasses( tbl );

Check warning on line 1248 in lib/ctbl.gi

View check run for this annotation

Codecov / codecov/patch

lib/ctbl.gi#L1248

Added line #L1248 was not covered by tests
end );


Expand Down Expand Up @@ -3300,7 +3300,7 @@
if i = r[1] or i-1 in hlines then
Append( str, " \\rule[0pt]{0pt}{13pt}" );
fi;
if i = r[ Length( r ) ] or i in hlines then
if i = Last(r) or i in hlines then

Check warning on line 3303 in lib/ctbl.gi

View check run for this annotation

Codecov / codecov/patch

lib/ctbl.gi#L3303

Added line #L3303 was not covered by tests
Append( str, " \\rule[-7pt]{0pt}{5pt}" );
fi;

Expand Down Expand Up @@ -4712,7 +4712,7 @@
n:= QuoInt(n-1, ll);
od;
Add( irrnames, name );
return irrnames[ Length( irrnames ) ];
return name;

elif ( IsList( entry ) and not IsString( entry ) )
or IsUnknown( entry ) then
Expand Down Expand Up @@ -5430,7 +5430,7 @@
for j in [ 1 .. Length( info ) - 1 ] do
Print( "\"", info[j], "\\n\",\n" );
od;
Print( "\"", info[ Length( info ) ], "\"\n]);\n" );
Print( "\"", Last(info), "\"\n]);\n" );

Check warning on line 5433 in lib/ctbl.gi

View check run for this annotation

Codecov / codecov/patch

lib/ctbl.gi#L5433

Added line #L5433 was not covered by tests
else
Print( "\"", info, "\";\n" );
fi;
Expand Down Expand Up @@ -7001,7 +7001,7 @@

# Check the arguments.
if not ( Length( arg ) in [ 2, 3 ] and IsOrdinaryTable( arg[1] ) and
IsList( arg[ Length( arg ) ] ) and
IsList( Last(arg) ) and

Check warning on line 7004 in lib/ctbl.gi

View check run for this annotation

Codecov / codecov/patch

lib/ctbl.gi#L7004

Added line #L7004 was not covered by tests
( Length( arg ) = 2 or IsOrdinaryTable( arg[2] ) ) ) then
Error( "usage: SortedCharacterTable( <tbl>, <kernel> ) resp.\n",
" SortedCharacterTable( <tbl>, <normalseries> ) resp.\n",
Expand Down Expand Up @@ -7048,7 +7048,7 @@
# if the `i'--th irreducible contains none of `kernels' in its kernel,
# we have `list[i] = -1',
# for an irreducible with kernel containing
# `kernels[ Length( kernels ) ]',
# `Last(kernels)',
# the value is `-(Length( kernels ) + 1)'.
list:= [];
if HasIrr( tbl ) then
Expand Down
2 changes: 1 addition & 1 deletion lib/gpfpiso.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2623,7 +2623,7 @@
if IsOddInt(i) then x:=(i+1)/2;
else x:=-i/2;fi;
# word must be freely cancelled
if Length(g)>0 and x=-g[Length(g)] then
if Length(g)>0 and x=-Last(g) then

Check warning on line 2626 in lib/gpfpiso.gi

View check run for this annotation

Codecov / codecov/patch

lib/gpfpiso.gi#L2626

Added line #L2626 was not covered by tests
Remove(g);
else Add(g,x); fi;
od;
Expand Down
61 changes: 32 additions & 29 deletions lib/grp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@
S := LowerCentralSeriesOfGroup( G );

# <G> is nilpotent if the lower central series reaches the trivial group
return IsTrivial( S[ Length( S ) ] );
return IsTrivial( Last(S) );
end );


Expand Down Expand Up @@ -710,7 +710,7 @@
fi;

der:= DerivedSeriesOfGroup( G );
der:= der[ Length( der ) ];
der:= Last(der);

Check warning on line 713 in lib/grp.gi

View check run for this annotation

Codecov / codecov/patch

lib/grp.gi#L713

Added line #L713 was not covered by tests
if IsTrivial( der ) then
return false;
fi;
Expand Down Expand Up @@ -797,7 +797,7 @@
S := DerivedSeriesOfGroup( G );

# the group is solvable if the derived series reaches the trivial group
isSolvable := IsTrivial( S[ Length( S ) ] );
isSolvable := IsTrivial( Last(S) );

# set IsAbelian filter
isAbelian := isSolvable and Length( S ) <= 2;
Expand Down Expand Up @@ -1017,16 +1017,16 @@
od;
while i<=Length(ser) and not IsSubset(sub,ser[i]) do
c:=ClosureGroup(sub,ser[i]);
if Size(new[Length(new)])>Size(c) then
if Size(Last(new))>Size(c) then
Add(new,c);
fi;
if Size(new[Length(new)])>Size(ser[i]) then
if Size(Last(new))>Size(ser[i]) then
Add(new,ser[i]);
fi;
sub:=Intersection(sub,ser[i]);
i:=i+1;
od;
if Size(sub)<Size(new[Length(new)]) and i<=Length(ser) and Size(sub)>Size(ser[i]) then
if Size(sub)<Size(Last(new)) and i<=Length(ser) and Size(sub)>Size(ser[i]) then
Add(new,sub);
fi;
while i<=Length(ser) do
Expand Down Expand Up @@ -1087,7 +1087,7 @@
TryNextMethod();
fi;
der := DerivedSeriesOfGroup(grp);
if not IsTrivial(der[Length(der)]) then
if not IsTrivial(Last(der)) then
TryNextMethod();
fi;

Expand Down Expand Up @@ -1153,9 +1153,9 @@
rev:=[j];
i:=post-1;
repeat
if not IsSubset(rev[Length(rev)],cs[i]) then
if not IsSubset(Last(rev),cs[i]) then
c:=ClosureGroup(cs[i],j);
if Size(c)>Size(rev[Length(rev)]) then
if Size(c)>Size(Last(rev)) then
# proper down step
Add(rev,c);
fi;
Expand All @@ -1167,9 +1167,9 @@

i:=pre;
repeat
if not IsSubset(cs[i],new[Length(new)]) then
if not IsSubset(cs[i],Last(new)) then
c:=Intersection(cs[i],j);
if Size(c)<Size(new[Length(new)]) then
if Size(c)<Size(Last(new)) then
# proper down step
Add(new,c);
fi;
Expand Down Expand Up @@ -1223,6 +1223,7 @@
[ IsGroup ],
function ( G )
local S, # derived series of <G>, result
lastS, # last element of S
D; # derived subgroups

# print out a warning for infinite groups
Expand All @@ -1234,26 +1235,28 @@

# compute the series by repeated calling of `DerivedSubgroup'
S := [ G ];
lastS := G;
Info( InfoGroup, 2, "DerivedSeriesOfGroup: step ", Length(S) );
D := DerivedSubgroup( G );

while
(not HasIsTrivial(S[Length(S)]) or
not IsTrivial(S[Length(S)])) and
(not HasIsTrivial(lastS) or
not IsTrivial(lastS)) and
(
(not HasIsPerfectGroup(S[Length(S)]) and
not HasAbelianInvariants(S[Length(S)]) and D <> S[ Length(S) ]) or
(HasIsPerfectGroup(S[Length(S)]) and not IsPerfectGroup(S[Length(S)]))
or (HasAbelianInvariants(S[Length(S)])
and Length(AbelianInvariants(S[Length(S)])) > 0)
(not HasIsPerfectGroup(lastS) and
not HasAbelianInvariants(lastS) and D <> lastS) or
(HasIsPerfectGroup(lastS) and not IsPerfectGroup(lastS))
or (HasAbelianInvariants(lastS)
and Length(AbelianInvariants(lastS)) > 0)
) do
Add( S, D );
lastS := D;
Info( InfoGroup, 2, "DerivedSeriesOfGroup: step ", Length(S) );
D := DerivedSubgroup( D );
od;

# set filters if the last term is known to be trivial
if HasIsTrivial(S[Length(S)]) and IsTrivial(S[Length(S)]) then
if HasIsTrivial(lastS) and IsTrivial(lastS) then
SetIsSolvableGroup(G, true);
if Length(S) <=2 then
Assert(3, IsAbelian(G));
Expand Down Expand Up @@ -1617,7 +1620,7 @@
S := [ G ];
Info( InfoGroup, 2, "LowerCentralSeriesOfGroup: step ", Length(S) );
C := DerivedSubgroup( G );
while C <> S[ Length(S) ] do
while C <> Last(S) do
Add( S, C );
Info( InfoGroup, 2, "LowerCentralSeriesOfGroup: step ", Length(S) );
C := CommutatorSubgroup( G, C );
Expand Down Expand Up @@ -2331,15 +2334,15 @@
S := [ TrivialSubgroup( G ) ];
Info( InfoGroup, 2, "UpperCentralSeriesOfGroup: step ", Length(S) );
C := Centre( G );
while C <> S[ Length(S) ] do
while C <> Last(S) do

Check warning on line 2337 in lib/grp.gi

View check run for this annotation

Codecov / codecov/patch

lib/grp.gi#L2337

Added line #L2337 was not covered by tests
Add( S, C );
Info( InfoGroup, 2, "UpperCentralSeriesOfGroup: step ", Length(S) );
hom := NaturalHomomorphismByNormalSubgroupNC( G, C );
C := PreImages( hom, Centre( Image( hom ) ) );
od;

if S[ Length(S) ] = G then
UseIsomorphismRelation( G, S[ Length(S) ] );
if Last(S) = G then
UseIsomorphismRelation( G, Last(S) );

Check warning on line 2345 in lib/grp.gi

View check run for this annotation

Codecov / codecov/patch

lib/grp.gi#L2344-L2345

Added lines #L2344 - L2345 were not covered by tests
fi;
# return the series when it becomes stable
return Reversed( S );
Expand Down Expand Up @@ -2977,7 +2980,7 @@
local ser;

ser := LowerCentralSeriesOfGroup( G );
return Size ( ser[ Length( ser ) ] ) mod p <> 0;
return Size( Last(ser) ) mod p <> 0;
end );

RedispatchOnCondition (IsPNilpotentOp, ReturnTrue, [IsGroup, IsPosInt], [IsFinite], 0);
Expand Down Expand Up @@ -3336,13 +3339,13 @@
for j in p do
u:=ClosureGroup(u,SylowSubgroup(d[i-1],j));
#force elementary
while not ForAll(GeneratorsOfGroup(u),x->x^j in loc[Length(loc)]) do
r:=NaturalHomomorphismByNormalSubgroupNC(u,loc[Length(loc)]);
while not ForAll(GeneratorsOfGroup(u),x->x^j in Last(loc)) do
r:=NaturalHomomorphismByNormalSubgroupNC(u,Last(loc));
Pker:=Omega(Range(r),j,1);
r:=PreImage(r,Pker);
Add(loc,r);
od;
if Size(u)<Size(ser[Length(ser)]) then
if Size(u)<Size(Last(ser)) then
Add(loc,u);
fi;
od;
Expand Down Expand Up @@ -3371,7 +3374,7 @@
S := [ G ];
Info( InfoGroup, 2, "SubnormalSeries: step ", Length(S) );
C := NormalClosure( G, U );
while C <> S[ Length( S ) ] do
while C <> Last(S) do

Check warning on line 3377 in lib/grp.gi

View check run for this annotation

Codecov / codecov/patch

lib/grp.gi#L3377

Added line #L3377 was not covered by tests
Add( S, C );
Info( InfoGroup, 2, "SubnormalSeries: step ", Length(S) );
C := NormalClosure( C, U );
Expand All @@ -3392,7 +3395,7 @@
function ( G, U )
local s;
s:=SubnormalSeries(G,U);
return U=s[Length(s)];
return U=Last(s);

Check warning on line 3398 in lib/grp.gi

View check run for this annotation

Codecov / codecov/patch

lib/grp.gi#L3398

Added line #L3398 was not covered by tests
end);


Expand Down
2 changes: 1 addition & 1 deletion lib/grpfp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -4772,7 +4772,7 @@ local g,i,x;
x:=-i/2;
fi;
# free cancellation
if Length(g)>0 and x=-g[Length(g)] then
if Length(g)>0 and x=-Last(g) then
Remove(g);
else
Add(g,x);
Expand Down
22 changes: 11 additions & 11 deletions lib/grplatt.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@
[IsGroup],0,
function(G)
G := DerivedSeriesOfGroup(G);
G := G[Length(G)];
G := Last(G);
SetIsPerfectGroup(G, true);
return G;
end);
Expand Down Expand Up @@ -2052,7 +2052,7 @@
vs:=[];
if Length(mat)>0 then
for k in AsList(VectorSpace(ocr.field,mat)) do
if IsOne(k[Length(k)]) then
if IsOne(Last(k)) then

Check warning on line 2055 in lib/grplatt.gi

View check run for this annotation

Codecov / codecov/patch

lib/grplatt.gi#L2055

Added line #L2055 was not covered by tests
Add(vs,k{[1..Length(vsb)]}*vsb);
fi;
od;
Expand Down Expand Up @@ -3874,22 +3874,22 @@

if Length(l)=0 then
# no groups there. Start getting new ones
a:=Filtered(process,x->Size(x)>=divs[Length(divs)]);
process:=Filtered(process,x->Size(x)<divs[Length(divs)]);
a:=Filtered(process,x->Size(x)>=Last(divs));
process:=Filtered(process,x->Size(x)<Last(divs));
for j in a do
m:=maxer(j);
Append(l,m);
od;
SortBy(l,Size);
fi;

if Size(l[Length(l)])<divs[Length(divs)] then
if Size(Last(l))<Last(divs) then
# new size.

if Length(process)>0
and Size(process[Length(process)])<=limit then
and Size(Last(process))<=limit then
# switch to lattice
a:=Size(l[Length(l)]);
a:=Size(Last(l));

Check warning on line 3892 in lib/grplatt.gi

View check run for this annotation

Codecov / codecov/patch

lib/grplatt.gi#L3892

Added line #L3892 was not covered by tests
Info(InfoLattice,1,"get full lattice @size ",a);
l:=List(ConjugacyClassesSubgroups(G),Representative);
l:=Filtered(l,x->Size(x)<=a and
Expand All @@ -3900,7 +3900,7 @@
fi;

while Length(process)>0
and Size(process[Length(process)])>=Maximum(List(l,Size)) do
and Size(Last(process))>=Maximum(List(l,Size)) do
# need to process those that could give next size (or
# larger)
a:=Remove(process);
Expand All @@ -3910,14 +3910,14 @@
SortBy(l,Size);

# delete the orders not used any more
while Length(l)>0 and Size(l[Length(l)])<divs[Length(divs)] do
while Length(l)>0 and Size(Last(l))<Last(divs) do
Remove(divs); # sizes still in play
od;
done:=[]; # can ignore anything larger

if mode=1 then
a:=Filtered(l,x->Size(x)=divs[Length(divs)]);
l:=Filtered(l,x->Size(x)<divs[Length(divs)]);
a:=Filtered(l,x->Size(x)=Last(divs));
l:=Filtered(l,x->Size(x)<Last(divs));
a:=List(SubgroupsOrbitsAndNormalizers(G,a,false),
x->x.representative);
Append(l,a);
Expand Down
2 changes: 1 addition & 1 deletion lib/grppcatr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ BindGlobal( "MinimalGensLayer", function( pcgs, pcgsS, pcgsN, min )
if Length( pcgsM ) <> Length( pcgsL ) then
Add( series, pcgsM );
fi;
pcgsL := series[Length(series)];
pcgsL := Last(series);

# modify minimal gens
ModifyMinGens( pcgs, pcgsS, pcgsL, min );
Expand Down
Loading
Loading