Skip to content

Commit

Permalink
feat: Add tons of stuff (#32)
Browse files Browse the repository at this point in the history
* feat: Add generate all possible diagonals method

* feat(tst): Add more tests

* feat: Add IdSmallAntimagma

* feat: Add MagmaIsomorphismInvariants

* chore: Order methods

* chore: Change error-log

* feat: Add linting for tests, simplified tests

* feat: Remove support for 4.11

* chore: Fixed and linted examples

* chore: Reformat test

* chore: Reformat test
  • Loading branch information
limakzi authored Aug 18, 2024
1 parent 2b8df6f commit 8af58a2
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 44 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pull-request-gap-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ jobs:
- master
- stable-4.13
- stable-4.12
- stable-4.11

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/pull-request-gaplint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ jobs:
find . -name '*.gi' | xargs -n1 gaplint
echo "::group:: gaplint -- *.gd"
find . -name '*.gd' | xargs -n1 gaplint
echo "::group:: gaplint -- *.tst"
find . -name '*.tst' | xargs -n1 gaplint
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test: test_linting test_docs test_gap
test: test_docs test_linting test_gap

test_docs:
gap ./makedoc.g
Expand All @@ -10,3 +10,4 @@ test_linting:
find . -type f -name "*.g" | xargs -n1 gaplint
find . -type f -name "*.gi" | xargs -n1 gaplint
find . -type f -name "*.gd" | xargs -n1 gaplint
find . -type f -name "*.tst" | xargs -n1 gaplint
4 changes: 2 additions & 2 deletions PackageInfo.g
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ PackageDoc := rec(
# a longer title of the book, this together with the book name should
# fit on a single text line (appears with the '?books' command in GAP)
# LongTitle := "Elementary Divisors of Integer Matrices",
LongTitle := "smallantimagmas/An antiassociative magmas package",
LongTitle := "smallantimagmas/Antimagmas package",
Autoload := true
),

Expand All @@ -239,7 +239,7 @@ PackageDoc := rec(
Dependencies := rec(
# GAP version, use the version string for specifying a least version,
# prepend a '=' for specifying an exact version.
GAP := "4.10",
GAP := "4.12",

# list of pairs [package name, version], package name is case
# insensitive, exact version denoted with '=' prepended to version string.
Expand Down
16 changes: 8 additions & 8 deletions lib/helper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ __SmallAntimagmaHelper := rec();

__SmallAntimagmaHelper.checkOrder := function(order)
if not IsInt(order) then
ErrorNoReturn("SmallAntimagmas: ", "<order> must be an integer");
ErrorNoReturn("smallantimagmas: ", "<order> must be an integer");
fi;

if order < 1 then
ErrorNoReturn("SmallAntimagmas:", "<order> must greater than or equal to 1");
ErrorNoReturn("smallantimagmas:", "<order> must greater than or equal to 1");
fi;
end;

__SmallAntimagmaHelper.checkId := function(id)
if not IsInt(id) then
ErrorNoReturn("SmallAntimagmas: ", "<id> must be an integer");
ErrorNoReturn("smallantimagmas: ", "<id> must be an integer");
fi;

if id < 1 then
ErrorNoReturn("SmallAntimagmas:", "<id> must greater than or equal to 1");
ErrorNoReturn("smallantimagmas:", "<id> must greater than or equal to 1");
fi;
end;

Expand All @@ -30,10 +30,10 @@ __SmallAntimagmaHelper.getSmallAntimagmaMetadataDirectory := function(order)
__SmallAntimagmaHelper.checkOrder(order);
result := DirectoriesPackageLibrary("smallantimagmas", Concatenation(["data", "/", "non-isomorphic", "/", String(order)]));
if Size(result) = 0 then
ErrorNoReturn("SmallAntimagmas:", "<order> is not yet implemeneted");
ErrorNoReturn("smallantimagmas:", "<order> is not yet implemeneted");
fi;
if Size(result) > 1 then
ErrorNoReturn("SmallAntimagmas:", "metadata directory must not be ambigous");
ErrorNoReturn("smallantimagmas:", "metadata directory must not be ambigous");
fi;
return First(result);
end;
Expand All @@ -50,10 +50,10 @@ __SmallAntimagmaHelper.getAllSmallAntimagmaMetadataDirectory := function(order)
__SmallAntimagmaHelper.checkOrder(order);
result := DirectoriesPackageLibrary("smallantimagmas", Concatenation(["data", "/", "all", "/", String(order)]));
if Size(result) = 0 then
ErrorNoReturn("SmallAntimagmas:", "<order> is not yet implemeneted");
ErrorNoReturn("smallantimagmas:", "<order> is not yet implemeneted");
fi;
if Size(result) > 1 then
ErrorNoReturn("SmallAntimagmas:", "metadata directory must not be ambigous");
ErrorNoReturn("smallantimagmas:", "metadata directory must not be ambigous");
fi;
return First(result);
end;
Expand Down
24 changes: 22 additions & 2 deletions lib/properties.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#! <pc group of size 4 with 2 generators>
#! gap> AssociativityIndex(OneSmallGroup(4));
#! 64
#! gap> AssociativityIndex(OneSmallGroup(4)) = 4^3;
#! gap> AssociativityIndex(OneSmallGroup(4)) = 4 ^ 3;
#! true
#! @EndExampleSession
#!
Expand Down Expand Up @@ -45,6 +45,26 @@ DeclareGlobalFunction( "AllSubmagmas" );
#!
DeclareProperty( "IsAntiassociative", IsMagma );

#! @Arguments M
#! @Description
#! identifies class of antiassociative magma <A>M</A>.
#!
#! @BeginExampleSession
#! gap> IsAntiassociative(OneSmallGroup(16));
#! false
#! gap> IsAntiassociative(OneSmallAntimagma(2));
#! true
#! gap> IsAntiassociative(OneSmallAntimagma(3));
#! true
#! @EndExampleSession
#!
DeclareAttribute( "IdSmallAntimagma", IsMagma );

#! @Arguments M
#! @Description
#! computes isomorphism invariants of <A>M</A>.
DeclareGlobalFunction( "MagmaIsomorphismInvariants" );

#! @Arguments M, N
#! @Description
#! computes an isomoprhism between magmas <A>M</A>, <A>N</A>.
Expand Down Expand Up @@ -103,7 +123,7 @@ DeclareGlobalFunction( "IsMagmaIsomorphic" );
#! @BeginExampleSession
#! gap> N := SmallAntimagma(2, 1);
#! <magma with 2 generators>
#! gap> M:= SmallAntimagma(2, 1);
#! gap> M := SmallAntimagma(2, 1);
#! <magma with 2 generators>
#! gap> N := SmallAntimagma(2, 2);
#! <magma with 2 generators>
Expand Down
14 changes: 13 additions & 1 deletion lib/properties.gi
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ InstallGlobalFunction(TransposedMagma,
return MagmaByMultiplicationTable(TransposedMat(MultiplicationTable(M)));
end);

InstallGlobalFunction(MagmaIsomorphismInvariants,
function(M)
return [ Size(M), IsLeftCancellative(M), IsRightCancellative(M) ];
end);

InstallGlobalFunction(MagmaIsomorphism,
function(M, N)
local psi, n, p, m, elms;
if Size(M) <> Size(N) then

if MagmaIsomorphismInvariants(M) <> MagmaIsomorphismInvariants(N) then
return fail;
fi;

Expand Down Expand Up @@ -201,3 +207,9 @@ InstallGlobalFunction(HasPropertyA3,
od;
return false;
end);

InstallMethod(IdSmallAntimagma, "for a magma", [IsMagma],
function(N)
return [ Size(N),
First( Filtered([1 .. NrSmallAntimagmas(3)], index -> IsMagmaIsomorphic(N, SmallAntimagma(3, index) )) ) ];
end);
27 changes: 17 additions & 10 deletions lib/smallantimagmas.gi
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@ InstallGlobalFunction(NrSmallAntimagmas,
return Size(__SmallAntimagmaHelper.getSmallAntimagmaMetadata(order)());
end);

InstallGlobalFunction(ReallyNrSmallAntimagmas,
function(order)
return Size(__SmallAntimagmaHelper.getAllSmallAntimagmaMetadata(order)());
end);

InstallGlobalFunction(SmallAntimagma,
function(order, id)
return MagmaByMultiplicationTable(__SmallAntimagmaHelper.getSmallAntimagmaMetadata(order)()[id]);
return MagmaByMultiplicationTable(__SmallAntimagmaHelper.getSmallAntimagmaMetadata(order)()[id]);
end);

InstallGlobalFunction(AllSmallAntimagmas,
function(order)
return List(__SmallAntimagmaHelper.getSmallAntimagmaMetadata(order)(), id -> MagmaByMultiplicationTable(id));
if IsList(order) and ForAll(order, o -> IsInt(o)) then
return Flat(
List(order, o -> List(__SmallAntimagmaHelper.getSmallAntimagmaMetadata(o)(),
id -> MagmaByMultiplicationTable(id)))
);
elif IsInt(order) then
return List(__SmallAntimagmaHelper.getSmallAntimagmaMetadata(order)(), id -> MagmaByMultiplicationTable(id));
fi;
end);

InstallGlobalFunction(OneSmallAntimagma,
function(order)
return SmallAntimagma(order, Random([1 .. NrSmallAntimagmas(order) ]));
return SmallAntimagma(order, Random([1 .. NrSmallAntimagmas(order) ]));
end);

InstallGlobalFunction(ReallyAllSmallAntimagmas,
InstallGlobalFunction(ReallyNrSmallAntimagmas,
function(order)
return List(__SmallAntimagmaHelper.getAllSmallAntimagmaMetadata(order)(), id -> MagmaByMultiplicationTable(id) );
return Size(__SmallAntimagmaHelper.getAllSmallAntimagmaMetadata(order)());
end);

InstallGlobalFunction(ReallyAllSmallAntimagmas,
function(order)
return List(__SmallAntimagmaHelper.getAllSmallAntimagmaMetadata(order)(), id -> MagmaByMultiplicationTable(id) );
end);
4 changes: 4 additions & 0 deletions lib/utils.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! @Arguments [m, k]
#! @Description
#! returns a right order of element <A>m</A>.
DeclareGlobalFunction( "GeneratePossibleDiagonals" );
4 changes: 4 additions & 0 deletions lib/utils.gi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
InstallGlobalFunction(GeneratePossibleDiagonals,
function(n)
return Filtered(Tuples([1 .. n], n), t -> ForAll([1 .. n], i -> t[i] <> i));
end);
9 changes: 6 additions & 3 deletions tst/test_antimagma.tst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ false
gap> IsAntiassociative(MagmaByMultiplicationTable([[2, 1], [2, 1]]));
true

gap> ForAll([2..3], n -> ForAll(AllSmallAntimagmas(n), M -> IsEmpty(Idempotents(M))));
gap> ForAll(AllSmallAntimagmas([2 .. 3]), M -> IsEmpty(Idempotents(M)));
true

gap> ForAll([2..3], n -> ForAll(AllSmallAntimagmas(n), M -> IsEmpty(Center(M))));
gap> ForAll(AllSmallAntimagmas([2 .. 3]), M -> IsEmpty(Center(M)));
true

gap> ForAll([2..3], n -> ForAll(AllSmallAntimagmas(n), M -> IsAntiassociative(M)));
gap> ForAll(AllSmallAntimagmas([2 .. 3]), M -> IsAntiassociative(M));
true

gap> Collected( List(ReallyAllSmallAntimagmas(3), M -> IdSmallAntimagma(M)) );
[ [ [ 3, 1 ], 6 ], [ [ 3, 2 ], 6 ], [ [ 3, 3 ], 6 ], [ [ 3, 4 ], 6 ], [ [ 3, 5 ], 6 ], [ [ 3, 6 ], 6 ], [ [ 3, 7 ], 6 ], [ [ 3, 8 ], 6 ], [ [ 3, 9 ], 2 ], [ [ 3, 10 ], 2 ] ]

gap> STOP_TEST( "test_antimagma.tst" );
4 changes: 2 additions & 2 deletions tst/test_antimagmas_count.tst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
gap> START_TEST("test_antimagmas_count.tst");

gap> List([2..4], i -> NrSmallAntimagmas(i));
gap> List([2 .. 4], i -> NrSmallAntimagmas(i));
[ 2, 10, 17780 ]

gap> List([2..4], i -> ReallyNrSmallAntimagmas(i));
gap> List([2 .. 4], i -> ReallyNrSmallAntimagmas(i));
[ 2, 52, 421560 ]

gap> STOP_TEST( "test_antimagmas_count.tst" );
Expand Down
8 changes: 4 additions & 4 deletions tst/test_properties_element_left_right_order.tst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
gap> START_TEST( "test_properties_element_left_right_order.tst" );

gap> ForAll([2..10], n -> ForAll(AllSmallGroups(n), G -> ForAll(Elements(G), g -> Order(g) = LeftOrder(g))));
gap> ForAll(AllSmallGroups([2 .. 10]), G -> ForAll(Elements(G), g -> Order(g) = LeftOrder(g)));
true

gap> ForAll([2..10], n -> ForAll(AllSmallGroups(n), G -> ForAll(Elements(G), g -> Order(g) = RightOrder(g))));
gap> ForAll(AllSmallGroups([2 .. 10]), G -> ForAll(Elements(G), g -> Order(g) = RightOrder(g)));
true

gap> ForAll([2..3], n -> ForAll(AllSmallAntimagmas(n), M -> ForAll(Filtered(Elements(M), m -> LeftOrder(m) <> infinity), m -> LeftOrder(m) <> RightOrder(m) ) ) );
gap> ForAll(AllSmallAntimagmas([2 .. 3]), M -> ForAll(Filtered(Elements(M), m -> LeftOrder(m) <> infinity), m -> LeftOrder(m) <> RightOrder(m)));
true

gap> ForAll([2..3], n -> ForAll(AllSmallAntimagmas(n), M -> ForAll(Filtered(Elements(M), m -> RightOrder(m) <> infinity), m -> LeftOrder(m) <> RightOrder(m) ) ) );
gap> ForAll(AllSmallAntimagmas([2 .. 3]), M -> ForAll(Filtered(Elements(M), m -> RightOrder(m) <> infinity), m -> LeftOrder(m) <> RightOrder(m)));
true

gap> STOP_TEST( "test_properties_element_left_right_order.tst" );
4 changes: 2 additions & 2 deletions tst/test_properties_magma_associativity_index.tst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
gap> START_TEST( "test_properties_magma_associativity_index.txt" );

gap> ForAll([2..12], n -> ForAll(AllSmallGroups(n), M -> AssociativityIndex(M) = n^3));
gap> ForAll( AllSmallGroups([2 .. 12]), M -> AssociativityIndex(M) = Size(M) ^ 3 );
true

gap> ForAll([2..3], n -> ForAll(AllSmallAntimagmas(n), M -> AssociativityIndex(M) = 0));
gap> ForAll(AllSmallAntimagmas([2 .. 3]), M -> AssociativityIndex(M) = 0);
true

gap> STOP_TEST( "test_properties_magma_associativity_index.txt" );
6 changes: 6 additions & 0 deletions tst/test_properties_magma_isomorphism_invariants.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gap> START_TEST( "test_properties_magma_isomorphism_invariants.tst" );

gap> List([2 .. 3], n -> List(AllSmallAntimagmas(n), M -> MagmaIsomorphismInvariants(M) <> MagmaIsomorphismInvariants(TransposedMagma(M)) ) );
[ [ true, true ], [ false, false, false, false, false, false, false, false, true, true ] ]

gap> STOP_TEST( "test_properties_magma_isomorphism_invariants.tst" );
8 changes: 4 additions & 4 deletions tst/test_properties_magma_left_right_cancellative.tst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
gap> START_TEST( "test_properties_magma_left_right_cancellative.tst" );

gap> ForAll([2..4], n -> ForAll(AllSmallGroups(n), G -> IsLeftCancellative(G)));
gap> ForAll(AllSmallGroups([2 .. 4]), G -> IsLeftCancellative(G));
true

gap> ForAll([2..4], n -> ForAll(AllSmallGroups(n), G -> IsRightCancellative(G)));
gap> ForAll(AllSmallGroups([2 .. 4]), G -> IsRightCancellative(G));
true

gap> ForAll([2..4], n -> ForAll(AllSmallGroups(n), G -> IsCancellative(G)));
gap> ForAll(AllSmallGroups([2 .. 4]), G -> IsCancellative(G));
true

gap> ForAny([2..3], n -> ForAny(AllSmallAntimagmas(n), M -> IsCancellative(M)));
gap> ForAny(AllSmallAntimagmas([2 .. 3]), M -> IsCancellative(M));
false

gap> STOP_TEST( "test_properties_magma_left_right_cancellative.tst" );
8 changes: 4 additions & 4 deletions tst/test_properties_magma_left_right_cylic.tst
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
gap> START_TEST( "test_properties_magma_left_right_cyclic.tst" );

gap> ForAll([2..12], n -> ForAll(Filtered(AllSmallGroups(n), G -> not IsCyclic(G)), G -> not IsLeftCyclic(G)) );
gap> ForAll(Filtered(AllSmallGroups([2 .. 12]), G -> not IsCyclic(G)), G -> not IsLeftCyclic(G));
true

gap> ForAll([2..12], n -> ForAll(Filtered(AllSmallGroups(n), G -> IsCyclic(G)), G -> IsLeftCyclic(G)) );
gap> ForAll(Filtered(AllSmallGroups([2 .. 12]), G -> IsCyclic(G)), G -> IsLeftCyclic(G));
true

gap> ForAll([2..12], n -> ForAll(Filtered(AllSmallGroups(n), G -> not IsCyclic(G)), G -> not IsRightCyclic(G)) );
gap> ForAll(Filtered(AllSmallGroups([2 .. 12]), G -> not IsCyclic(G)), G -> not IsRightCyclic(G));
true

gap> ForAll([2..12], n -> ForAll(Filtered(AllSmallGroups(n), G -> IsCyclic(G)), G -> IsRightCyclic(G)) );
gap> ForAll(Filtered(AllSmallGroups([2 .. 12]), G -> IsCyclic(G)), G -> IsRightCyclic(G));
true

gap> STOP_TEST( "test_properties_magma_left_right_cyclic.tst" );
42 changes: 42 additions & 0 deletions tst/test_utils.tst
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,47 @@ gap> List(Cartesian(Ms_2, Ms_3), M -> IsMagmaIsomorphic(M[1], M[2]));
gap> List(Cartesian(Ms_2, Ms_3), M -> MagmaIsomorphism(M[1], M[2]));
[ fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail, fail ]

gap> GeneratePossibleDiagonals(2);
[ [ 2, 1 ] ]

gap> GeneratePossibleDiagonals(3);
[
[ 2, 1, 1 ], [ 2, 1, 2 ],
[ 2, 3, 1 ], [ 2, 3, 2 ],
[ 3, 1, 1 ], [ 3, 1, 2 ],
[ 3, 3, 1 ], [ 3, 3, 2 ]
]

gap> GeneratePossibleDiagonals(4);
[
[ 2, 1, 1, 1 ], [ 2, 1, 1, 2 ], [ 2, 1, 1, 3 ],
[ 2, 1, 2, 1 ], [ 2, 1, 2, 2 ], [ 2, 1, 2, 3 ],
[ 2, 1, 4, 1 ], [ 2, 1, 4, 2 ], [ 2, 1, 4, 3 ],
[ 2, 3, 1, 1 ], [ 2, 3, 1, 2 ], [ 2, 3, 1, 3 ],
[ 2, 3, 2, 1 ], [ 2, 3, 2, 2 ], [ 2, 3, 2, 3 ],
[ 2, 3, 4, 1 ], [ 2, 3, 4, 2 ], [ 2, 3, 4, 3 ],
[ 2, 4, 1, 1 ], [ 2, 4, 1, 2 ], [ 2, 4, 1, 3 ],
[ 2, 4, 2, 1 ], [ 2, 4, 2, 2 ], [ 2, 4, 2, 3 ],
[ 2, 4, 4, 1 ], [ 2, 4, 4, 2 ], [ 2, 4, 4, 3 ],
[ 3, 1, 1, 1 ], [ 3, 1, 1, 2 ], [ 3, 1, 1, 3 ],
[ 3, 1, 2, 1 ], [ 3, 1, 2, 2 ], [ 3, 1, 2, 3 ],
[ 3, 1, 4, 1 ], [ 3, 1, 4, 2 ], [ 3, 1, 4, 3 ],
[ 3, 3, 1, 1 ], [ 3, 3, 1, 2 ], [ 3, 3, 1, 3 ],
[ 3, 3, 2, 1 ], [ 3, 3, 2, 2 ], [ 3, 3, 2, 3 ],
[ 3, 3, 4, 1 ], [ 3, 3, 4, 2 ], [ 3, 3, 4, 3 ],
[ 3, 4, 1, 1 ], [ 3, 4, 1, 2 ], [ 3, 4, 1, 3 ],
[ 3, 4, 2, 1 ], [ 3, 4, 2, 2 ], [ 3, 4, 2, 3 ],
[ 3, 4, 4, 1 ], [ 3, 4, 4, 2 ], [ 3, 4, 4, 3 ],
[ 4, 1, 1, 1 ], [ 4, 1, 1, 2 ], [ 4, 1, 1, 3 ],
[ 4, 1, 2, 1 ], [ 4, 1, 2, 2 ], [ 4, 1, 2, 3 ],
[ 4, 1, 4, 1 ], [ 4, 1, 4, 2 ], [ 4, 1, 4, 3 ],
[ 4, 3, 1, 1 ], [ 4, 3, 1, 2 ], [ 4, 3, 1, 3 ],
[ 4, 3, 2, 1 ], [ 4, 3, 2, 2 ], [ 4, 3, 2, 3 ],
[ 4, 3, 4, 1 ], [ 4, 3, 4, 2 ], [ 4, 3, 4, 3 ],
[ 4, 4, 1, 1 ], [ 4, 4, 1, 2 ], [ 4, 4, 1, 3 ],
[ 4, 4, 2, 1 ], [ 4, 4, 2, 2 ], [ 4, 4, 2, 3 ],
[ 4, 4, 4, 1 ], [ 4, 4, 4, 2 ], [ 4, 4, 4, 3 ]
]

gap> STOP_TEST( "test_utils.tst" );

0 comments on commit 8af58a2

Please sign in to comment.