Skip to content

Commit

Permalink
Hide internal functions and make first edits on ideal.tst
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun2M authored Mar 27, 2024
1 parent 1140492 commit abdf215
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 91 deletions.
22 changes: 7 additions & 15 deletions gap/ideals/ideals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,22 @@
##
#############################################################################

DeclareSynonymAttr("GeneratorsOfSemigroupIdeal", GeneratorsOfMagmaIdeal);
DeclareSynonymAttr("GeneratorsOfSemigroupIdeal",
GeneratorsOfMagmaIdeal);
DeclareSynonymAttr("GeneratorsOfLeftSemigroupIdeal",
GeneratorsOfLeftMagmaIdeal);
DeclareSynonymAttr("GeneratorsOfRightSemigroupIdeal",
GeneratorsOfRightMagmaIdeal);


DeclareGlobalFunction("SemigroupIdeal");
DeclareGlobalFunction("LeftSemigroupIdeal");
DeclareGlobalFunction("RightSemigroupIdeal");
DeclareGlobalFunction("AnySemigroupIdealInputParsing");

DeclareOperation("AnySemigroupIdealByGenerators",
[IsSemigroup, IsOperation, IsListOrCollection]);

DeclareOperation("AnySemigroupIdealByGenerators",
[IsSemigroup, IsOperation, IsListOrCollection, IsRecord]);

DeclareOperation("AnySemigroupIdealByGeneratorsNC",
[IsSemigroup, IsOperation, IsListOrCollection, IsRecord]);

DeclareOperation("SemigroupIdealByGenerators",
[IsSemigroup, IsListOrCollection]);

DeclareOperation("SemigroupIdealByGenerators",
[IsSemigroup, IsListOrCollection, IsRecord]);

DeclareOperation("SemigroupIdealByGeneratorsNC",
[IsSemigroup, IsListOrCollection, IsRecord]);

Expand All @@ -53,6 +47,4 @@ DeclareAttribute("MinimalIdealGeneratingSet", IsSemigroupIdeal);

DeclareAttribute("SupersemigroupOfIdeal", IsSemigroupIdeal);

InstallTrueMethod(IsSemigroup, IsSemigroupIdeal); # Duplicate with ideal.gi?

