Skip to content
Merged
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
14 changes: 8 additions & 6 deletions modules/Graphs.tla
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ AllPredecessors(G, S) == UNION {Predecessors(G, n): n \in S}
(***************************************************************************)
Ancestors(G, n) ==
LET EdgeRelation ==
[<<x, y>> \in G.node \X G.node |-> <<x, y>> \in G.edge]
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* [<<x, y>> \in G.node \X G.node |-> <<x, y>> \in G.edge]
[p \in G.node \X G.node |-> <<p[1], p[2]>> \in G.edge]
IN { m \in G.node : TransitiveClosure(EdgeRelation, G.node)[m, n] }

(***************************************************************************)
Expand All @@ -169,7 +172,10 @@ Ancestors(G, n) ==
(***************************************************************************)
Descendants(G, n) ==
LET EdgeRelation ==
[<<x, y>> \in G.node \X G.node |-> <<x, y>> \in G.edge]
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* [<<x, y>> \in G.node \X G.node |-> <<x, y>> \in G.edge]
[p \in G.node \X G.node |-> <<p[1], p[2]>> \in G.edge]
IN { m \in G.node : TransitiveClosure(EdgeRelation, G.node)[n, m] }

(*************************************************************)
Expand Down Expand Up @@ -218,7 +224,3 @@ EmptyGraph == [node |-> {}, edge |-> {}]
(************************************************************************)
Graphs(S) == [node: {S}, edge: SUBSET (S \X S)]
=============================================================================
\* Modification History
\* Last modified Sun Mar 06 18:10:34 CET 2022 by Stephan Merz
\* Last modified Tue Dec 21 15:55:45 PST 2021 by Markus Kuppe
\* Created Tue Jun 18 11:44:08 PST 2002 by Leslie Lamport
55 changes: 41 additions & 14 deletions modules/Relation.tla
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
----------------------------- MODULE Relation ------------------------------
LOCAL INSTANCE Naturals
LOCAL INSTANCE FiniteSets \* TODO Consider moving to a more specific module.
LOCAL INSTANCE FiniteSets

(***************************************************************************)
(* This module provides some basic operations on relations, represented *)
Expand Down Expand Up @@ -33,7 +33,10 @@ LOCAL INSTANCE FiniteSets \* TODO Consider moving to a more specific module.
IsReflexive(R, S) == \A x \in S : R[x,x]

