Lift some functions to magmas in general

This commit is contained in:
Glen Whitney 2017-10-18 21:36:03 +02:00
parent cf2bc14423
commit 1ac424c524
2 changed files with 62 additions and 39 deletions

View File

@ -96,11 +96,12 @@ DeclareOperation( "NormalizedQuasigroupTable", [ IsMatrix ] );
## CREATING QUASIGROUPS AND LOOPS MANUALLY ## CREATING QUASIGROUPS AND LOOPS MANUALLY
## ------------------------------------------------------------------------- ## -------------------------------------------------------------------------
DeclareAttribute( "CayleyTable", IsQuasigroup ); DeclareAttribute( "CayleyTable", IsMagma );
DeclareOperation( "QuasigroupByCayleyTable", [ IsMatrix ] ); DeclareOperation( "QuasigroupByCayleyTable", [ IsMatrix ] );
DeclareOperation( "LoopByCayleyTable", [ IsMatrix ] ); DeclareOperation( "LoopByCayleyTable", [ IsMatrix ] );
DeclareOperation( "SetQuasigroupElmName", [ IsQuasigroup, IsString ] ); DeclareOperation( "SetQuasigroupElmName", [ IsQuasigroup, IsString ] );
DeclareSynonym( "SetLoopElmName", SetQuasigroupElmName ); DeclareSynonym( "SetLoopElmName", SetQuasigroupElmName );
DeclareAttribute( "ConstructorFromTable", IsMagma );
DeclareOperation( "CanonicalCopy", [ IsMagma ] ); DeclareOperation( "CanonicalCopy", [ IsMagma ] );
############################################################################# #############################################################################
@ -142,9 +143,9 @@ DeclareOperation( "IntoGroup", [ IsMagma ] );
## OPPOSITE QUASIGROUPS AND LOOPS ## OPPOSITE QUASIGROUPS AND LOOPS
## -------------------------------------------------------------------------- ## --------------------------------------------------------------------------
DeclareOperation( "OppositeQuasigroup", [ IsQuasigroup ] ); DeclareGlobalFunction( "OppositeQuasigroup");
DeclareOperation( "OppositeLoop", [ IsLoop ] ); DeclareGlobalFunction( "OppositeLoop");
DeclareAttribute( "Opposite", IsQuasigroup ); DeclareAttribute( "Opposite", IsMagma );
############################################################################# #############################################################################
## AUXILIARY ## AUXILIARY

View File

@ -149,10 +149,12 @@ end );
## ##
#A CayleyTable( Q ) #A CayleyTable( Q )
## ##
## Returns the Cayley table of the quasigroup <Q> ## Returns the Cayley table of the magma <Q>. 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", InstallMethod( CayleyTable, "for magma",
[ IsQuasigroup ], [ IsMagma ],
function( Q ) function( Q )
local elms, parent_elms; local elms, parent_elms;
elms := Elements( Q ); elms := Elements( Q );
@ -194,6 +196,7 @@ function( ct )
SetAsSSortedList( Q, elms ); SetAsSSortedList( Q, elms );
SetParent( Q, Q ); SetParent( Q, Q );
SetCayleyTable( Q, ct ); SetCayleyTable( Q, ct );
SetConstructorFromTable(QuasigroupByCayleyTable);
return Q; return Q;
end ); end );
@ -232,6 +235,7 @@ function( ct )
SetParent( L, L ); SetParent( L, L );
SetCayleyTable( L, ct ); SetCayleyTable( L, ct );
SetOne( L, elms[ 1 ] ); SetOne( L, elms[ 1 ] );
SetConstructorFromTable(LoopByCayleyTable);
return L; return L;
end ); end );
@ -249,22 +253,50 @@ function( Q, name )
F!.names := name; F!.names := name;
end); end);
#############################################################################
##
#O ConstructorFromTable( M )
##
## Given a magma <M>, 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 ) #O CanonicalCopy( Q )
## ##
## Returns a canonical copy of <Q>, that is, an isomorphic object <O> with ## Returns a canonical copy of <Q>, that is, an isomorphic object <O> with
## canonical multiplication table and Parent( <O> ) = <O>. ## 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! ## (PROG) Properties and attributes are lost!
InstallMethod( CanonicalCopy, "for quasigroup or loop", InstallMethod( CanonicalCopy, "for magma",
[ IsQuasigroup ], [ IsMagma ],
function( Q ) M -> ConstructorFromTable(M)(MultiplicationTable(M));
if IsLoop( Q ) then );
return LoopByCayleyTable( CayleyTable( Q ) );
fi;
return QuasigroupByCayleyTable( CayleyTable( Q ) );
end);
############################################################################# #############################################################################
@ -768,41 +800,31 @@ function( list, dummy )
## ##
#O OppositeQuasigroup( Q ) #O OppositeQuasigroup( Q )
## ##
## Returns the quasigroup opposite to the quasigroup <Q>. ## Identical to Opposite, except forces its return to be a quasigroup if
## possible
InstallMethod( OppositeQuasigroup, "for quasigroup", InstallGlobalFunction( OppositeQuasigroup,
[ IsQuasigroup ], Q -> IntoQuasigroup( Opposite( L ) ) );
function( Q )
return QuasigroupByCayleyTable( TransposedMat( CayleyTable( Q ) ) );
end );
############################################################################# #############################################################################
## ##
#O OppositeLoop( Q ) #O OppositeLoop( Q )
## ##
## Returns the loop opposite to the loop <Q>. ## Identical to Opposite, except forces its return to be a loop if possible
InstallMethod( OppositeLoop, "for loop", InstallGlobalFunction( OppositeLoop, L -> IntoLoop( Opposite( L ) ) );
[ IsLoop ],
function( Q )
return LoopByCayleyTable( TransposedMat( CayleyTable( Q ) ) );
end );
############################################################################# #############################################################################
## ##
#A Opposite( Q ) #A Opposite( M )
## ##
## Returns the quasigroup opposite to the quasigroup <Q>. When ## Returns the magma opposite to the magma <M>, with as much structure
## <Q> is a loop, a loop is returned. ## as can be preserved.
InstallMethod( Opposite, "for quasigroup", InstallMethod( Opposite, "for magma",
[ IsQuasigroup ], [ IsMagma ],
function( Q ) M -> ConstructorFromTable(M)( TransposedMat( MultiplicationTable( M ) ) )
if IsLoop( Q ) then );
return LoopByCayleyTable( TransposedMat( CayleyTable( Q ) ) );
fi;
return QuasigroupByCayleyTable( TransposedMat( CayleyTable( Q ) ) );
end );
############################################################################# #############################################################################
## DISPLAYING QUASIGROUPS AND LOOPS ## DISPLAYING QUASIGROUPS AND LOOPS