From 3521dbefbb660c4d50c2615494f165f49d8ad96d Mon Sep 17 00:00:00 2001 From: stertooy <5571903+stertooy@users.noreply.github.com> Date: Mon, 12 Oct 2026 17:05:19 +0200 Subject: [PATCH 1/2] Another small optimisation for AddToIgs code Skip adjustment in AddToIgs if there is no need for it Assisted-by: Claude Code (Opus 5.5, Fable 5.1) --- gap/basic/pcppara.gi | 13 ++++++++++++- gap/basic/pcppcps.gi | 26 ++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/gap/basic/pcppara.gi b/gap/basic/pcppara.gi index 66cd6b2e..b170143d 100644 --- a/gap/basic/pcppara.gi +++ b/gap/basic/pcppara.gi @@ -113,7 +113,7 @@ end ); InstallGlobalFunction( AddToIgsParallel, function( pcs, gens, ppcs, pgens ) local coll, rels, n, todo, tododo, ind, indd, g, gg, d, h, hh, k, - c, i, r, sub, val, j, f, nrmd, pairs; + c, i, r, sub, val, j, f, nrmd, pairs, added; if Length( gens ) = 0 then return [pcs, ppcs]; fi; @@ -132,6 +132,9 @@ function( pcs, gens, ppcs, pgens ) indd[d] := ppcs[i]; od; + # initial gens still need to be reduced + added := true; + # do a reduction step c := TailLimit(ind, c); sub := Filtered([1..Length(gens)], i -> Depth(gens[i]) < c); @@ -145,6 +148,7 @@ function( pcs, gens, ppcs, pgens ) j := PositionMinimum(val); g := Remove(todo, j); gg := Remove(tododo, j); + Remove(val, j); d := Depth( g ); f := []; @@ -182,11 +186,15 @@ function( pcs, gens, ppcs, pgens ) d := Depth(g); od; + # only adjust if needed + if Length(f) = 0 and not added then continue; fi; + # adjust c := TailLimit(ind, c); ReduceExpoPara(ind, todo, indd, tododo, rels); # add powers and commutators + added := false; for d in f do g := ind[d]; gg := indd[d]; @@ -196,6 +204,7 @@ function( pcs, gens, ppcs, pgens ) if Depth(k) < c then Add(todo, k); Add(tododo, gg^r); + added := true; fi; fi; for j in [1..n] do @@ -207,12 +216,14 @@ function( pcs, gens, ppcs, pgens ) if Depth(k) < c then Add(todo, k); Add(tododo, Comm(gg, indd[j])); + added := true; fi; if rels[j] = 0 then k := Comm(g, ind[j]^-1); if Depth(k) < c then Add(todo, k); Add(tododo, Comm(gg, indd[j]^-1)); + added := true; fi; fi; fi; diff --git a/gap/basic/pcppcps.gi b/gap/basic/pcppcps.gi index 4f04b2f8..fb2c4605 100644 --- a/gap/basic/pcppcps.gi +++ b/gap/basic/pcppcps.gi @@ -134,7 +134,8 @@ end ); #F AddToIgs( , ) ## InstallGlobalFunction(AddToIgs, function(igs, gens) - local coll, rels, n, c, ind, g, d, todo, val, j, f, h, k, pair, t; + local coll, rels, n, c, ind, g, d, todo, val, j, f, h, k, pair, t, + added; if Length(gens) = 0 then return igs; fi; @@ -148,6 +149,9 @@ InstallGlobalFunction(AddToIgs, function(igs, gens) ind := ListWithIdenticalEntries(n, false); for g in igs do ind[Depth(g)] := g; od; + # initial gens still need to be reduced + added := true; + # do a reduction step c := TailLimit(ind, c); todo := Set(Filtered(gens, x -> Depth(x) < c)); @@ -157,6 +161,7 @@ InstallGlobalFunction(AddToIgs, function(igs, gens) while Length(todo) > 0 and c > 1 do j := PositionMinimum(val); g := Remove(todo, j); + Remove(val, j); d := Depth(g); f := []; @@ -184,17 +189,24 @@ InstallGlobalFunction(AddToIgs, function(igs, gens) d := Depth(g); od; + # only adjust if needed + if Length(f) = 0 and not added then continue; fi; + # adjust c := TailLimit(ind, c); ReduceExpo(ind, todo, rels); # add powers and commutators + added := false; for d in f do g := ind[d]; # skip infinite factors and powers in the tail if d < c-1 and rels[d] > 0 then k := g ^ RelativeOrderPcp(g); - if Depth(k) < c then Add(todo, k); fi; + if Depth(k) < c then + Add(todo, k); + added := true; + fi; fi; for j in [1..n] do # skip trivial commutators and those in the tail @@ -203,10 +215,16 @@ InstallGlobalFunction(AddToIgs, function(igs, gens) fi; if not IsBool(ind[j]) then k := Comm(g, ind[j]); - if Depth(k) < c then Add(todo, k); fi; + if Depth(k) < c then + Add(todo, k); + added := true; + fi; if rels[j] = 0 then k := Comm(g, ind[j]^-1); - if Depth(k) < c then Add(todo, k); fi; + if Depth(k) < c then + Add(todo, k); + added := true; + fi; fi; fi; od; From ca5c88bc2f10599a774c9dbbe0d028ee49af75f5 Mon Sep 17 00:00:00 2001 From: stertooy <5571903+stertooy@users.noreply.github.com> Date: Sat, 17 Oct 2026 09:12:51 +0200 Subject: [PATCH 2/2] Apply batched suggestions from code review Co-authored-by: Max Horn --- gap/basic/pcppara.gi | 3 ++- gap/basic/pcppcps.gi | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gap/basic/pcppara.gi b/gap/basic/pcppara.gi index b170143d..295ce711 100644 --- a/gap/basic/pcppara.gi +++ b/gap/basic/pcppara.gi @@ -186,7 +186,8 @@ function( pcs, gens, ppcs, pgens ) d := Depth(g); od; - # only adjust if needed + # ind unchanged and every todo entry already reduced, so ReduceExpo, + # TailLimit and the filter would be no-ops if Length(f) = 0 and not added then continue; fi; # adjust diff --git a/gap/basic/pcppcps.gi b/gap/basic/pcppcps.gi index fb2c4605..364f7d33 100644 --- a/gap/basic/pcppcps.gi +++ b/gap/basic/pcppcps.gi @@ -189,7 +189,8 @@ InstallGlobalFunction(AddToIgs, function(igs, gens) d := Depth(g); od; - # only adjust if needed + # ind unchanged and every todo entry already reduced, so ReduceExpo, + # TailLimit and the filter would be no-ops if Length(f) = 0 and not added then continue; fi; # adjust