From 9b4d4e32331a13ed969c5e3e092ed34c3e79e2f4 Mon Sep 17 00:00:00 2001 From: Marcin Weremczuk Date: Wed, 7 May 2025 17:39:35 +0100 Subject: [PATCH 1/4] Started implementing Meet/JoinSemilatticeTableIntoDigraph functions --- gap/oper.gd | 4 +++ gap/oper.gi | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/gap/oper.gd b/gap/oper.gd index fbfe4c554..2d1511a84 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -154,3 +154,7 @@ DeclareOperation("PartialOrderDigraphJoinOfVertices", [IsDigraph, IsPosInt, IsPosInt]); DeclareOperation("PartialOrderDigraphMeetOfVertices", [IsDigraph, IsPosInt, IsPosInt]); + +# 11. Operations for tables . . . +DeclareOperation("DigraphFromMeetTable", [IsList]) +DeclareOperation("DigraphFromJoinTable", [IsList]) diff --git a/gap/oper.gi b/gap/oper.gi index d934269b6..5987c980f 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -21,6 +21,7 @@ # 8. IsSomething # 9. Connectivity # 10. Operations for vertices +# 11. Operations for tables ############################################################################# ############################################################################# @@ -2679,7 +2680,88 @@ function(D, i, j) if intr = Set(nbs[x]) then return x; fi; - od; + od; 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); + From 7790b9381165fcdb001166031baa2e8b280dde1e Mon Sep 17 00:00:00 2001 From: Marcin Weremczuk Date: Wed, 7 May 2025 17:46:41 +0100 Subject: [PATCH 2/4] Indent fixes --- gap/oper.gi | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gap/oper.gi b/gap/oper.gi index 5987c980f..1e318b5d5 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -2680,7 +2680,7 @@ function(D, i, j) if intr = Set(nbs[x]) then return x; fi; - od; + od; return fail; end); @@ -2741,7 +2741,7 @@ function(join_table) # Initialise adjacency list # Every node must be related to itself to satisfy reflexitivity - adj := List([1..n], x -> [x]); + 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 @@ -2763,5 +2763,4 @@ function(join_table) else return fail; fi; -end); - +end); \ No newline at end of file From f69850d3f9a4b4636585370807b8d631f443c0b7 Mon Sep 17 00:00:00 2001 From: Marcin Weremczuk Date: Wed, 7 May 2025 19:59:37 +0100 Subject: [PATCH 3/4] Fixed typos, added tests --- gap/oper.gd | 4 ++-- tst/standard/oper.tst | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/gap/oper.gd b/gap/oper.gd index 2d1511a84..6a7226bbf 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -156,5 +156,5 @@ DeclareOperation("PartialOrderDigraphMeetOfVertices", [IsDigraph, IsPosInt, IsPosInt]); # 11. Operations for tables . . . -DeclareOperation("DigraphFromMeetTable", [IsList]) -DeclareOperation("DigraphFromJoinTable", [IsList]) +DeclareOperation("DigraphFromMeetTable", [IsList]); +DeclareOperation("DigraphFromJoinTable", [IsList]); \ No newline at end of file diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index e8460bc84..614eaba45 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -3234,6 +3234,20 @@ gap> DigraphEdges(D); gap> DigraphVertexLabels(D); [ 1, 2, 3, 6, [ 4, 5 ] ] +# DigraphFromMeetTable +gap> DigraphFromMeetTable([[1,1],[1,2]]); + +gap> DigraphFromMeetTable([[1, 1, 1, 1],[1, 2, 1, 2],[1, 1, 3, 3],[1, 2, 3, 4]]); + +gap> DigraphFromMeetTable([[1,3,2],[2,3,1],[3,3,3]]); +fail + +# DigraphFromJoinTable +gap> DigraphFromJoinTable([[1, 3, 3],[3, 2, 3],[3, 3, 3]]); + +gap> DigraphFromJoinTable([[1,3,2],[2,3,1],[3,3,3]]); +fail + # DIGRAPHS_UnbindVariables gap> Unbind(C); gap> Unbind(D); From 913cff95884af763e89ef63412ad815b362bbb55 Mon Sep 17 00:00:00 2001 From: Marcin Weremczuk Date: Wed, 7 May 2025 20:10:07 +0100 Subject: [PATCH 4/4] test formatting --- tst/standard/oper.tst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index 614eaba45..b33ecd65a 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -3235,17 +3235,17 @@ gap> DigraphVertexLabels(D); [ 1, 2, 3, 6, [ 4, 5 ] ] # DigraphFromMeetTable -gap> DigraphFromMeetTable([[1,1],[1,2]]); +gap> DigraphFromMeetTable([[1, 1], [1, 2]]); -gap> DigraphFromMeetTable([[1, 1, 1, 1],[1, 2, 1, 2],[1, 1, 3, 3],[1, 2, 3, 4]]); +gap> DigraphFromMeetTable([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 3], [1, 2, 3, 4]]); -gap> DigraphFromMeetTable([[1,3,2],[2,3,1],[3,3,3]]); +gap> DigraphFromMeetTable([[1, 3, 2], [2, 3, 1], [3, 3, 3]]); fail # DigraphFromJoinTable -gap> DigraphFromJoinTable([[1, 3, 3],[3, 2, 3],[3, 3, 3]]); +gap> DigraphFromJoinTable([[1, 3, 3], [3, 2, 3], [3, 3, 3]]); -gap> DigraphFromJoinTable([[1,3,2],[2,3,1],[3,3,3]]); +gap> DigraphFromJoinTable([[1, 3, 2], [2, 3, 1], [3, 3, 3]]); fail # DIGRAPHS_UnbindVariables