From 89346928278269c1788452a63ec606810a7943db Mon Sep 17 00:00:00 2001 From: stertooy <5571903+stertooy@users.noreply.github.com> Date: Mon, 12 Oct 2026 16:02:15 +0200 Subject: [PATCH] More mini-optimisations for AddToIgs code Avoid calling GcdPcp(Para) when it will not do anything Assisted-by: Claude Code (Opus 5.5, Fable 5.1) --- gap/basic/pcppara.gi | 31 ++++++++++++++++++++----------- gap/basic/pcppcps.gi | 21 ++++++++++++++------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/gap/basic/pcppara.gi b/gap/basic/pcppara.gi index 66cd6b2e..4c38d0be 100644 --- a/gap/basic/pcppara.gi +++ b/gap/basic/pcppara.gi @@ -112,7 +112,7 @@ end ); ## InstallGlobalFunction( AddToIgsParallel, function( pcs, gens, ppcs, pgens ) - local coll, rels, n, todo, tododo, ind, indd, g, gg, d, h, hh, k, + local coll, rels, n, todo, tododo, ind, indd, g, gg, d, h, hh, a, b, q, k, c, i, r, sub, val, j, f, nrmd, pairs; if Length( gens ) = 0 then return [pcs, ppcs]; fi; @@ -167,16 +167,25 @@ function( pcs, gens, ppcs, pgens ) g := g^0; gg := gg^0; else - pairs := GcdPcpPara(g, h, gg, hh); - h := pairs[1]; - g := pairs[2]; - hh := pairs[3]; - gg := pairs[4]; - if h <> ind[d] then - nrmd := NormedPcpElementPara( h, hh ); - ind[d] := nrmd[1]; - indd[d] := nrmd[2]; - AddSet(f, d); + a := LeadingExponent(g); + b := LeadingExponent(h); + if a > 0 and b > 0 and a mod b = 0 then + # GcdPcpPara would leave h and hh unchanged. + q := a/b; + g := g * h^-q; + gg := gg * hh^-q; + else + pairs := GcdPcpPara(g, h, gg, hh); + h := pairs[1]; + g := pairs[2]; + hh := pairs[3]; + gg := pairs[4]; + if h <> ind[d] then + nrmd := NormedPcpElementPara( h, hh ); + ind[d] := nrmd[1]; + indd[d] := nrmd[2]; + AddSet(f, d); + fi; fi; fi; d := Depth(g); diff --git a/gap/basic/pcppcps.gi b/gap/basic/pcppcps.gi index 4f04b2f8..b6b4f49e 100644 --- a/gap/basic/pcppcps.gi +++ b/gap/basic/pcppcps.gi @@ -134,7 +134,7 @@ 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, a, b, k, pair, t; if Length(gens) = 0 then return igs; fi; @@ -173,12 +173,19 @@ InstallGlobalFunction(AddToIgs, function(igs, gens) if g = h then g := g^0; else - pair := GcdPcp(g, h); - h := pair[1]; - g := pair[2]; - if h <> ind[d] then - ind[d] := NormedPcpElement( h ); - AddSet(f, d); + a := LeadingExponent(g); + b := LeadingExponent(h); + if a > 0 and b > 0 and a mod b = 0 then + # GcdPcp would leave h unchanged. + g := g * h^(-a/b); + else + pair := GcdPcp(g, h); + h := pair[1]; + g := pair[2]; + if h <> ind[d] then + ind[d] := NormedPcpElement( h ); + AddSet(f, d); + fi; fi; fi; d := Depth(g);