Skip to content

Implement Meet/JoinSemilatticeTableIntoDigraph functions #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,7 @@ DeclareOperation("PartialOrderDigraphJoinOfVertices",
[IsDigraph, IsPosInt, IsPosInt]);
DeclareOperation("PartialOrderDigraphMeetOfVertices",
[IsDigraph, IsPosInt, IsPosInt]);

# 11. Operations for tables . . .
DeclareOperation("DigraphFromMeetTable", [IsList]);
DeclareOperation("DigraphFromJoinTable", [IsList]);
81 changes: 81 additions & 0 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# 8. IsSomething
# 9. Connectivity
# 10. Operations for vertices
# 11. Operations for tables
#############################################################################

#############################################################################
Expand Down Expand Up @@ -2683,3 +2684,83 @@ function(D, i, j)

return fail;
end);

#############################################################################
# 11. Operations for tables
#############################################################################

InstallMethod(DigraphFromMeetTable,
"for a meet table for a meet semilattice Digraph",
[IsList],
function(meet_table)
local n, adj, i, j, output;
# Input verification: must be a square matrix
n := Length(meet_table);
if not ForAll(meet_table, row -> Length(row) = n) then
Error("Input is not a square matrix.");
fi;

n := Length(meet_table);

# Initialise adjacency list
# Every node must be related to itself to satisfy reflexitivity
adj := List([1 .. n], x -> [x]);
for i in [1 .. n] do
for j in [1 .. n] do
# meet_table[i][j]=i for meet semilattice
if meet_table[i][j] = i and i <> j then
Add(adj[i], j);
fi;
od;
od;

# Create a Digraph using the adjacency list
output := Digraph(adj);

# Post-condition tests
if IsMeetSemilatticeDigraph(output) then
if DigraphMeetTable(output) = meet_table then
return output;
else return fail;
fi;
else return fail;
fi;
end);

InstallMethod(DigraphFromJoinTable,
"for a join table for a join semilattice Digraph",
[IsList],
function(join_table)
local n, adj, i, j, output;

# Input verification: must be a square matrix
n := Length(join_table);
if not ForAll(join_table, row -> Length(row) = n) then
Error("Input is not a square matrix.");
fi;

# Initialise adjacency list
# Every node must be related to itself to satisfy reflexitivity
adj := List([1 .. n], x -> [x]);
for i in [1 .. n] do
for j in [1 .. n] do
if join_table[i][j] = j and i <> j then
# join_table[i][j] = j for join semilattice
Add(adj[i], j);
fi;
od;
od;

# Create a Digraph using the adjacency list
output := Digraph(adj);

# Post-condition tests
if IsJoinSemilatticeDigraph(output) then
if DigraphJoinTable(output) = join_table then
return output;
else return fail;
fi;
else return fail;
fi;

end);
14 changes: 14 additions & 0 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -3234,6 +3234,20 @@ gap> DigraphEdges(D);
gap> DigraphVertexLabels(D);
[ 1, 2, 3, 6, [ 4, 5 ] ]

# DigraphFromMeetTable
gap> DigraphFromMeetTable([[1, 1], [1, 2]]);
<immutable meet semilattice digraph with 2 vertices, 3 edges>
gap> DigraphFromMeetTable([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 3], [1, 2, 3, 4]]);
<immutable meet semilattice digraph with 4 vertices, 9 edges>
gap> DigraphFromMeetTable([[1, 3, 2], [2, 3, 1], [3, 3, 3]]);
fail

# DigraphFromJoinTable
gap> DigraphFromJoinTable([[1, 3, 3], [3, 2, 3], [3, 3, 3]]);
<immutable join semilattice digraph with 3 vertices, 5 edges>
gap> DigraphFromJoinTable([[1, 3, 2], [2, 3, 1], [3, 3, 3]]);
fail

# DIGRAPHS_UnbindVariables
gap> Unbind(C);
gap> Unbind(D);
Expand Down
Loading