Skip to content

Commit

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

Fixes #4030.
  • Loading branch information
wilfwilson committed May 7, 2021
1 parent 8839587 commit cea9c29
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/semigrp.gd
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ DeclareOperation( "SemigroupByGenerators", [ IsCollection ] );
## <Oper Name="AsSemigroup" Arg='C'/>
##
## <Description>
## If <A>C</A> is a collection whose elements form a semigroup
## If <A>C</A> is a
## multiplicative element collection whose elements form a semigroup
## (see&nbsp;<Ref Filt="IsSemigroup"/>) then <Ref Oper="AsSemigroup"/>
## returns this semigroup.
## Otherwise <K>fail</K> is returned.
Expand Down
6 changes: 5 additions & 1 deletion lib/semigrp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,14 @@ InstallMethod( AsSemigroup,

InstallMethod( AsSemigroup,
"generic method for collections",
[ IsCollection ],
[ IsMultiplicativeElementCollection ],
function ( D )
local S, L;

if not IsAssociative( D ) then
return fail;
fi;

D := AsSSortedList( D );
L := ShallowCopy( D );
S := Submagma( SemigroupByGenerators( D ), [] );
Expand Down
52 changes: 52 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,52 @@
# 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
gap> AsSemigroup(Elements(M));
fail

#
gap> T := [
> [ 1, 2, 3, 4, 5 ],
> [ 2, 2, 2, 5, 5 ],
> [ 3, 2, 3, 4, 5 ],
> [ 4, 2, 4, 3, 5 ],
> [ 5, 2, 5, 2, 5 ]
> ];;
gap> M := MagmaByMultiplicationTable(T);
<magma with 5 generators>
gap> IsAssociative(M);
true
gap> S := AsSemigroup(M);;
gap> IsSemigroup(S);
true
gap> Size(S);
5
gap> M := MagmaByMultiplicationTable(T);
<magma with 5 generators>
gap> S := AsSemigroup(M);;
gap> IsSemigroup(S);
true
gap> Size(S);
5
gap> S := AsSemigroup(Elements(M));;
gap> IsSemigroup(S);
true
gap> Size(S);
5
4 changes: 4 additions & 0 deletions tst/testinstall/magma.tst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ gap> IsAssociative(M) or IsCommutative(M);
false
gap> Filtered(Combinations(Elements(M)), x -> Size(x) > 0 and IsAssociative(x));
[ [ m1 ], [ m1, m3 ], [ m2 ], [ m2, m4 ], [ m3 ], [ m4 ] ]
gap> AsSemigroup([Elements(M)[1], Elements(M)[2]]);
fail
gap> AsSemigroup([Elements(M)[1], Elements(M)[3]]);
<semigroup of size 2, with 2 generators>
gap> Filtered(Combinations(Elements(M)), x -> Size(x) > 0 and IsCommutative(x));
[ [ m1 ], [ m1, m2 ], [ m1, m2, m3 ], [ m1, m2, m5 ], [ m1, m3 ], [ m1, m5 ],
[ m2 ], [ m2, m3 ], [ m2, m4 ], [ m2, m5 ], [ m3 ], [ m4 ], [ m5 ] ]
Expand Down

0 comments on commit cea9c29

Please sign in to comment.