DeclareAttribute("Ideals", IsSemigroup);
105 changes: 49 additions & 56 deletions gap/ideals/ideals.gi
Original file line number Diff line number Diff line change
Expand Up @@ -187,116 +187,108 @@ InstallMethod(Representative, "for a semigroup ideal",

# a convenience, similar to the functions <Semigroup>, <Monoid>, etc

InstallGlobalFunction(AnySemigroupIdealInputParsing,
function(inputArgs)
SEMIGROUPS.AnySemigroupIdealInputParsing := function(arg...)
local out, i;

if Length(inputArgs) <= 1 then
if Length(arg) <= 1 then
ErrorNoReturn("there must be 2 or more arguments");
elif not IsSemigroup(inputArgs[1]) then
elif not IsSemigroup(arg[1]) then
ErrorNoReturn("the 1st argument is not a semigroup");
elif Length(inputArgs) = 2 and IsMatrix(inputArgs[2]) then
elif Length(arg) = 2 and IsMatrix(arg[2]) then
# special case for matrices, because they may look like lists
return [inputArgs[1], [inputArgs[2]]];
return [arg[1], [arg[2]]];

elif Length(inputArgs) = 2 and IsList(inputArgs[2]) and 0 < Length(inputArgs[2]) then
elif Length(arg) = 2 and IsList(arg[2]) and
0 < Length(arg[2]) then
# list of generators
return [inputArgs[1], inputArgs[2]];
elif (IsMultiplicativeElement(inputArgs[2])
and IsGeneratorsOfSemigroup([inputArgs[2]]))
or (IsListOrCollection(inputArgs[2])
and IsGeneratorsOfSemigroup(inputArgs[2]))
or (HasIsEmpty(inputArgs[2]) and IsEmpty(inputArgs[2])) then
return [arg[1], arg[2]];
elif (IsMultiplicativeElement(arg[2])
and IsGeneratorsOfSemigroup([arg[2]]))
or (IsListOrCollection(arg[2])
and IsGeneratorsOfSemigroup(arg[2]))
or (HasIsEmpty(arg[2]) and IsEmpty(arg[2])) then
# generators and collections of generators
out := [];
for i in [2 .. Length(inputArgs)] do
for i in [2 .. Length(arg)] do
# so that we can pass the options record
if i = Length(inputArgs) and IsRecord(inputArgs[i]) then
return [inputArgs[1], out, inputArgs[i]];
elif IsMultiplicativeElement(inputArgs[i]) and
IsGeneratorsOfSemigroup([inputArgs[i]]) then
Add(out, inputArgs[i]);
elif IsGeneratorsOfSemigroup(inputArgs[i]) then
if HasGeneratorsOfSemigroupIdeal(inputArgs[i]) then
Append(out, GeneratorsOfSemigroupIdeal(inputArgs[i]));
elif HasGeneratorsOfSemigroup(inputArgs[i]) then
Append(out, GeneratorsOfSemigroup(inputArgs[i]));
elif IsList(inputArgs[i]) then
Append(out, inputArgs[i]);
if i = Length(arg) and IsRecord(arg[i]) then
return [arg[1], out, arg[i]];
elif IsMultiplicativeElement(arg[i]) and
IsGeneratorsOfSemigroup([arg[i]]) then
Add(out, arg[i]);
elif IsGeneratorsOfSemigroup(arg[i]) then
if HasGeneratorsOfSemigroupIdeal(arg[i]) then
Append(out, GeneratorsOfSemigroupIdeal(arg[i]));
elif HasGeneratorsOfSemigroup(arg[i]) then
Append(out, GeneratorsOfSemigroup(arg[i]));
elif IsList(arg[i]) then
Append(out, arg[i]);
else
Append(out, AsList(inputArgs[i]));
Append(out, AsList(arg[i]));
fi;
else
ErrorNoReturn("the 2nd argument is not a combination ",
"of generators, lists of generators, ",
"nor semigroups");
fi;
od;
return [inputArgs[1], out];
return [arg[1], out];
fi;
ErrorNoReturn("invalid arguments");
end);
end;

InstallGlobalFunction(SemigroupIdeal,
function(arg...)
local parsed;
parsed := AnySemigroupIdealInputParsing(arg);
parsed := CallFuncList(SEMIGROUPS.AnySemigroupIdealInputParsing, arg);
if Length(parsed) = 3 then
return AnySemigroupIdealByGenerators(parsed[1],
return SEMIGROUPS.AnySemigroupIdealByGenerators4(parsed[1],
IsMagmaIdeal, parsed[2], parsed[3]);
else
return AnySemigroupIdealByGenerators(parsed[1],
return SEMIGROUPS.AnySemigroupIdealByGenerators3(parsed[1],
IsMagmaIdeal, parsed[2]);
fi;
end);

InstallGlobalFunction(LeftSemigroupIdeal,
function(arg...)
local parsed;
parsed := AnySemigroupIdealInputParsing(arg);
parsed := CallFuncList(SEMIGROUPS.AnySemigroupIdealInputParsing, arg);
if Length(parsed) = 3 then
return AnySemigroupIdealByGenerators(parsed[1],
return SEMIGROUPS.AnySemigroupIdealByGenerators4(parsed[1],
IsLeftMagmaIdeal, parsed[2], parsed[3]);
else
return AnySemigroupIdealByGenerators(parsed[1],
return SEMIGROUPS.AnySemigroupIdealByGenerators3(parsed[1],
IsLeftMagmaIdeal, parsed[2]);
fi;
end);

InstallGlobalFunction(RightSemigroupIdeal,
function(arg...)
local parsed;
parsed := AnySemigroupIdealInputParsing(arg);
parsed := CallFuncList(SEMIGROUPS.AnySemigroupIdealInputParsing, arg);
if Length(parsed) = 3 then
return AnySemigroupIdealByGenerators(parsed[1],
return SEMIGROUPS.AnySemigroupIdealByGenerators4(parsed[1],
IsRightMagmaIdeal, parsed[2], parsed[3]);
else
return AnySemigroupIdealByGenerators(parsed[1],
return SEMIGROUPS.AnySemigroupIdealByGenerators3(parsed[1],
IsRightMagmaIdeal, parsed[2]);
fi;
end);

InstallMethod(AnySemigroupIdealByGenerators,
"for a semigroup, filter and list or collections",
[IsSemigroup, IsOperation, IsListOrCollection],
{S, filter, gens} -> AnySemigroupIdealByGenerators(S,
filter, gens, SEMIGROUPS.OptionsRec(S)));
SEMIGROUPS.AnySemigroupIdealByGenerators3 := {S, filter, gens} ->
SEMIGROUPS.AnySemigroupIdealByGenerators4(S,
filter, gens, SEMIGROUPS.OptionsRec(S));

InstallMethod(AnySemigroupIdealByGenerators,
"for semigroup, filter, list or collection, and record",
[IsSemigroup, IsOperation, IsListOrCollection, IsRecord],
function(S, filter, gens, opts)
SEMIGROUPS.AnySemigroupIdealByGenerators4 := function(S, filter, gens, opts)
if not ForAll(gens, x -> x in S) then
ErrorNoReturn("the 2nd argument (a mult. elt. coll.) do not all ",
"belong to the semigroup");
fi;
return AnySemigroupIdealByGeneratorsNC(S, filter, gens, opts);
end);
return SEMIGROUPS.AnySemigroupIdealByGeneratorsNC(S, filter, gens, opts);
end;

InstallMethod(AnySemigroupIdealByGeneratorsNC,
"for a semigroup, filter, (list or collections) and record",
[IsSemigroup, IsOperation, IsListOrCollection, IsRecord],
function(S, filter, gens, opts)
SEMIGROUPS.AnySemigroupIdealByGeneratorsNC := function(S, filter, gens, opts)
local filts, I;
opts := SEMIGROUPS.ProcessOptionsRec(SEMIGROUPS.DefaultOptionsRec, opts);
gens := AsList(gens);
Expand Down Expand Up @@ -375,7 +367,7 @@ function(S, filter, gens, opts)
fi;

return I;
end);
end;

InstallMethod(SemigroupIdealByGenerators,
"for a semigroup and list or collections",
Expand All @@ -386,14 +378,15 @@ InstallMethod(SemigroupIdealByGenerators,
"for semigroup, list or collection, and record",
[IsSemigroup, IsListOrCollection, IsRecord],
function(S, gens, opts)
return AnySemigroupIdealByGenerators(S, IsMagmaIdeal, gens, opts);
return SEMIGROUPS.AnySemigroupIdealByGenerators4(S, IsMagmaIdeal, gens, opts);
end);

InstallMethod(SemigroupIdealByGeneratorsNC,
"for a semigroup, list or collections, and record",
[IsSemigroup, IsListOrCollection, IsRecord],
function(S, gens, opts)
return AnySemigroupIdealByGeneratorsNC(S, IsMagmaIdeal, gens, opts);
return SEMIGROUPS.AnySemigroupIdealByGeneratorsNC(S,
IsMagmaIdeal, gens, opts);
end);

InstallMethod(MinimalIdealGeneratingSet,
Expand Down
52 changes: 32 additions & 20 deletions tst/standard/ideals/ideals.tst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ gap> SEMIGROUPS.StartTest();

# Test SupersemigroupOfIdeal
gap> S := RegularBooleanMatMonoid(3);;
gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat,
gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat,
> [[1, 1, 1], [1, 0, 1], [1, 1, 1]]));
<semigroup ideal of 3x3 boolean matrices with 1 generator>
gap> J := MinimalIdeal(I);
Expand All @@ -35,8 +35,8 @@ true

# Test PrintString
gap> S := RegularBooleanMatMonoid(3);;
gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat,
gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat,
> [[1, 1, 1], [1, 0, 1], [1, 1, 1]]));
<semigroup ideal of 3x3 boolean matrices with 1 generator>
gap> PrintString(I);
Expand Down Expand Up @@ -133,16 +133,28 @@ false
gap> S = MinimalIdeal(S);
false

# Test SemigroupIdeal (the function)
# Test SemigroupIdeal, LeftSemigroupIdeal, RightSemigroupIdeal (the function)
gap> SemigroupIdeal("a");
Error, there must be 2 or more arguments
gap> LeftSemigroupIdeal("314159265358979");
Error, there must be 2 or more arguments
gap> RightSemigroupIdeal(5);
Error, there must be 2 or more arguments
gap> S := RegularBooleanMatMonoid(1);;
gap> SemigroupIdeal(S);
Error, there must be 2 or more arguments
gap> LeftSemigroupIdeal(S);
Error, there must be 2 or more arguments
gap> RightSemigroupIdeal(S);
Error, there must be 2 or more arguments
gap> S := Semigroup([[Z(2)]]);
<trivial group with 1 generator>
gap> SemigroupIdeal(S, S.1);
<commutative inverse semigroup ideal with 1 generator>
gap> LeftSemigroupIdeal(S, S.1);
<commutative inverse semigroup ideal with 1 generator>
gap> RightSemigroupIdeal(S, S.1);
<commutative inverse semigroup ideal with 1 generator>
gap> S := RegularBooleanMatMonoid(2);;
gap> I := SemigroupIdeal(S, [S.1, S.2]);
<semigroup ideal of 2x2 boolean matrices with 2 generators>
Expand Down Expand Up @@ -200,7 +212,7 @@ gap> I := SemigroupIdeal(S, S.1);
gap> MinimalIdealGeneratingSet(I);
[ Transformation( [ 2, 3, 1 ] ) ]
gap> S := RegularBooleanMatMonoid(3);;
gap> I := SemigroupIdeal(S,
gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat, [[1, 1, 1], [1, 1, 0], [1, 0, 1]]),
> Matrix(IsBooleanMat, [[1, 1, 1], [1, 1, 0], [0, 0, 1]]),
> Matrix(IsBooleanMat, [[1, 0, 0], [0, 1, 1], [1, 0, 1]]),
Expand All @@ -213,12 +225,12 @@ gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat, [[0, 1, 1], [0, 1, 1], [1, 0, 1]]));
<semigroup ideal of 3x3 boolean matrices with 10 generators>
gap> MinimalIdealGeneratingSet(I);
[ Matrix(IsBooleanMat, [[0, 1, 0], [1, 0, 1], [1, 1, 0]]),
[ Matrix(IsBooleanMat, [[0, 1, 0], [1, 0, 1], [1, 1, 0]]),
Matrix(IsBooleanMat, [[1, 0, 0], [1, 1, 0], [1, 0, 1]]) ]

# Test InversesOfSemigroupElementNC
gap> S := RegularBooleanMatMonoid(3);;
gap> I := SemigroupIdeal(S,
gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat, [[1, 1, 1], [1, 1, 0], [1, 0, 1]]),
> Matrix(IsBooleanMat, [[1, 1, 1], [1, 1, 0], [0, 0, 1]]),
> Matrix(IsBooleanMat, [[1, 0, 0], [0, 1, 1], [1, 0, 1]]),
Expand All @@ -231,14 +243,14 @@ gap> I := SemigroupIdeal(S,
> Matrix(IsBooleanMat, [[0, 1, 1], [0, 1, 1], [1, 0, 1]]));;
gap> x := Matrix(IsBooleanMat, [[1, 0, 1], [0, 1, 0], [1, 0, 1]]);;
gap> InversesOfSemigroupElement(I, x);
[ Matrix(IsBooleanMat, [[0, 0, 0], [0, 1, 0], [0, 0, 1]]),
Matrix(IsBooleanMat, [[0, 0, 0], [0, 1, 0], [1, 0, 0]]),
Matrix(IsBooleanMat, [[0, 0, 0], [0, 1, 0], [1, 0, 1]]),
Matrix(IsBooleanMat, [[0, 0, 1], [0, 1, 0], [0, 0, 0]]),
Matrix(IsBooleanMat, [[0, 0, 1], [0, 1, 0], [0, 0, 1]]),
Matrix(IsBooleanMat, [[1, 0, 0], [0, 1, 0], [0, 0, 0]]),
Matrix(IsBooleanMat, [[1, 0, 0], [0, 1, 0], [1, 0, 0]]),
Matrix(IsBooleanMat, [[1, 0, 1], [0, 1, 0], [0, 0, 0]]),
[ Matrix(IsBooleanMat, [[0, 0, 0], [0, 1, 0], [0, 0, 1]]),
Matrix(IsBooleanMat, [[0, 0, 0], [0, 1, 0], [1, 0, 0]]),
Matrix(IsBooleanMat, [[0, 0, 0], [0, 1, 0], [1, 0, 1]]),
Matrix(IsBooleanMat, [[0, 0, 1], [0, 1, 0], [0, 0, 0]]),
Matrix(IsBooleanMat, [[0, 0, 1], [0, 1, 0], [0, 0, 1]]),
Matrix(IsBooleanMat, [[1, 0, 0], [0, 1, 0], [0, 0, 0]]),
Matrix(IsBooleanMat, [[1, 0, 0], [0, 1, 0], [1, 0, 0]]),
Matrix(IsBooleanMat, [[1, 0, 1], [0, 1, 0], [0, 0, 0]]),
Matrix(IsBooleanMat, [[1, 0, 1], [0, 1, 0], [1, 0, 1]]) ]

# Test IsCommutativeSemigroup
Expand All @@ -247,7 +259,7 @@ gap> x := Transformation([13, 4, 1, 2, 14, 14, 7, 12, 4, 9, 2, 14, 5, 14, 13,
gap> y := Transformation([13, 15, 7, 18, 4, 2, 8, 12, 10, 7, 8, 11, 12, 12, 17,
> 6, 13, 9, 16, 13]);;
gap> T := DirectProduct(Semigroup(x), Semigroup(y));
<commutative transformation semigroup of size 45, degree 40 with 13
<commutative transformation semigroup of size 45, degree 40 with 13
generators>
gap> z := Transformation([14, 2, 14, 4, 14, 14, 7, 14, 2, 4, 4, 14, 14, 14, 14,
> 14, 14, 14, 14, 4, 32, 31, 28, 28, 31, 32, 32, 31, 31, 28, 32, 28, 31, 31, 28,
Expand All @@ -256,8 +268,8 @@ gap> I := SemigroupIdeal(T, z);;
gap> IsCommutativeSemigroup(I);
true
gap> S := RegularBooleanMatMonoid(3);;
gap> I := SemigroupIdeal(S,
> [Matrix(IsBooleanMat, [[0, 1, 0], [1, 0, 1], [1, 1, 0]]),
gap> I := SemigroupIdeal(S,
> [Matrix(IsBooleanMat, [[0, 1, 0], [1, 0, 1], [1, 1, 0]]),
> Matrix(IsBooleanMat, [[1, 0, 0], [1, 1, 0], [1, 0, 1]])]);;
gap> IsCommutativeSemigroup(I);
false
Expand Down Expand Up @@ -327,7 +339,7 @@ gap> ideals := Ideals(S);;
gap> Size(ideals);
1
gap> S := Semigroup([
> Bipartition([[1, 2, -1, -4], [3, -5], [4], [5, -2], [-3]]),
> Bipartition([[1, 2, -1, -4], [3, -5], [4], [5, -2], [-3]]),
> Bipartition([[1, 2, 4, -3, -5], [3, -4], [5, -1, -2]]),
> Bipartition([[1, 2, 5, -3, -4], [3, 4, -1, -2], [-5]])]);;
gap> ideals := Ideals(S);;
Expand Down

0 comments on commit abdf215

Please sign in to comment.