Skip to content

Commit

Permalink
semigrp: improve viewing of empty semigroups
Browse files Browse the repository at this point in the history
Previously, unexpected errors could occur when
viewing empty semigroups.
  • Loading branch information
wilfwilson authored and fingolfin committed Nov 26, 2018
1 parent 0a9548e commit 23f47b6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
9 changes: 9 additions & 0 deletions lib/magma.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,15 @@ InstallMethod( AsSubmagma,
end );


#############################################################################
##
#M IsEmpty( <M> ) . . . . . . . . . . . . . . test whether a magma is empty
##
InstallMethod(IsEmpty, "for a magma with generators of magma",
[IsMagma and HasGeneratorsOfMagma],
M -> IsEmpty(GeneratorsOfMagma(M)));


#############################################################################
##
#E
Expand Down
15 changes: 9 additions & 6 deletions lib/semigrp.gi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ function(S)

str := "\><";

if HasIsTrivial(S) and IsTrivial(S) then
if IsEmpty(S) then
Append(str, "\>empty\< ");
elif HasIsTrivial(S) and IsTrivial(S) then
Append(str, "\>trivial\< ");
else
if HasIsFinite(S) and not IsFinite(S) then
Expand All @@ -49,7 +51,7 @@ function(S)
fi;
fi;

if not IsGroup(S) then
if not IsGroup(S) and not IsEmpty(S) then
if HasIsTrivial(S) and IsTrivial(S) then
# do nothing
elif HasIsZeroSimpleSemigroup(S) and IsZeroSimpleSemigroup(S) then
Expand All @@ -72,7 +74,10 @@ function(S)

Append(str, SemigroupViewStringPrefix(S));

if HasIsMonoid(S) and IsMonoid(S) then
if IsEmpty(S) then
Append(str, "\>semigroup\<>\<");
return str;
elif HasIsMonoid(S) and IsMonoid(S) then
Append(str, "\>monoid\< ");
if HasGeneratorsOfInverseMonoid(S) then
nrgens := Length(GeneratorsOfInverseMonoid(S));
Expand Down Expand Up @@ -108,9 +113,7 @@ function(S)
if nrgens > 1 or nrgens = 0 then
Append(str, "s");
fi;
Append(str, "\<");

Append(str, ">\<");
Append(str, "\<>\<");

return str;
end);
Expand Down
2 changes: 1 addition & 1 deletion tst/testbugfix/2012-11-21-t00263.tst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ true
gap> Size(t);
infinity
gap> t := Subsemigroup(s, []);
<semigroup of size 0, with 0 generators>
<empty semigroup>
gap> HasSize(t);
true
gap> Size(t);
Expand Down
2 changes: 1 addition & 1 deletion tst/testbugfix/2018-05-09-submagma.tst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ false

#
gap> sub:=Submagma(mgm,[]);
<commutative semigroup with 0 generators>
<empty semigroup>
gap> Size(sub);
0
gap> IsTrivial(sub);
Expand Down
10 changes: 9 additions & 1 deletion tst/testinstall/semigrp.tst
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ gap> GeneratorsOfInverseMonoid(S);
gap> S := FreeSemigroup(2);
<free semigroup on the generators [ s1, s2 ]>
gap> T := Subsemigroup(S, []);
<semigroup of size 0, with 0 generators>
<empty semigroup>
gap> IsTrivial(T);
false
gap> IsEmpty(T);
Expand Down Expand Up @@ -501,6 +501,14 @@ Rank 2: [H size = 1, 1 L-class, 1 R-class]
Rank 2: [H size = 1, 1 L-class, 1 R-class]
Rank 1: *[H size = 1, 1 L-class, 1 R-class]

# test printing an empty semigroup
gap> S := FullTransformationMonoid(1);;
gap> Subsemigroup(S, []);
<empty transformation semigroup>
gap> S := SymmetricInverseMonoid(1);;
gap> Subsemigroup(S, []);
<empty partial perm semigroup>

#
gap> STOP_TEST( "semigrp.tst", 1);

Expand Down

0 comments on commit 23f47b6

Please sign in to comment.