Skip to content

Commit 1e2f2d4

Browse files
committed
Add operators to the Relation module.
* IsComparable * IsPartiallyOrdered * IsTotallyOrdered * (ToRelation) Signed-off-by: Markus Alexander Kuppe <[email protected]>
1 parent 9c13c11 commit 1e2f2d4

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The Modules
2525
| [`HTML.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/HTML.tla) | Format strings into HTML tags | | [@afonsof](https://github.com/afonsof) |
2626
| [`IOUtils.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/IOUtils.tla) | Input/Output of TLA+ values & Spawn system commands from a spec. | [&#10004;](https://github.com/tlaplus/CommunityModules/blob/master/modules/tlc2/overrides/IOUtils.java) | [@lemmy](https://github.com/lemmy), [@lvanengelen](https://github.com/lvanengelen), [@afonsof](https://github.com/afonsof) |
2727
| [`Json.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/Json.tla) | JSON serialization and deserialization into TLA+ values. | [&#10004;](https://github.com/tlaplus/CommunityModules/blob/master/modules/tlc2/overrides/Json.java) | [@kuujo](https://github.com/kuujo), [@lemmy](https://github.com/lemmy), [@jobvs](https://github.com/jobvs), [@pfeodrippe](https://github.com/pfeodrippe) |
28-
| [`Relation.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/Relation.tla) | Basic operations on relations, represented as binary Boolean functions over some set S. | | [@muenchnerkindl](https://github.com/muenchnerkindl) |
28+
| [`Relation.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/Relation.tla) | Basic operations on relations, represented as binary Boolean functions over some set S. | | [@muenchnerkindl](https://github.com/muenchnerkindl), [@lemmy](https://github.com/lemmy) |
2929
| [`SequencesExt.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/SequencesExt.tla) | Additional operators on sequences (e.g. `ToSet`, `Reverse`, `ReplaceAll`, `SelectInSeq`, etc.) | [&#10004;](https://github.com/tlaplus/CommunityModules/blob/master/modules/tlc2/overrides/SequencesExt.java) | [@muenchnerkindl](https://github.com/muenchnerkindl), [@lemmy](https://github.com/lemmy), [@hwayne](https://github.com/hwayne), [@quicquid](https://github.com/quicquid), [@konnov](https://github.com/konnov), [@afonsof](https://github.com/afonsof) |
3030
| [`ShiViz.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/ShiViz.tla) | Visualize error-traces of multi-process PlusCal algorithms with an [Interactive Communication Graphs](https://bestchai.bitbucket.io/shiviz/). | | [@lemmy](https://github.com/lemmy) |
3131
| [`Statistics.tla`](https://github.com/tlaplus/CommunityModules/blob/master/modules/Statistics.tla) | Statistics operators (`ChiSquare`, etc.) | [&#10004;](https://github.com/tlaplus/CommunityModules/blob/master/modules/tlc2/overrides/Statistics.java) | [@lemmy](https://github.com/lemmy) |

modules/Relation.tla

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
----------------------------- MODULE Relation ------------------------------
22
LOCAL INSTANCE Naturals
3-
LOCAL INSTANCE FiniteSets
3+
LOCAL INSTANCE FiniteSets \* TODO Consider moving to a more specific module.
44

55
(***************************************************************************)
66
(* This module provides some basic operations on relations, represented *)
77
(* as binary Boolean functions over some set S. *)
88
(***************************************************************************)
99

10+
(***************************************************************************)
11+
(* Given a binary operator op, return the relation it represents over set *)
12+
(* S. *)
13+
(***************************************************************************)
14+
ToRelation(op(_, _), S) == [x, y \in S |-> op(x,y)]
15+
1016
(***************************************************************************)
1117
(* Is the relation R reflexive over S? *)
1218
(***************************************************************************)
@@ -32,6 +38,27 @@ IsAsymmetric(R, S) == \A x,y \in S : ~(R[x,y] /\ R[y,x])
3238
(***************************************************************************)
3339
IsTransitive(R, S) == \A x,y,z \in S : R[x,y] /\ R[y,z] => R[x,z]
3440

41+
(***************************************************************************)
42+
(* Determines if, for any two elements in S, the two elements are *)
43+
(* comparable under the relation R. *)
44+
(***************************************************************************)
45+
IsComparable(R, S) == \A x,y \in S : R[x,y] \/ R[y,x]
46+
47+
(***************************************************************************)
48+
(* Is the set S partially ordered under the (binary) relation R? *)
49+
(***************************************************************************)
50+
IsPartiallyOrdered(R, S) ==
51+
/\ IsReflexive(R, S)
52+
/\ IsTransitive(R, S)
53+
/\ IsAsymmetric(R, S)
54+
55+
(***************************************************************************)
56+
(* Is the set S totally ordered under the (binary) relation R? *)
57+
(***************************************************************************)
58+
IsTotallyOrdered(R, S) ==
59+
/\ IsPartiallyOrdered(R, S)
60+
/\ IsComparable(R, S)
61+
3562
(***************************************************************************)
3663
(* Compute the transitive closure of relation R over set S. *)
3764
(***************************************************************************)

0 commit comments

Comments
 (0)