IsReflexiveUnder(op(_,_), S) ==
IsReflexive([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsReflexive([<<x,y>> \in S \X S |-> op(x,y)], S)
IsReflexive([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the relation R irreflexive over set S? *)
Expand All @@ -48,7 +51,10 @@ IsReflexiveUnder(op(_,_), S) ==
IsIrreflexive(R, S) == \A x \in S : ~ R[x,x]

IsIrreflexiveUnder(op(_,_), S) ==
IsIrreflexive([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsIrreflexive([<<x,y>> \in S \X S |-> op(x,y)], S)
IsIrreflexive([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the relation R symmetric over set S? *)
Expand All @@ -62,7 +68,10 @@ IsIrreflexiveUnder(op(_,_), S) ==
IsSymmetric(R, S) == \A x,y \in S : R[x,y] <=> R[y,x]

IsSymmetricUnder(op(_,_), S) ==
IsSymmetric([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsSymmetric([<<x,y>> \in S \X S |-> op(x,y)], S)
IsSymmetric([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the relation R antisymmetric over set S? *)
Expand All @@ -77,7 +86,10 @@ IsSymmetricUnder(op(_,_), S) ==
IsAntiSymmetric(R, S) == \A x,y \in S : R[x,y] /\ R[y,x] => x=y

IsAntiSymmetricUnder(op(_,_), S) ==
IsAntiSymmetric([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsAntiSymmetric([<<x,y>> \in S \X S |-> op(x,y)], S)
IsAntiSymmetric([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the relation R asymmetric over set S? *)
Expand All @@ -92,7 +104,10 @@ IsAntiSymmetricUnder(op(_,_), S) ==
IsAsymmetric(R, S) == \A x,y \in S : ~(R[x,y] /\ R[y,x])

IsAsymmetricUnder(op(_,_), S) ==
IsAsymmetric([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsAsymmetric([<<x,y>> \in S \X S |-> op(x,y)], S)
IsAsymmetric([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the relation R transitive over set S? *)
Expand All @@ -107,7 +122,10 @@ IsAsymmetricUnder(op(_,_), S) ==
IsTransitive(R, S) == \A x,y,z \in S : R[x,y] /\ R[y,z] => R[x,z]

IsTransitiveUnder(op(_,_), S) ==
IsTransitive([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsTransitive([<<x,y>> \in S \X S |-> op(x,y)], S)
IsTransitive([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the set S strictly partially ordered under the (binary) relation R? *)
Expand All @@ -125,7 +143,10 @@ IsStrictlyPartiallyOrdered(R, S) ==
/\ IsTransitive(R, S)

IsStrictlyPartiallyOrderedUnder(op(_,_), S) ==
IsStrictlyPartiallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsStrictlyPartiallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
IsStrictlyPartiallyOrdered([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the set S (weakly) partially ordered under the (binary) relation R? *)
Expand All @@ -143,7 +164,10 @@ IsPartiallyOrdered(R, S) ==
/\ IsTransitive(R, S)

IsPartiallyOrderedUnder(op(_,_), S) ==
IsPartiallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsPartiallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
IsPartiallyOrdered([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the set S strictly totally ordered under the (binary) relation R? *)
Expand All @@ -160,7 +184,10 @@ IsStrictlyTotallyOrdered(R, S) ==
/\ \A x,y \in S : x # y => R[x,y] \/ R[y,x]

IsStrictlyTotallyOrderedUnder(op(_,_), S) ==
IsStrictlyTotallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsStrictlyTotallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
IsStrictlyTotallyOrdered([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Is the set S totally ordered under the (binary) relation R? *)
Expand All @@ -175,7 +202,10 @@ IsTotallyOrdered(R, S) ==
/\ \A x,y \in S : R[x,y] \/ R[y,x]

IsTotallyOrderedUnder(op(_,_), S) ==
IsTotallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
\* revert to the following syntax once TLAPS uses SANY
\* (https://github.com/tlaplus/tlapm/issues/213)
\* IsTotallyOrdered([<<x,y>> \in S \X S |-> op(x,y)], S)
IsTotallyOrdered([p \in S \X S |-> op(p[1], p[2])], S)

(***************************************************************************)
(* Compute the transitive closure of relation R over set S. *)
Expand Down Expand Up @@ -204,6 +234,3 @@ IsConnected(R, S) ==
IN \A x,y \in S : rtrcl[x,y]

=============================================================================
\* Modification History
\* Last modified Tues Sept 17 06:20:47 CEST 2024 by Markus Alexander Kuppe
\* Created Tue Apr 26 10:24:07 CEST 2016 by merz
4 changes: 2 additions & 2 deletions tests/UndirectedGraphsTests.tla
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
------------------------- MODULE GraphsTests -------------------------
------------------------- MODULE UndirectedGraphsTests -------------------
EXTENDS UndirectedGraphs, TLCExt

ASSUME LET T == INSTANCE TLC IN T!PrintT("UndirectedGraphsTests")
Expand All @@ -14,7 +14,7 @@ ASSUME LET G == [edge|-> {{1,2}}, node |-> {1,2,3}]
/\ AreConnectedIn(1, 2, G)
/\ ~ AreConnectedIn(1, 3, G)

AssertEq(ConnectedComponents([edge|-> {{1,2}}, node |-> {1,2,3}]),
ASSUME AssertEq(ConnectedComponents([edge|-> {{1,2}}, node |-> {1,2,3}]),
{{1,2}, {3}})
ASSUME LET G == [node |-> {1,2,3,4,5},
edge |-> {{1,3}, {1,4}, {2,3}, {2,4}, {3,5}, {4,5}}]
Expand Down
Loading