Skip to content
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
6 changes: 6 additions & 0 deletions specifications/SpecifyingSystems/AdvancedExamples/Graphs.tla
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
------------------------------- MODULE Graphs -------------------------------
(***************************************************************************)
(* Representation of (directed) graphs in TLA+. *)
(* This is the ancestor of the Graphs community module, available at *)
(* https://github.com/tlaplus/CommunityModules/blob/master/modules/Graphs.tla *)
(* which contains more operators and also slightly changed definitions. *)
(***************************************************************************)
LOCAL INSTANCE Naturals
LOCAL INSTANCE Sequences

Expand Down
46 changes: 23 additions & 23 deletions specifications/ewd687a/EWD687a.tla
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
(* not to be detected. It requires that a process can send acknowledgment *)
(* messages to any process that can send it computation messages. *)
(***************************************************************************)
EXTENDS Integers
EXTENDS Integers, Graphs

(***************************************************************************)
(* We declare the following constants: *)
Expand Down Expand Up @@ -215,7 +215,7 @@ VARIABLES
(* network. In an implementation, we would, thus, expect to find *)
(* code that maintains the values of active, sentUnacked, and *)
(* rcvdUnacked in the implementation of a process. The variables msgs *)
(* and acks, however, would likely be implicitly because they model *)
(* and acks, however, would likely be implicit because they model *)
(* the state of the network. *)
(***********************************************************************)

Expand All @@ -231,7 +231,7 @@ VARIABLES
msgs,
(***********************************************************************)
(* For an edge <<q,p>> \in OutEdges(p), acks[<<q,p>>] is the number of *)
(* control) messages in transit from process p to process q. *)
(* (control) messages in transit from process p to process q. *)
(***********************************************************************)
acks
(***********************************************************************)
Expand Down Expand Up @@ -330,7 +330,7 @@ RcvAck(p) == \E e \in OutEdges(p) :
(* 2b. The receiver q of the ack is the parent of p in the overlay tree, *)
(* and p is neutral after sending the ack. *)
(* *)
(* UP. If process p is neutral after sending an ack (hence netural(p)'), *)
(* UP. If process p is neutral after sending an ack (hence neutral(p)'), *)
(* it removes itself from the overlay tree by setting the value of *)
(* upEdge[p] to NotAnEdge. *)
(***************************************************************************)
Expand Down Expand Up @@ -383,16 +383,17 @@ RcvMsg(p) == \E e \in InEdges(p) :
(* that p was not a node of the overlay tree when it became idle. Thus, *)
(* there is no need to change upEdge[p] in the Idle subaction. *)
(***************************************************************************)
Idle(p) == /\ active' = [active EXCEPT ![p] = FALSE]
Idle(p) == /\ active[p] \* otherwise this step is subsumed by stuttering
/\ active' = [active EXCEPT ![p] = FALSE]
/\ UNCHANGED <<msgs, acks, sentUnacked, rcvdUnacked, upEdge>>

----------------------------------------------------------------------------

Next == \E p \in Procs : SendMsg(p) \/ SendAck(p) \/ RcvMsg(p) \/ RcvAck(p)
\/ Idle(p)

Spec == Init /\ [][Next]_vars /\ WF_vars(Next)

----------------------------------------------------------------------------

(***************************************************************************)
Expand All @@ -401,34 +402,33 @@ Spec == Init /\ [][Next]_vars /\ WF_vars(Next)
(* rcvdUnacked[e] equals sentUnacked[e], for any e in Edges. *)
(***************************************************************************)
CountersConsistent ==
[] \A e \in Edges: sentUnacked[e] = rcvdUnacked[e] + acks[e] + msgs[e]
\A e \in Edges: sentUnacked[e] = rcvdUnacked[e] + acks[e] + msgs[e]

THEOREM Spec => CountersConsistent
THEOREM Spec => []CountersConsistent

(***************************************************************************)
(* The overlay tree is a tree of non-neutral nodes rooted in the leader, *)
(* or the tree is empty s.t. it has no edges nor nodes. *)
(* With bigger graphs, expect a significant slowdown when model-checking *)
(* the property TreeWithRoot. *)
(* The overlay tree is a tree rooted in the leader such that all inner *)
(* nodes are non-neutral. *)
(* *)
(* In a variant of this spec, the conjunct labelled Up in the SendAck *)
(* subactions could be removed. In this variant, the processes in the *)
(* overlay tree would be processes that are or were non-neutral in the *)
(* past. Consequently, the conjunct labelled N would have to be *)
(* removed from the property TreeWithRoot . *)
(* removed from the property TreeWithRoot. *)
(***************************************************************************)

TreeWithRoot ==
LET E == {upEdge[p] : p \in DOMAIN upEdge} \ {NotAnEdge}
N == {e[1] : e \in E} \cup {e[2] : e \in E}
G == INSTANCE Graphs
O == G!Transpose([edge |-> E, node |-> N])
IN [](
\* O is a tree rooted in the leader.
/\ O.edge # {} => G!IsTreeWithRoot(O, Leader)
\* All nodes of the overlay tree are non-neutral.
/\ N:: \A n \in O.node: ~neutral(n))
\* The original definition includes every node occurring in the tree
\* twice (except the leader), which unnecessarily complicates the proof.
N == (* {e[1] : e \in E} \cup *) {e[2] : e \in E} \cup {Leader}
O == Transpose([edge |-> E, node |-> N])
IN \* O is a tree rooted in the leader.
/\ IsTreeWithRoot(O, Leader)
\* All nodes of the overlay tree, except the root, are non-neutral.
/\ N:: \A n \in O.node \ {Leader} : ~neutral(n)

THEOREM Spec => TreeWithRoot
THEOREM Spec => []TreeWithRoot

---------------------------------------------------------------------------

Expand Down
Loading
Loading