Skip to content

Commit

Permalink
Add HighLevelGroebnerBasis as an alternative to GBNPGroebnerBasis.
Browse files Browse the repository at this point in the history
  This is a high-level implementation and therefore certainly not as fast
  as GBNPGroebnerBasis. However, GBNPGroebnerBasis sometimes results in
  unpredictable bugs such that having an alternative seems reasonable.
  • Loading branch information
erich-9 committed Oct 1, 2018
1 parent e8c8606 commit 045eab7
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 1 deletion.
1 change: 1 addition & 0 deletions init.g
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ReadPackage("QPA", "lib/projpathalgmodule.gd");
ReadPackage("QPA", "lib/moduledecomp.gd");
ReadPackage("QPA", "lib/idempotent.gd");
ReadPackage("QPA", "lib/gbnp.gd");
ReadPackage("QPA", "lib/gbhighlevel.gd");
ReadPackage("QPA", "lib/moduleprojres.gd");
ReadPackage("QPA", "lib/pathalgtensor.gd");
ReadPackage("QPA", "lib/pathalgpredef.gd");
Expand Down
4 changes: 4 additions & 0 deletions lib/gbhighlevel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DeclareOperation( "HighLevelGroebnerBasis", [ IsList, IsPathAlgebra ] );
DeclareOperation( "RemainderOfDivision", [ IsElementOfMagmaRingModuloRelations, IsList, IsPathAlgebra ] );
DeclareOperation( "LeftmostOccurrence", [ IsList, IsList ] );
DeclareSynonym( "TipWalk", x -> WalkOfPath(TipMonomial(x)) );
113 changes: 113 additions & 0 deletions lib/gbhighlevel.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
InstallMethod( HighLevelGroebnerBasis,
"compute a complete Groebner Basis",
[ IsList, IsPathAlgebra ],
function(els, A)
local gb, el, el_tip,
n, i, j, x, y, k, l, r, b, c,
overlap, remainder;

if not QPA_InArrowIdeal(els, A) then
Error("elements do not belong to the arrow ideal of the path algebra");
fi;

els := MakeUniform(els);

gb := [];

while Length(els) > 0 do
for el in els do
el_tip := Tip(el);
Add(gb, el/TipCoefficient(el_tip));
od;

n := Length(gb);
els := [];

for i in [1..n] do
x := TipWalk(gb[i]);
k := Length(x);

for j in [1..n] do
y := TipWalk(gb[j]);
l := Length(y);

for r in [Maximum(0, k-l)..k-1] do
if x{[r+1..k]} = y{[1..k-r]} then
b := x{[1..r]};
c := y{[k-r+1..l]};

overlap := gb[i]*Product(c, One(A)) - Product(b, One(A))*gb[j];
remainder := RemainderOfDivision(overlap, gb, A);

if not IsZero(remainder) then
AddSet(els, remainder);
fi;
fi;
od;
od;
od;
od;

return gb;
end
);


InstallMethod( RemainderOfDivision,
"for a path-algebra element and a list of monic path-algebra elements",
[ IsElementOfMagmaRingModuloRelations, IsList, IsPathAlgebra ],
function(y, X, A)
local r, n, y_tip, y_wtip, divided, i, p, u, v;

r := Zero(A);
n := Length(X);

while not IsZero(y) do
y_tip := Tip(y);
y_wtip := TipWalk(y_tip);

divided := false;

for i in [1..n] do
p := LeftmostOccurrence(y_wtip, TipWalk(X[i]));

if p <> fail then
u := Product(y_wtip{[1..p[1]-1]}, One(A));
v := Product(y_wtip{[p[2]+1..Length(y_wtip)]}, One(A));

y := y - TipCoefficient(y_tip) * u*X[i]*v;

divided := true;
break;
fi;
od;

if not divided then
r := r + y_tip;
y := y - y_tip;
fi;
od;

return r;
end
);


InstallMethod( LeftmostOccurrence,
"find second list as sublist of first list",
[ IsList, IsList ],
function(b, c)
local lb, lc, i;

lb := Length(b);
lc := Length(c);

for i in [1..lb-lc+1] do
if b{[i..i+lc-1]} = c then
return [i, i+lc-1];
fi;
od;

return fail;
end
);
2 changes: 1 addition & 1 deletion lib/pathalgideal.gi
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ InstallTrueMethod( IsIdealInPathAlgebra,
#O \in(<elt>, <I>)
##
## This function performs a membership test for an ideal in path algebra using
## Groebner Bases machinery.
## (by default GBNP) Groebner Bases machinery.
## It returns true if <elt> is a member of an ideal <I>, false otherwise.
## For the efficiency reasons, it computes Groebner basis
## for <I> only if it has not been computed. Similarly, it performs
Expand Down
1 change: 1 addition & 0 deletions read.g
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ReadPackage("QPA", "lib/projpathalgmodule.gi");
ReadPackage("QPA", "lib/moduledecomp.gi");
ReadPackage("QPA", "lib/idempotent.gi");
ReadPackage("QPA", "lib/gbnp.gi");
ReadPackage("QPA", "lib/gbhighlevel.gi");
ReadPackage("QPA", "lib/moduleprojres.gi");
ReadPackage("QPA", "lib/pathalgtensor.gi");
ReadPackage("QPA", "lib/pathalgpredef.gi");
Expand Down

0 comments on commit 045eab7

Please sign in to comment.