2017-10-18 10:46:13 +00:00
|
|
|
## structure.gi RAQ Implementation of definitiions, reps, and elt operations
|
|
|
|
|
|
|
|
## Create structures with generators
|
2017-10-18 11:19:57 +00:00
|
|
|
InstallGlobalFunction(CloneOfTypeByGenerators,
|
2017-10-18 20:00:02 +00:00
|
|
|
function(cat, fam, gens, genAttrib, tableCstr)
|
2017-10-18 10:46:13 +00:00
|
|
|
local M;
|
|
|
|
if not(IsEmpty(gens) or IsIdenticalObj(FamilyObj(gens), fam)) then
|
|
|
|
Error("<fam> and family of <gens> do not match");
|
|
|
|
fi;
|
|
|
|
M := Objectify(NewType( fam, cat and IsAttributeStoringRep), rec());
|
|
|
|
Setter(genAttrib)(M, AsList(gens));
|
2017-10-18 19:37:48 +00:00
|
|
|
SetConstructorFromTable(M, tableCstr);
|
2017-10-18 10:46:13 +00:00
|
|
|
return M;
|
|
|
|
end);
|
|
|
|
|
|
|
|
## Functions for each of the magma categories here
|
|
|
|
InstallGlobalFunction(LeftQuasigroup, function(arg)
|
|
|
|
local fam;
|
|
|
|
if Length(arg) = 0 then
|
|
|
|
Error("usage: LeftQuasigroup([<family>], <gens>)");
|
|
|
|
fi;
|
|
|
|
# Extract the family
|
|
|
|
if IsFamily(arg[1]) then
|
2017-10-18 11:25:13 +00:00
|
|
|
fam := arg[1];
|
2017-10-18 10:46:13 +00:00
|
|
|
Remove(arg, 1);
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
2017-10-18 10:46:13 +00:00
|
|
|
else
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
|
|
|
fam := FamilyObj(arg[1]);
|
2017-10-18 10:46:13 +00:00
|
|
|
fi;
|
|
|
|
return CloneOfTypeByGenerators(IsLeftQuasigroup, fam, arg,
|
2017-10-18 19:37:48 +00:00
|
|
|
GeneratorsOfLeftQuasigroup,
|
|
|
|
LeftQuasigroupByMultiplicationTable);
|
2017-10-18 10:46:13 +00:00
|
|
|
end);
|
|
|
|
|
|
|
|
InstallGlobalFunction(LeftRack, function(arg)
|
|
|
|
local fam;
|
|
|
|
if Length(arg) = 0 then
|
|
|
|
Error("usage: LeftRack([<family>], <gens>)");
|
|
|
|
fi;
|
|
|
|
# Extract the family
|
|
|
|
if IsFamily(arg[1]) then
|
2017-10-18 11:25:13 +00:00
|
|
|
fam := arg[1];
|
2017-10-18 10:46:13 +00:00
|
|
|
Remove(arg, 1);
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
2017-10-18 10:46:13 +00:00
|
|
|
else
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
|
|
|
fam := FamilyObj(arg[1]);
|
2017-10-18 10:46:13 +00:00
|
|
|
fi;
|
|
|
|
return CloneOfTypeByGenerators(IsLeftRack, fam, arg,
|
2017-10-18 19:37:48 +00:00
|
|
|
GeneratorsOfLeftQuasigroup,
|
|
|
|
LeftRackByMultiplicationTableNC);
|
2017-10-18 10:46:13 +00:00
|
|
|
end);
|
|
|
|
|
|
|
|
InstallGlobalFunction(RightQuasigroup, function(arg)
|
|
|
|
local fam;
|
|
|
|
if Length(arg) = 0 then
|
|
|
|
Error("usage: RightQuasigroup([<family>], <gens>)");
|
|
|
|
fi;
|
|
|
|
# Extract the family
|
|
|
|
if IsFamily(arg[1]) then
|
2017-10-18 11:25:13 +00:00
|
|
|
fam := arg[1];
|
2017-10-18 10:46:13 +00:00
|
|
|
Remove(arg, 1);
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
2017-10-18 10:46:13 +00:00
|
|
|
else
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
|
|
|
fam := FamilyObj(arg[1]);
|
2017-10-18 10:46:13 +00:00
|
|
|
fi;
|
|
|
|
return CloneOfTypeByGenerators(IsRightQuasigroup, fam, arg,
|
2017-10-18 19:37:48 +00:00
|
|
|
GeneratorsOfRightQuasigroup,
|
|
|
|
RightQuasigroupByMultiplicationTable);
|
2017-10-18 10:46:13 +00:00
|
|
|
end);
|
|
|
|
|
|
|
|
InstallGlobalFunction(RightRack, function(arg)
|
|
|
|
local fam;
|
|
|
|
if Length(arg) = 0 then
|
|
|
|
Error("usage: RightRack([<family>], <gens>)");
|
|
|
|
fi;
|
|
|
|
# Extract the family
|
|
|
|
if IsFamily(arg[1]) then
|
2017-10-18 11:25:13 +00:00
|
|
|
fam := arg[1];
|
2017-10-18 10:46:13 +00:00
|
|
|
Remove(arg, 1);
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
2017-10-18 10:46:13 +00:00
|
|
|
else
|
2017-10-18 11:25:13 +00:00
|
|
|
arg := Flat(arg);
|
|
|
|
fam := FamilyObj(arg[1]);
|
2017-10-18 10:46:13 +00:00
|
|
|
fi;
|
|
|
|
return CloneOfTypeByGenerators(IsRightRack, fam, arg,
|
2017-10-18 19:37:48 +00:00
|
|
|
GeneratorsOfRightQuasigroup,
|
|
|
|
RightRackByMultiplicationTableNC);
|
2017-10-18 10:46:13 +00:00
|
|
|
end);
|
|
|
|
|
2017-10-18 19:37:48 +00:00
|
|
|
## Predicates to check tables for distributivity
|
|
|
|
InstallMethod(IsRightSelfDistributiveTable, "for matrix",
|
|
|
|
[ IsMatrix ],
|
|
|
|
T -> IsLeftSelfDistributiveTable(TransposedMat(T))
|
|
|
|
);
|
|
|
|
|
|
|
|
InstallMethod(IsLeftSelfDistributiveTable, "for matrix",
|
|
|
|
[ IsMatrix ],
|
|
|
|
function(T)
|
|
|
|
# Everybody else does it by checking all of the cases, so why not me, too?
|
|
|
|
# Is there a better way?
|
|
|
|
local n,i,j,k;
|
|
|
|
n := Length(T);
|
|
|
|
for i in [1..n] do for j in [1..n] do for k in [1..n] do
|
|
|
|
if T[i, T[j,k]] <> T[T[i,j], T[i,k]] then return false; fi;
|
|
|
|
od; od; od;
|
|
|
|
return true;
|
|
|
|
end);
|
|
|
|
|
2017-10-18 10:46:13 +00:00
|
|
|
## And now create them from multiplication tables
|
|
|
|
InstallGlobalFunction(LeftQuasigroupByMultiplicationTable,
|
|
|
|
function(T)
|
|
|
|
if not IsLeftQuasigroupTable(T) then
|
|
|
|
Error("Multiplication table <T> must have each row a permutation of ",
|
|
|
|
"the same entries.");
|
|
|
|
fi;
|
|
|
|
return MagmaByMultiplicationTableCreatorNC(
|
|
|
|
CanonicalCayleyTableOfLeftQuasigroupTable(T),
|
|
|
|
LeftQuasigroup,
|
|
|
|
IsLeftQuotientElement and IsMagmaByMultiplicationTableObj
|
|
|
|
);
|
|
|
|
end);
|
|
|
|
|
2017-10-18 19:37:48 +00:00
|
|
|
InstallGlobalFunction(RightQuasigroupByMultiplicationTable,
|
|
|
|
function(T)
|
|
|
|
if not IsRightQuasigroupTable(T) then
|
|
|
|
Error("Multiplication table <T> must have each column a permutation of ",
|
|
|
|
"the same entries.");
|
|
|
|
fi;
|
|
|
|
return MagmaByMultiplicationTableCreatorNC(
|
|
|
|
CanonicalCayleyTable(T),
|
|
|
|
RightQuasigroup,
|
|
|
|
IsRightQuotientElement and IsMagmaByMultiplicationTableObj
|
|
|
|
);
|
|
|
|
end);
|
|
|
|
|
|
|
|
InstallGlobalFunction(LeftRackByMultiplicationTable,
|
|
|
|
function(T)
|
|
|
|
if not IsLeftQuasigroupTable(T) then
|
|
|
|
Error("Multiplication table <T> must have each row a permutation of ",
|
|
|
|
"the same entries.");
|
|
|
|
fi;
|
|
|
|
T := CanonicalCayleyTableOfLeftQuasigroupTable(T);
|
|
|
|
if not IsLeftSelfDistributiveTable(T) then
|
|
|
|
Error("Multiplication table <T> must be left self distributive.");
|
|
|
|
fi;
|
|
|
|
return LeftRackByMulitplicationTableNC(T);
|
|
|
|
end);
|
|
|
|
|
|
|
|
InstallGlobalFunction(LeftRackByMulitplicationTableNC,
|
|
|
|
T -> MagmaByMultiplicationTableCreatorNC(T, LeftRack,
|
|
|
|
IsLeftQuotientElement and IsLSelfDistributiveElement and
|
|
|
|
IsMagmaByMultiplicationTableObj
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
InstallGlobalFunction(RightRackByMultiplicationTable,
|
|
|
|
function(T)
|
|
|
|
if not IsRightQuasigroupTable(T) then
|
|
|
|
Error("Multiplication table <T> must have each column a permutation of ",
|
|
|
|
"the same entries.");
|
|
|
|
fi;
|
|
|
|
T := CanonicalCayleyTable(T);
|
|
|
|
if not IsRightSelfDistributiveTable(T) then
|
|
|
|
Error("Multiplication table <T> must be right self distributive.");
|
|
|
|
fi;
|
|
|
|
return RightRackByMultiplicationTableNC(T);
|
|
|
|
end);
|
|
|
|
|
|
|
|
InstallGlobalFunction(RightRackByMultiplicationTableNC,
|
|
|
|
T -> MagmaByMultiplicationTableCreatorNC(T, RightRack,
|
|
|
|
IsRightQuotientElement and IsRSelfDistributiveElement and
|
|
|
|
IsMagmaByMultiplicationTableObj
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
## And define the operations
|
2017-10-18 10:46:13 +00:00
|
|
|
|
|
|
|
InstallOtherMethod(LeftQuotient,
|
|
|
|
"for two elts in magma by mult table, when left has left quotients",
|
|
|
|
IsIdenticalObj,
|
|
|
|
[IsLeftQuotientElement, IsMagmaByMultiplicationTableObj],
|
|
|
|
function (l,r)
|
2017-10-18 11:36:38 +00:00
|
|
|
local fam, ix;
|
|
|
|
fam := FamilyObj(l);
|
|
|
|
ix := LeftDivisionTable(fam)[l![1],r![1]];
|
|
|
|
return fam!.set[ix];
|
2017-10-18 10:46:13 +00:00
|
|
|
end);
|
|
|
|
|
2017-10-18 19:37:48 +00:00
|
|
|
InstallOtherMethod(\/,
|
|
|
|
"for two elts in magma by mult table, when right has right quotients",
|
|
|
|
IsIdenticalObj,
|
|
|
|
[IsMagmaByMultiplicationTableObj, IsRightQuotientElement],
|
|
|
|
function (l,r)
|
|
|
|
local fam, ix;
|
|
|
|
fam := FamilyObj(r);
|
|
|
|
ix := RightDivisionTable(fam)[l![1],r![1]];
|
|
|
|
return fam!.set[ix];
|
|
|
|
end);
|
|
|
|
|
2017-10-18 10:46:13 +00:00
|
|
|
## Create division tables as needed
|
|
|
|
InstallMethod(LeftDivisionTable,
|
2017-10-18 19:37:48 +00:00
|
|
|
"for an object with a multiplication table",
|
|
|
|
[HasMultiplicationTable],
|
2017-10-18 10:46:13 +00:00
|
|
|
function(fam)
|
|
|
|
local LS, n;
|
2017-10-18 19:37:48 +00:00
|
|
|
LS := LeftPerms(fam);
|
2017-10-18 11:32:42 +00:00
|
|
|
n := Size(LS);
|
|
|
|
return List(LS, x->ListPerm(Inverse(x), n));
|
2017-10-18 10:46:13 +00:00
|
|
|
end);
|
|
|
|
|
2017-10-18 19:37:48 +00:00
|
|
|
InstallMethod(RightDivisionTable,
|
|
|
|
"for an object with a multiplication table",
|
|
|
|
[HasMultiplicationTable],
|
|
|
|
function (obj)
|
|
|
|
local RS, n;
|
|
|
|
RS := RightPerms(fam);
|
|
|
|
n := Size(RS);
|
|
|
|
return TransposedMat(List(RS, x->ListPerm(Inverse(x), n)));
|
|
|
|
end);
|
|
|
|
|
|
|
|
## Create perm lists as needed
|
|
|
|
InstallMethod(LeftPerms,
|
|
|
|
"for an object with a multiplication table",
|
|
|
|
[HasMultiplicationTable],
|
2017-10-18 10:46:13 +00:00
|
|
|
function(fam)
|
|
|
|
return List(MultiplicationTable(fam), x->PermList(x));
|
|
|
|
end);
|
|
|
|
|
2017-10-18 19:37:48 +00:00
|
|
|
InstallMethod(RightPerms,
|
|
|
|
"for an object with a muliplication table",
|
|
|
|
[HasMultiplicationTable],
|
|
|
|
function(fam)
|
|
|
|
return List(TransposedMat(MultiplicationTable(fam)), x->PermList(x));
|
|
|
|
end);
|
2017-10-18 19:55:52 +00:00
|
|
|
|
|
|
|
## Special case the Opposite function from LOOPS package, since the opposite
|
|
|
|
## of a left quasigroup is a right quasigroup and vice versa
|
|
|
|
|
|
|
|
# Is there a way to do this just once for each direction?
|
|
|
|
InstallMethod(Opposite, "for left quasigroup",
|
|
|
|
[ IsLeftQuasigroup ],
|
|
|
|
L -> RightQuasigroupByMultiplicationTable(
|
|
|
|
TransposedMat(MultiplicationTable(L))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
InstallMethod(Opposite, "for left rack",
|
|
|
|
[ IsLeftRack ],
|
|
|
|
L -> RightRackByMultiplicationTableNC(TransposedMat(MultiplicationTable(L)))
|
|
|
|
);
|
|
|
|
|
|
|
|
InstallMethod(Opposite, "for right quasigroup",
|
|
|
|
[ IsRightQuasigroup ],
|
|
|
|
L -> LeftQuasigroupByMultiplicationTable(
|
|
|
|
TransposedMat(MultiplicationTable(L))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
InstallMethod(Opposite, "for right rack",
|
|
|
|
[ IsRightRack ],
|
|
|
|
L -> LeftRackByMultiplicationTableNC(TransposedMat(MultiplicationTable(L)))
|
|
|
|
);
|