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

Resolve issue 15 #34

Merged
merged 14 commits into from
Jul 4, 2024
52 changes: 43 additions & 9 deletions lib/grobner.gi
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ end);;
###

GBNP.ReducePol2:=function(arg)
local i,j,jl,h,ind,lts,new,lans,newind,temp,G,GLOT;
local i,j,jl,h,ind,lts,new,lans,newind,temp,G,GLOT,done,one;
G:=arg[1];
if Length(arg)>=2 then
GLOT:=arg[2];
Expand All @@ -650,13 +650,38 @@ local i,j,jl,h,ind,lts,new,lans,newind,temp,G,GLOT;
SortParallel(lts,G,LtNP);
GBNP.SortParallelLOT(temp,GLOT,LtNP);
else
for i in [1..Length(G)] do
G[i]:=GBNP.ReduceCancellation(G[i]);
od;
lts:=LMonsNP(G);
SortParallel(lts,G,LtNP);
done := false;
while not done do
for i in [1..Length(G)] do
G[i]:=GBNP.ReduceCancellation(G[i]);
od;
lts:=LMonsNP(G);
SortParallel(lts,G,LtNP);
done := true;
for i in Reversed( [1..Length(lts)-1] ) do
if ( lts[i] = lts[i+1] ) then
done := false;
## Print( "G[i],G[i+1] = ", G[i], G[i+1], "\n" );
one:=One(G[i][2][1]);
G[i+1] := CleanNP(AddNP(G[i+1],G[i],one,-one));
## Print( "new G[i+1] = ", G[i+1], "\n" );
fi;
od;
if not done then
## need to resort G
lts:=LMonsNP(G);
SortParallel(lts,G,LtNP);
## Print( "resorted lts and G:\n", lts, "\n", G, "\n" );
fi;
od;

## Print( "after SortParallel G and lts =:\n", G, "\n", lts, "\n" );

GLOT:=GBNP.CreateOccurTreePTSLR(lts,GBNP.CalculatePGlts(lts),true);
fi;

## Print( "initial GLOT:\n", GLOT, "\n" );

lans:=Length(lts);
ind:=[1..lans];

Expand All @@ -665,6 +690,9 @@ local i,j,jl,h,ind,lts,new,lans,newind,temp,G,GLOT;
RemoveSet(ind,i);
j:=i+1;
while j <= lans do

## Print( "[i,j] = ", [i,j], "\n" );

if #IsSubsetBlist(Gset[j],Gset[i]) and
GBNP.Occur(G[i][1][1],G[j][1][1]) <> 0
# XXX can this occur be removed
Expand Down Expand Up @@ -890,14 +918,15 @@ Grobner,function(arg) local tt,todo,G, funcs,KI,loop, withpair;
# - Compute internal NormalForm

Info(InfoGBNP,1,"number of entered polynomials is ",Length(KI));

if (withpair) then
# no cleaning should be needed when continuing
G:= ShallowCopy(KI);
else
G:= GBNP.ReducePol(KI);
fi;


## Print( "here is the resulting G\n", G, "\n" );

# only call GBNP.CalculatePG after reduction
funcs.pg:=GBNP.CalculatePG(G);

Expand Down Expand Up @@ -1023,7 +1052,6 @@ SGrobner,function(arg) local tt,todo,G,GLOT,funcs,KI,loop,withpair;
else
KI:=arg[1];
fi;

tt:=Runtime();

if Length(arg)>=2 and IsInt(arg[Length(arg)]) then
Expand Down Expand Up @@ -1308,11 +1336,17 @@ end);;

GBNP.StrongNormalForm2TS:=function(G,j,GLOT)
local g,h,il,i1,l,dr,ga,tt,lth,iid;

## Print( "in StrongNormalForm2TS G[j] = ", G[j], "\n" );

h:=StructuralCopy(G[j]);
iid := 1;
while iid <= Length(h[1]) do
lth:=h[1][iid];
il:=GBNP.LookUpOccurTreeAllLstPTSLR(lth,GLOT,true);

## Print( "il = ", il, "\n" );

il:=Filtered(il,x->x[1]<>j);
while il<>[] do
i1:=il[1];
Expand Down
2 changes: 1 addition & 1 deletion lib/occurtree.gi
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ end;
###

GBNP.CreateOccurTreePTSLR:=function(L,pg,left)
if (pg <> GBNP.GetOptions().pg) then
if (pg <> GBNP.GetOptions().pg) then
Info(InfoGBNP,2,"Warning: CreateOccurTreePTSLR: pg argument (",pg,") is not the same as pg option (",GBNP.GetOptions().pg,")\n");
fi;

Expand Down
10 changes: 10 additions & 0 deletions tst/issue15.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
LoadPackage("gbnp");
SetInfoLevel( InfoGBNP, 2 );
A:=FreeAssociativeAlgebraWithOne(Rationals,"a","b");
a:=A.1;
b:=A.2;
rels := [ a^3, a^2*b, a*b^2+a^2, b*a^2, a^3+b^2+b*a, a*b^2+a*b*a,
b*a*b+b*a^2, b^2*a+b*a^2, b^3+b*a^2, a^2*b*a, a*b*a^2, b*a^2*b ];
relsnp := List( rels, x-> GP2NP(x) );
grobnp := Grobner(relsnp);
grob := List( grobnp, p -> NP2GP(p,A) );
23 changes: 23 additions & 0 deletions tst/issue15.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
gap> START_TEST("GBNP issue 15");
gap>
gap> LoadPackage("gbnp");;
gap>
gap> A:=FreeAssociativeAlgebraWithOne(Rationals,"a","b");;
gap> a:=A.1;;
gap> b:=A.2;;
gap> rels := [ a^3, a^2*b, a*b^2+a^2, b*a^2, a^3+b^2+b*a,
> a*b^2+a*b*a, b*a*b+b*a^2, b^2*a+b*a^2, b^3+b*a^2,
> a^2*b*a, a*b*a^2, b*a^2*b ];;
gap> Display(rels);
[ (1)*a^3, (1)*a^2*b, (1)*a^2+(1)*a*b^2, (1)*b*a^2, (1)*b*a+(1)*b^2+(1)*a^3,
(1)*a*b*a+(1)*a*b^2, (1)*b*a^2+(1)*b*a*b, (1)*b*a^2+(1)*b^2*a,
(1)*b*a^2+(1)*b^3, (1)*a^2*b*a, (1)*a*b*a^2, (1)*b*a^2*b ]
gap> relsnp := List( rels, x-> GP2NP(x) );;
gap> grobnp := Grobner(relsnp);;
gap> grob := List( grobnp, p -> NP2GP(p,A) );;
gap> Display(grob);
[ (1)*b^2+(1)*b*a, (1)*a^3, (1)*a^2*b, (1)*a*b*a+(-1)*a^2, (1)*b*a^2,
(1)*b*a*b+(1)*b*a^2 ]
gap>
gap> STOP_TEST("GBNP issue 15",10000);