From 1ac424c52494f5fd83a21ec1c7cc7e250a38fb70 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Wed, 18 Oct 2017 21:36:03 +0200 Subject: [PATCH] Lift some functions to magmas in general --- gap/quasigroups.gd | 9 +++-- gap/quasigroups.gi | 92 ++++++++++++++++++++++++++++------------------ 2 files changed, 62 insertions(+), 39 deletions(-) diff --git a/gap/quasigroups.gd b/gap/quasigroups.gd index d97a8dd..aee54d3 100644 --- a/gap/quasigroups.gd +++ b/gap/quasigroups.gd @@ -96,11 +96,12 @@ DeclareOperation( "NormalizedQuasigroupTable", [ IsMatrix ] ); ## CREATING QUASIGROUPS AND LOOPS MANUALLY ## ------------------------------------------------------------------------- -DeclareAttribute( "CayleyTable", IsQuasigroup ); +DeclareAttribute( "CayleyTable", IsMagma ); DeclareOperation( "QuasigroupByCayleyTable", [ IsMatrix ] ); DeclareOperation( "LoopByCayleyTable", [ IsMatrix ] ); DeclareOperation( "SetQuasigroupElmName", [ IsQuasigroup, IsString ] ); DeclareSynonym( "SetLoopElmName", SetQuasigroupElmName ); +DeclareAttribute( "ConstructorFromTable", IsMagma ); DeclareOperation( "CanonicalCopy", [ IsMagma ] ); ############################################################################# @@ -142,9 +143,9 @@ DeclareOperation( "IntoGroup", [ IsMagma ] ); ## OPPOSITE QUASIGROUPS AND LOOPS ## -------------------------------------------------------------------------- -DeclareOperation( "OppositeQuasigroup", [ IsQuasigroup ] ); -DeclareOperation( "OppositeLoop", [ IsLoop ] ); -DeclareAttribute( "Opposite", IsQuasigroup ); +DeclareGlobalFunction( "OppositeQuasigroup"); +DeclareGlobalFunction( "OppositeLoop"); +DeclareAttribute( "Opposite", IsMagma ); ############################################################################# ## AUXILIARY diff --git a/gap/quasigroups.gi b/gap/quasigroups.gi index ca43e40..51fccb5 100644 --- a/gap/quasigroups.gi +++ b/gap/quasigroups.gi @@ -149,10 +149,12 @@ end ); ## #A CayleyTable( Q ) ## -## Returns the Cayley table of the quasigroup +## Returns the Cayley table of the magma . This is just like +## its multiplication table, except in case Q is a submagma of P, in which +## case the entries used are the indices in P rather than in Q. -InstallMethod( CayleyTable, "for quasigroup", - [ IsQuasigroup ], +InstallMethod( CayleyTable, "for magma", + [ IsMagma ], function( Q ) local elms, parent_elms; elms := Elements( Q ); @@ -194,6 +196,7 @@ function( ct ) SetAsSSortedList( Q, elms ); SetParent( Q, Q ); SetCayleyTable( Q, ct ); + SetConstructorFromTable(QuasigroupByCayleyTable); return Q; end ); @@ -232,6 +235,7 @@ function( ct ) SetParent( L, L ); SetCayleyTable( L, ct ); SetOne( L, elms[ 1 ] ); + SetConstructorFromTable(LoopByCayleyTable); return L; end ); @@ -249,22 +253,50 @@ function( Q, name ) F!.names := name; end); +############################################################################# +## +#O ConstructorFromTable( M ) +## +## Given a magma , returns a function which will create a domain of the +## same structure as M from from an operation table. This implementation of +## the method is to backfill the constructors for library domains that do +## not set the attribute directly at construction time. New domains that wish +## to use facilities like CanonicalCopy or Opposite should call +## SetConstructorFromTable at creation time. + +InstallMethod( ConstructorFromTable, "for other magmas", + [ IsMagma ], + function ( M ) + # Go in reverse order of refinement of structure + if IsGroup(M) then + return GroupByMultiplicationTable; + elif IsMagmaWithInverses(M) then + return MagmaWithInversesByMultiplicationTable; + elif IsMonoid(M) then + return MonoidByMultiplicationTable; + elif IsMagmaWithOne(M) then + return MagmaWithOneByMultiplicationTable; + elif IsSemigroup(M) then + return SemigroupByMultiplicationTable; + fi; + return MagmaByMultiplicationTable; +end); + + ############################################################################# ## #O CanonicalCopy( Q ) ## ## Returns a canonical copy of , that is, an isomorphic object with -## canonical multiplication table and Parent( ) = . +## canonical multiplication table and no parent set. Note that this is +## guaranteed to be a new object, not satisfying IsIdenticalObj with any +## previously existing structure. THEREFORE: ## (PROG) Properties and attributes are lost! -InstallMethod( CanonicalCopy, "for quasigroup or loop", - [ IsQuasigroup ], -function( Q ) - if IsLoop( Q ) then - return LoopByCayleyTable( CayleyTable( Q ) ); - fi; - return QuasigroupByCayleyTable( CayleyTable( Q ) ); -end); +InstallMethod( CanonicalCopy, "for magma", + [ IsMagma ], + M -> ConstructorFromTable(M)(MultiplicationTable(M)); +); ############################################################################# @@ -768,41 +800,31 @@ function( list, dummy ) ## #O OppositeQuasigroup( Q ) ## -## Returns the quasigroup opposite to the quasigroup . +## Identical to Opposite, except forces its return to be a quasigroup if +## possible -InstallMethod( OppositeQuasigroup, "for quasigroup", - [ IsQuasigroup ], -function( Q ) - return QuasigroupByCayleyTable( TransposedMat( CayleyTable( Q ) ) ); -end ); +InstallGlobalFunction( OppositeQuasigroup, + Q -> IntoQuasigroup( Opposite( L ) ) ); ############################################################################# ## #O OppositeLoop( Q ) ## -## Returns the loop opposite to the loop . +## Identical to Opposite, except forces its return to be a loop if possible -InstallMethod( OppositeLoop, "for loop", - [ IsLoop ], -function( Q ) - return LoopByCayleyTable( TransposedMat( CayleyTable( Q ) ) ); -end ); +InstallGlobalFunction( OppositeLoop, L -> IntoLoop( Opposite( L ) ) ); ############################################################################# ## -#A Opposite( Q ) +#A Opposite( M ) ## -## Returns the quasigroup opposite to the quasigroup . When -## is a loop, a loop is returned. +## Returns the magma opposite to the magma , with as much structure +## as can be preserved. -InstallMethod( Opposite, "for quasigroup", - [ IsQuasigroup ], -function( Q ) - if IsLoop( Q ) then - return LoopByCayleyTable( TransposedMat( CayleyTable( Q ) ) ); - fi; - return QuasigroupByCayleyTable( TransposedMat( CayleyTable( Q ) ) ); -end ); +InstallMethod( Opposite, "for magma", + [ IsMagma ], + M -> ConstructorFromTable(M)( TransposedMat( MultiplicationTable( M ) ) ) +); ############################################################################# ## DISPLAYING QUASIGROUPS AND LOOPS