string conversions and showing objects

This commit is contained in:
Glen Whitney 2017-10-19 01:12:31 +02:00
parent 384270d9db
commit f065049281

View File

@ -247,6 +247,123 @@ InstallMethod(IsRSelfDistributive, "for magma",
M -> IsRightSelfDistributiveTable(MultiplicationTable(M))
);
## View and print and such
LeftObjString@ := function(Q)
if HasIsLeftRack(Q) and IsLeftRack(Q) then return "LeftRack"; fi;
return "LeftQuasigroup";
end;
RightObjString@ := function(Q)
if HasIsRightRack(Q) and IsRightRack(Q) then return "RightRack"; fi;
return "RightQuasigroup";
end;
InstallMethod(String, "for a left quasigroup",
[IsLeftQuasigroup],
Q -> Concatenation(LeftObjString@(Q), "(...)");
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],
Q -> Concatenation(RightObjString@(Q), "(...)");
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(DisplayString, "for a one-sided quasigroup",
[IsLeftQuasigroup or IsRightQuasigroup],
Q -> String(Q));
InstallMethod(Display, "for a left quasigroup with multiplication table",
[IsLeftQuasigroup and HasMultiplicationTable],
function(Q)
Print(LeftObjString@, " with ", Size(Q),
" 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@, " with ", Size(Q),
" elements, generated by ",
GeneratorsOfRightQuasigroup(Q), ", with table\n");
Display(MultiplicationTable(Q));
end);
LeftObjView@ := function(Q)
if HasIsLeftRack(Q) and IsLeftRack(Q) then return "<left rack"; fi;
return "<left quasigroup";
end;
RightObjView@ := function(Q)
if HasIsRightRack(Q) and IsRightRack(Q) then return "<right rack"; fi;
return "<right quasigroup";
end;
InstallMethod(ViewString, "for a left quasigroup",
[IsLeftQuasigroup],
Q -> Concatenation(LeftObjView@(Q), ">");
InstallMethod(ViewString, "for a left quasigroup with generators",
[IsLeftQuasigroup and HasGeneratorsOfLeftQuasigroup],
Q -> Concatenation(LeftObjView@(Q), " with ",
Size(GeneratorsOfLeftQuasigroup),
" generators>"));
InstallMethod(ViewString, "for a right quasigroup",
[IsRightQuasigroup],
Q -> Concatenation(RightObjView@(Q), ">");
InstallMethod(ViewString, "for a right quasigroup with generators",
[IsRightQuasigroup and HasGeneratorsOfRightQuasigroup],
Q -> Concatenation(RightObjView@(Q), " with ",
Size(GeneratorsOfRightQuasigroup),
" generators>"));
# Patch View/Print/Display for magma by mult objects
InstallMethod(String, "for an element of magma by multiplication table",
[IsMagmaByMultiplicationTableObj],
function(obj)
local fam;
fam := FamilyObj(obj);
if IsBound(fam!.elmNamePrefix) then
return Concatenation(fam!.elmNamePrefix, String(obj![1]));
fi;
return Concatenation("m", String(obj![1]));
end);
InstallMethod(ViewString, "for an element of magma by multiplication table",
[IsMagmaByMultiplicationTableObj],
obj -> String(obj));
InstallMethod(DisplayString, "for an element of magma by multiplication table",
[IsMagmaByMultiplicationTableObj],
obj -> String(obj));
InstallMethod(PrintObj, "for an element of magma by multiplication table",
[IsMagmaByMultiplicationTableObj],
function(obj) Print(String(obj)); end);
## Special case the Opposite function from LOOPS package, since the opposite
## of a left quasigroup is a right quasigroup and vice versa