Skip to content

Commit

Permalink
Introduce associativity check to AsSemigroup
Browse files Browse the repository at this point in the history
See #4030.

I thought about adding a similar check to `SemigroupByGenerators`,
but that operation is explicitly documented as not checking for
associativity.

Fixes #4030.
  • Loading branch information
wilfwilson committed Apr 8, 2021
1 parent 84d1367 commit a7a788f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/semigrp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,25 @@ InstallMethod( AsSemigroup,
"generic method for collections",
[ IsCollection ],
function ( D )
local S, L;
local L, S, i, j, k;

# Must check associativity
if ApplicableMethod(IsAssociative, [D]) <> fail then
# In case there are better methods/known attributes for associativity
if not IsAssociative(D) then
return fail;
fi;
else
for i in D do
for j in D do
for k in D do
if (i * j) * k <> i * (j * k) then
return fail;
fi;
od;
od;
od;
fi;

D := AsSSortedList( D );
L := ShallowCopy( D );
Expand Down
19 changes: 19 additions & 0 deletions tst/testbugfix/2021-04-08-non-associative-semigroup.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# https://github.com/gap-system/gap/issues/4030
gap> T := [
> [ 1, 2, 6, 5, 4, 3 ],
> [ 2, 1, 4, 2, 2, 5 ],
> [ 6, 5, 1, 6, 6, 4 ],
> [ 5, 6, 3, 4, 1, 2 ],
> [ 4, 3, 2, 1, 5, 6 ],
> [ 3, 4, 5, 3, 3, 1 ]
> ];;
gap> M := MagmaByMultiplicationTable(T);
<magma with 6 generators>
gap> IsAssociative(M);
false
gap> AsSemigroup(M);
fail
gap> M := MagmaByMultiplicationTable(T);
<magma with 6 generators>
gap> AsSemigroup(M);
fail

0 comments on commit a7a788f

Please sign in to comment.