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

Fix ShallowCopy for KnuthBendixRewritingSystem #3128

Merged
merged 2 commits into from
Jan 7, 2019
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
21 changes: 9 additions & 12 deletions lib/kbsemi.gi
Original file line number Diff line number Diff line change
Expand Up @@ -501,33 +501,28 @@ InstallMethod(IsReduced,
"for a Knuth Bendix rewriting system", true,
[IsKnuthBendixRewritingSystem and IsKnuthBendixRewritingSystemRep and IsMutable], 0,
function(kbrws)
local i,copy_of_kbrws,u;
local i, copy_of_kbrws, u, tzr;

# if the rws already knows it is reduced return true
if kbrws!.reduced then return true; fi;

for i in [1..Length(Rules(kbrws))] do
tzr := TzRules(kbrws);
for i in [1..Length(tzr)] do

u := Rules(kbrws)[i];
u := tzr[i];
fingolfin marked this conversation as resolved.
Show resolved Hide resolved

#TODO
copy_of_kbrws := ShallowCopy(kbrws);
copy_of_kbrws!.tzrules := [];
Append(copy_of_kbrws!.tzrules,kbrws!.tzrules{[1..i-1]});
Append(copy_of_kbrws!.tzrules,kbrws!.tzrules
{[i+1..Length(kbrws!.tzrules)]});

if ReduceLetterRepWordsRewSys(copy_of_kbrws!.tzrules,u[1])<>u[1] then
return false;
fi;
if ReduceLetterRepWordsRewSys(copy_of_kbrws!.tzrules,u[2])<>u[2] then
if ReduceLetterRepWordsRewSys(copy_of_kbrws!.tzrules,u[1])<>u[1] or
ReduceLetterRepWordsRewSys(copy_of_kbrws!.tzrules,u[2])<>u[2] then
return false;
fi;

od;

return true;

end);


Expand Down Expand Up @@ -788,7 +783,9 @@ InstallMethod( ShallowCopy,
reduced := false,
tzrules:= StructuralCopy(kbrws!.tzrules),
pairs2check:= [],
ordering :=kbrws!.ordering)));
ordering :=kbrws!.ordering,
freefam := kbrws!.freefam,
tzordering := kbrws!.tzordering)));
fingolfin marked this conversation as resolved.
Show resolved Hide resolved

###############################################################################
##
Expand Down
95 changes: 95 additions & 0 deletions tst/testinstall/kbsemi.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
gap> START_TEST("kbsemi.tst");
gap> F:=FreeGroup(2);
<free group on the generators [ f1, f2 ]>
gap> mhom:=IsomorphismFpMonoid(F);;
gap> mon:=Image(mhom);
<fp monoid on the generators [ f1, f1^-1, f2, f2^-1 ]>
gap> k:=KnuthBendixRewritingSystem(mon);
Knuth Bendix Rewriting System for Monoid( [ f1, f1^-1, f2, f2^-1
] ) with rules
[ [ f1*f1^-1, <identity ...> ], [ f1^-1*f1, <identity ...> ],
[ f2*f2^-1, <identity ...> ], [ f2^-1*f2, <identity ...> ] ]
gap> k1:=ShallowCopy(k);
Knuth Bendix Rewriting System for Monoid( [ f1, f1^-1, f2, f2^-1
] ) with rules
[ [ f1*f1^-1, <identity ...> ], [ f1^-1*f1, <identity ...> ],
[ f2*f2^-1, <identity ...> ], [ f2^-1*f2, <identity ...> ] ]
gap> MakeKnuthBendixRewritingSystemConfluent(k1);
gap> k = k1;
true

#
gap> f := FreeSemigroup("a","b");;
gap> a := f.1;; b := f.2;;
gap> s := f/[[a*b,b],[b*a,a]];;
gap> rws := KnuthBendixRewritingSystem(s);
Knuth Bendix Rewriting System for Semigroup( [ a, b ] ) with rules
[ [ a*b, b ], [ b*a, a ] ]
gap> IsConfluent(rws);
false
gap> rws1 := ShallowCopy(rws);
Knuth Bendix Rewriting System for Semigroup( [ a, b ] ) with rules
[ [ a*b, b ], [ b*a, a ] ]
gap> rws1 = rws;
true
gap> IsConfluent(rws1);
false
gap> MakeKnuthBendixRewritingSystemConfluent(rws1);
gap> rws1 = rws;
false
gap> MakeKnuthBendixRewritingSystemConfluent(rws);
gap> rws1 = rws;
true

# Some more tests for Knuth-Bendix rewriting
gap> CreateKnuthBendixRewritingSystem(FamilyObj(1), x -> x);
Error, Can only create a KB rewriting system for an fp semigroup or monoid
gap> M := FreeMonoid(2);; N := M / [ [M.1, M.2] ];;
gap> CreateKnuthBendixRewritingSystem(FamilyObj(Representative(N)), x -> x);
Error, Second argument must be a reduction ordering
gap> kbrws := KnuthBendixRewritingSystem(N);
Knuth Bendix Rewriting System for Monoid( [ m1, m2 ] ) with rules
[ [ m2, m1 ] ]
gap> kbrws := KnuthBendixRewritingSystem(N, {x,y} -> [y,x]);
Error, <expr> must be 'true' or 'false' (not a list (plain,dense))
gap> kbrws := KnuthBendixRewritingSystem(N, \<);
Knuth Bendix Rewriting System for Monoid( [ m1, m2 ] ) with rules
[ [ m2, m1 ] ]
gap> F := FreeGroup(2);; G := F / [ F.1^2, F.2^2, (F.1 * F.2)^6 ];;
gap> kbrws := KnuthBendixRewritingSystem(Image(IsomorphismFpMonoid(G)));;
gap> IsConfluent(kbrws);
false
gap> IsReduced(kbrws);
true
gap> kbrws2 := ShallowCopy(kbrws);
Knuth Bendix Rewriting System for Monoid( [ f1, f1^-1, f2, f2^-1
] ) with rules
[ [ f1^2, <identity ...> ], [ f1*f1^-1, <identity ...> ],
[ f1^-1*f1, <identity ...> ], [ f2^2, <identity ...> ],
[ f2*f2^-1, <identity ...> ], [ f2^-1*f2, <identity ...> ],
[ (f1*f2)^6, <identity ...> ] ]
gap> kbrws = kbrws2;
true
gap> IsConfluent(kbrws2);
false
gap> IsReduced(kbrws2);
true
gap> MakeKnuthBendixRewritingSystemConfluent(kbrws);
gap> IsConfluent(kbrws);
true
gap> IsConfluent(kbrws2);
false
gap> kbrws = kbrws2;
false
gap> S := FreeSemigroup(2);; T := S / [ [S.1, S.2] ];;
gap> KnuthBendixRewritingSystem(S, \<);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `KnuthBendixRewritingSystem' on 2 argume\
nts
gap> M := FreeMonoid(2);; N := M / [ [M.1, M.2] ];;
gap> KnuthBendixRewritingSystem(N, \<);
Knuth Bendix Rewriting System for Monoid( [ m1, m2 ] ) with rules
[ [ m2, m1 ] ]
#
gap> STOP_TEST("kbsemi.tst");