RAQ/gap/structure.gi

257 lines
8.3 KiB
Plaintext
Raw Normal View History

## structure.gi RAQ Implementation of definitiions, reps, and elt operations
## Create structures with generators
InstallGlobalFunction(CloneOfTypeByGenerators,
2017-10-18 20:00:02 +00:00
function(cat, fam, gens, genAttrib, tableCstr)
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));
SetConstructorFromTable(M, tableCstr);
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];
Remove(arg, 1);
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
else
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
fam := FamilyObj(arg);
fi;
return CloneOfTypeByGenerators(IsLeftQuasigroup, fam, arg,
GeneratorsOfLeftQuasigroup,
LeftQuasigroupByMultiplicationTableNC);
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];
Remove(arg, 1);
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
else
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
fam := FamilyObj(arg);
fi;
return CloneOfTypeByGenerators(IsLeftRack, fam, arg,
GeneratorsOfLeftQuasigroup,
LeftRackByMultiplicationTableNC);
end);
InstallGlobalFunction(LeftQuandle, function(arg)
local fam;
if Length(arg) = 0 then
Error("usage: LeftQuandle([<family>], <gens>)");
fi;
# Extract the family
if IsFamily(arg[1]) then
fam := arg[1];
Remove(arg, 1);
arg := Flat(arg);
else
arg := Flat(arg);
fam := FamilyObj(arg);
fi;
return CloneOfTypeByGenerators(IsLeftQuandle, fam, arg,
GeneratorsOfLeftQuasigroup,
LeftQuandleByMultiplicationTableNC);
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];
Remove(arg, 1);
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
else
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
fam := FamilyObj(arg);
fi;
return CloneOfTypeByGenerators(IsRightQuasigroup, fam, arg,
GeneratorsOfRightQuasigroup,
RightQuasigroupByMultiplicationTableNC);
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];
Remove(arg, 1);
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
else
2017-10-18 11:25:13 +00:00
arg := Flat(arg);
fam := FamilyObj(arg);
fi;
return CloneOfTypeByGenerators(IsRightRack, fam, arg,
GeneratorsOfRightQuasigroup,
RightRackByMultiplicationTableNC);
end);
InstallGlobalFunction(RightQuandle, function(arg)
local fam;
if Length(arg) = 0 then
Error("usage: RightQuandle([<family>], <gens>)");
fi;
# Extract the family
if IsFamily(arg[1]) then
fam := arg[1];
Remove(arg, 1);
arg := Flat(arg);
else
arg := Flat(arg);
fam := FamilyObj(arg);
fi;
return CloneOfTypeByGenerators(IsRightQuandle, fam, arg,
GeneratorsOfRightQuasigroup,
RightQuandleByMultiplicationTableNC);
end);
2017-10-18 23:12:31 +00:00
## View and print and such
LeftObjString@ := function(Q)
# Don't test distributivity if we haven't already
if HasIsLSelfDistributive(Q) and IsLeftRack(Q) then
if HasIsElementwiseIdempotent(Q) and IsElementwiseIdempotent(Q) then
return "LeftQuandle";
fi;
return "LeftRack";
fi;
2017-10-18 23:12:31 +00:00
return "LeftQuasigroup";
end;
2017-10-18 23:12:31 +00:00
RightObjString@ := function(Q)
# Don't test distributivity if we haven't already
if HasIsRSelfDistributive(Q) and IsRightRack(Q) then
if HasIsElementwiseIdempotent(Q) and IsElementwiseIdempotent(Q) then
return "RightQuandle";
fi;
return "RightRack";
fi;
2017-10-18 23:12:31 +00:00
return "RightQuasigroup";
end;
InstallMethod(String, "for a left quasigroup",
[IsLeftQuasigroup],
2017-10-18 23:22:48 +00:00
Q -> Concatenation(LeftObjString@(Q), "(...)"));
2017-10-18 23:12:31 +00:00
InstallMethod(String, "for a left quasigroup with generators",
[IsLeftQuasigroup and HasGeneratorsOfLeftQuasigroup],
Q -> Concatenation(LeftObjString@(Q), "( ",
String(GeneratorsOfLeftQuasigroup(Q)), " )"));
InstallMethod(String, "for a left quasigroup with multiplication table",
[IsLeftQuasigroup and HasMultiplicationTable],
Q -> Concatenation(LeftObjString@(Q),
"ByMultiplicationTableNC( ",
String(MultiplicationTable(Q)), " )"));
InstallMethod(String, "for a right quasigroup",
[IsRightQuasigroup],
2017-10-18 23:22:48 +00:00
Q -> Concatenation(RightObjString@(Q), "(...)"));
2017-10-18 23:12:31 +00:00
InstallMethod(String, "for a right quasigroup with generators",
[IsRightQuasigroup and HasGeneratorsOfRightQuasigroup],
Q -> Concatenation(RightObjString@(Q), "( ",
String(GeneratorsOfRightQuasigroup(Q)), " )"));
InstallMethod(String, "for a right quasigroup with multiplication table",
[IsRightQuasigroup and HasMultiplicationTable],
Q -> Concatenation(RightObjString@(Q),
"ByMultiplicationTableNC( ",
String(MultiplicationTable(Q)), " )"));
InstallMethod(PrintString, "for a left quasigroup",
[IsLeftQuasigroup], Q -> String(Q));
InstallMethod(PrintString, "for a right quasigroup",
[IsRightQuasigroup], Q -> String(Q));
2017-10-18 23:30:57 +00:00
InstallMethod(DisplayString, "for a left quasigroup",
[IsLeftQuasigroup], Q -> String(Q));
InstallMethod(DisplayString, "for a right quasigroup",
2017-10-18 23:30:57 +00:00
[IsRightQuasigroup], Q -> String(Q));
2017-10-18 23:12:31 +00:00
InstallMethod(Display, "for a left quasigroup with multiplication table",
[IsLeftQuasigroup and HasMultiplicationTable],
function(Q)
Print(LeftObjString@(Q), " with ", Size(Q),
2017-10-18 23:12:31 +00:00
" elements, generated by ",
GeneratorsOfLeftQuasigroup(Q), ", with table\n");
Display(MultiplicationTable(Q));
end);
InstallMethod(Display, "for a right quasigroup with multiplication table",
[IsRightQuasigroup and HasMultiplicationTable],
function(Q)
Print(RightObjString@(Q), " with ", Size(Q),
2017-10-18 23:12:31 +00:00
" elements, generated by ",
GeneratorsOfRightQuasigroup(Q), ", with table\n");
Display(MultiplicationTable(Q));
end);
LeftObjView@ := function(Q)
# Don't test distributivity if we haven't already
if HasIsLSelfDistributive(Q) and IsLeftRack(Q) then
if HasIsElementwiseIdempotent(Q) and IsElementwiseIdempotent(Q) then
return "<left quandle";
fi;
return "<left rack";
fi;
2017-10-18 23:12:31 +00:00
return "<left quasigroup";
end;
2017-10-18 23:12:31 +00:00
RightObjView@ := function(Q)
# Don't test distributivity if we haven't already
if HasIsRSelfDistributive(Q) and IsRightRack(Q) then
if HasIsElementwiseIdempotent(Q) and IsElementwiseIdempotent(Q) then
return "<right quandle";
fi;
return "<right rack";
fi;
2017-10-18 23:12:31 +00:00
return "<right quasigroup";
end;
InstallMethod(ViewString, "for a left quasigroup",
[IsLeftQuasigroup],
2017-10-18 23:37:07 +00:00
Q -> Concatenation(LeftObjView@(Q), ">"));
2017-10-18 23:12:31 +00:00
InstallMethod(ViewString, "for a left quasigroup with generators",
[IsLeftQuasigroup and HasGeneratorsOfLeftQuasigroup],
Q -> Concatenation(LeftObjView@(Q), " with ",
2017-10-18 23:39:48 +00:00
String(Size(GeneratorsOfLeftQuasigroup(Q))),
2017-10-18 23:12:31 +00:00
" generators>"));
InstallMethod(ViewString, "for a right quasigroup",
[IsRightQuasigroup],
2017-10-18 23:37:07 +00:00
Q -> Concatenation(RightObjView@(Q), ">"));
2017-10-18 23:12:31 +00:00
InstallMethod(ViewString, "for a right quasigroup with generators",
[IsRightQuasigroup and HasGeneratorsOfRightQuasigroup],
Q -> Concatenation(RightObjView@(Q), " with ",
2017-10-18 23:39:48 +00:00
String(Size(GeneratorsOfRightQuasigroup(Q))),
2017-10-18 23:12:31 +00:00
" generators>"));