Documentation

CslibFrontier.Computability.Distributed.ChandyLamport.Basic

Asynchronous point-to-point FIFO message-passing networks #

This module models asynchronous distributed systems communicating over point-to-point first-in, first-out (FIFO) channels along a directed communication graph Digraph P, following the underlying system model of [CL85] (§2, pp. 65–68, and §1, p. 64 for stable properties).

Each ordered pair (src, dest) of processes has an unbounded reliable FIFO queue chan src dest : List M whose head is the next message deliverable to dest and whose tail receives newly sent messages via append. Where §2 (p. 66, Figure 1) allows parallel labeled channels and single-channel 5-tuple events ⟨p, s, s', M, c⟩ over finite process/channel sets, System P S M over Digraph P models at most one channel per ordered pair (including self-loops), leaves P S M : Type* unrestricted, and allows each step to emit a list sent : List (P × M) of outgoing messages atomically:

Both local transition relations may be nondeterministic, while the induced labelled transition system System.lts over Event P S M is deterministic given the event label (lts_deterministic). Because System.lts includes no artificial stuttering transition, sys.lts.IsTerminal expresses genuine global deadlock or termination, which is automatically a stable global predicate (isStablePred_isTerminal).

The fundamental FIFO queue commutation property (System.tr_comm_of_ne) shows that two transitions at distinct processes p ≠ q commute in sys.lts whenever the second step does not pop from an initially empty channel (p, q)—because head-pop and tail-append commute on every non-empty list ((h :: t) ++ out = h :: (t ++ out)).

Main definitions #

Main results #

References #

structure Cslib.Distributed.ChandyLamport.GlobalState (P : Type u_1) (S : Type u_2) (M : Type u_3) :
Type (max (max u_1 u_2) u_3)

Global configuration of an asynchronous point-to-point FIFO message-passing network.

  • proc : P → S

    Local state of each process.

  • chan : P → P → List M

    Point-to-point FIFO channel chan src dest: the head is the next deliverable message and newly sent messages are appended to the tail.

theorem Cslib.Distributed.ChandyLamport.GlobalState.ext_iff {P : Type u_1} {S : Type u_2} {M : Type u_3} {x y : GlobalState P S M} :
x = y ↔ x.proc = y.proc ∧ x.chan = y.chan
theorem Cslib.Distributed.ChandyLamport.GlobalState.ext {P : Type u_1} {S : Type u_2} {M : Type u_3} {x y : GlobalState P S M} (proc : x.proc = y.proc) (chan : x.chan = y.chan) :
x = y
@[instance_reducible]
def Cslib.Distributed.ChandyLamport.outgoingTo {P : Type u_1} {M : Type u_2} [DecidableEq P] (sent : List (P × M)) (dest : P) :

Extract the payloads addressed to dest from an outgoing list of (recipient, payload) pairs, preserving emission order.

@[simp]
theorem Cslib.Distributed.ChandyLamport.outgoingTo_nil {P : Type u_1} {M : Type u_2} [DecidableEq P] (dest : P) :
@[simp]
theorem Cslib.Distributed.ChandyLamport.mem_outgoingTo_iff {P : Type u_1} {M : Type u_2} [DecidableEq P] {sent : List (P × M)} {dest : P} {m : M} :
m ∈ outgoingTo sent dest ↔ (dest, m) ∈ sent

Payload m appears in outgoingTo sent dest if and only if (dest, m) ∈ sent.

theorem Cslib.Distributed.ChandyLamport.outgoingTo_eq_nil_of_forall_ne {P : Type u_1} {M : Type u_2} [DecidableEq P] {sent : List (P × M)} {dest : P} (h : ∀ (m : M), (dest, m) ∉ sent) :
outgoingTo sent dest = []

outgoingTo sent dest is empty when no entry of sent targets dest.

def Cslib.Distributed.ChandyLamport.GlobalState.popChan {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (s : GlobalState P S M) (src dest : P) :

Pop the head message from channel (src, dest), leaving all other channels and all local process states unchanged.

def Cslib.Distributed.ChandyLamport.GlobalState.applyLocal {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (s : GlobalState P S M) (p : P) (nextState : S) (sent : List (P × M)) :

Update process p's local state to nextState and append its outgoing messages sent to the tails of the corresponding outgoing channels (p, v).

inductive Cslib.Distributed.ChandyLamport.Event (P : Type u_1) (S : Type u_2) (M : Type u_3) :
Type (max (max u_1 u_2) u_3)

Transition label of an asynchronous FIFO message-passing system.

  • internal {P : Type u_1} {S : Type u_2} {M : Type u_3} (p : P) (nextState : S) (sent : List (P × M)) : Event P S M

    Spontaneous internal/send transition at process p moving to nextState and emitting sent.

  • recv {P : Type u_1} {S : Type u_2} {M : Type u_3} (src dest : P) (msg : M) (nextState : S) (sent : List (P × M)) : Event P S M

    Receipt of msg from the head of channel (src, dest) by dest, moving dest to nextState and emitting sent.

def Cslib.Distributed.ChandyLamport.instDecidableEqEvent.decEq {P✝ : Type u_1} {S✝ : Type u_2} {M✝ : Type u_3} [DecidableEq P✝] [DecidableEq S✝] [DecidableEq M✝] (x✝ x✝¹ : Event P✝ S✝ M✝) :
Decidable (x✝ = x✝¹)
@[instance_reducible]
instance Cslib.Distributed.ChandyLamport.instDecidableEqEvent {P✝ : Type u_1} {S✝ : Type u_2} {M✝ : Type u_3} [DecidableEq P✝] [DecidableEq S✝] [DecidableEq M✝] :
DecidableEq (Event P✝ S✝ M✝)
def Cslib.Distributed.ChandyLamport.Event.actor {P : Type u_1} {S : Type u_2} {M : Type u_3} :
Event P S M → P

The acting process of an Event.

def Cslib.Distributed.ChandyLamport.Event.nextState {P : Type u_1} {S : Type u_2} {M : Type u_3} :
Event P S M → S

Target local state written to e.actor by e.

def Cslib.Distributed.ChandyLamport.Event.sent {P : Type u_1} {S : Type u_2} {M : Type u_3} :
Event P S M → List (P × M)

Outgoing (recipient, payload) list emitted by an Event.

def Cslib.Distributed.ChandyLamport.Event.popsFrom {P : Type u_1} {S : Type u_2} {M : Type u_3} (e : Event P S M) (src dest : P) :

Whether event e consumes a message from channel (src, dest).

Instances For
    @[instance_reducible]
    instance Cslib.Distributed.ChandyLamport.instDecidablePopsFrom {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (e : Event P S M) (src dest : P) :
    Decidable (e.popsFrom src dest)
    theorem Cslib.Distributed.ChandyLamport.Event.popsFrom_dest {P : Type u_1} {S : Type u_2} {M : Type u_3} {e : Event P S M} {u v : P} (h : e.popsFrom u v) :
    v = e.actor
    def Cslib.Distributed.ChandyLamport.GlobalState.applyEvent {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (s : GlobalState P S M) :
    Event P S M → GlobalState P S M

    Next global state obtained by applying event e to s.

    def Cslib.Distributed.ChandyLamport.GlobalState.runEvents {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (s : GlobalState P S M) :
    List (Event P S M) → GlobalState P S M

    State reached from s by applying each event in xl sequentially.

    theorem Cslib.Distributed.ChandyLamport.GlobalState.applyEvent_proc {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (s : GlobalState P S M) (e : Event P S M) (r : P) :
    theorem Cslib.Distributed.ChandyLamport.GlobalState.applyEvent_chan {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (s : GlobalState P S M) (e : Event P S M) (u v : P) :
    (s.applyEvent e).chan u v = (if e.popsFrom u v then (s.chan u v).tail else s.chan u v) ++ if u = e.actor then outgoingTo e.sent v else []
    structure Cslib.Distributed.ChandyLamport.System (P : Type u_1) (S : Type u_2) (M : Type u_3) :
    Type (max (max u_1 u_2) u_3)

    Underlying asynchronous message-passing system over a directed communication graph Digraph P. Both spontaneous steps (internal) and message-receive steps (recv) may be relational (nondeterministic).

    • graph : Digraph P

      Directed communication topology: channel (u, v) exists when graph.Adj u v.

    • internal : P → S → S → List (P × M) → Prop

      Allowed spontaneous transitions internal p st st' sent at process p.

    • recv : P → P → S → M → S → List (P × M) → Prop

      Allowed receive transitions recv src dest st msg st' sent at process dest.

    def Cslib.Distributed.ChandyLamport.System.Enabled {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) (s : GlobalState P S M) :
    Event P S M → Prop

    Whether event e is enabled in global state s.

    Instances For
      @[instance_reducible]
      instance Cslib.Distributed.ChandyLamport.System.instDecidableEnabled {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq M] [DecidableRel sys.graph.Adj] [(p : P) → (st st' : S) → (sent : List (P × M)) → Decidable (sys.internal p st st' sent)] [(src dest : P) → (st : S) → (msg : M) → (st' : S) → (sent : List (P × M)) → Decidable (sys.recv src dest st msg st' sent)] (s : GlobalState P S M) (e : Event P S M) :
      Decidable (sys.Enabled s e)
      def Cslib.Distributed.ChandyLamport.System.lts {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] :
      LTS (GlobalState P S M) (Event P S M)

      Labelled transition system of sys with FIFO point-to-point channels.

      Instances For
        instance Cslib.Distributed.ChandyLamport.System.lts_deterministic {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] :

        sys.lts is deterministic: each state and Event label determines at most one successor.

        def Cslib.Distributed.ChandyLamport.System.validTrace {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] (s : GlobalState P S M) :
        List (Event P S M) → Prop

        Executable trace-validity predicate checking that each event in xl is enabled when reached from s.

        Instances For
          @[instance_reducible]
          instance Cslib.Distributed.ChandyLamport.System.instDecidableValidTrace {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] [DecidableEq M] [DecidableRel sys.graph.Adj] [(p : P) → (st st' : S) → (sent : List (P × M)) → Decidable (sys.internal p st st' sent)] [(src dest : P) → (st : S) → (msg : M) → (st' : S) → (sent : List (P × M)) → Decidable (sys.recv src dest st msg st' sent)] (s : GlobalState P S M) (xl : List (Event P S M)) :
          theorem Cslib.Distributed.ChandyLamport.System.mTr_iff_validTrace {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] {s s' : GlobalState P S M} {xl : List (Event P S M)} :
          sys.lts.MTr s xl s' ↔ sys.validTrace s xl ∧ s' = s.runEvents xl

          Because sys.lts is deterministic, sys.lts.MTr s xl s' holds if and only if xl is a valid trace from s and s' = s.runEvents xl.

          @[instance_reducible]
          instance Cslib.Distributed.ChandyLamport.System.instDecidableMTr {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [Fintype P] [DecidableEq P] [DecidableEq S] [DecidableEq M] [DecidableRel sys.graph.Adj] [(p : P) → (st st' : S) → (sent : List (P × M)) → Decidable (sys.internal p st st' sent)] [(src dest : P) → (st : S) → (msg : M) → (st' : S) → (sent : List (P × M)) → Decidable (sys.recv src dest st msg st' sent)] (s s' : GlobalState P S M) (xl : List (Event P S M)) :
          Decidable (sys.lts.MTr s xl s')
          def Cslib.Distributed.ChandyLamport.System.WellFormedChan {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) (s : GlobalState P S M) :

          A global state has well-formed channels if every non-edge of sys.graph is empty.

          Instances For
            @[instance_reducible]
            theorem Cslib.Distributed.ChandyLamport.System.wellFormedChan_mTr {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] {s₁ s₂ : GlobalState P S M} {xl : List (Event P S M)} (hmtr : sys.lts.MTr s₁ xl s₂) (hwf : sys.WellFormedChan s₁) :

            Non-edge channels remain empty across any finite execution of sys.lts.

            theorem Cslib.Distributed.ChandyLamport.System.tr_comm_of_ne {P : Type u_1} {S : Type u_2} {M : Type u_3} (sys : System P S M) [DecidableEq P] {s s₁ s₂ : GlobalState P S M} {e₁ e₂ : Event P S M} (htr₁ : sys.lts.Tr s e₁ s₁) (htr₂ : sys.lts.Tr s₁ e₂ s₂) (hne : e₁.actor ≠ e₂.actor) (hchan : e₂.popsFrom e₁.actor e₂.actor → s.chan e₁.actor e₂.actor ≠ []) :
            ∃ (s₁' : GlobalState P S M), sys.lts.Tr s e₂ s₁' ∧ sys.lts.Tr s₁' e₁ s₂

            FIFO causal commutation for distinct processes: if e₁ (at actor p) is followed by e₂ (at actor q ≠ p), and e₂ does not pop from an initially empty channel (p, q) in s, then e₂ is already enabled in s and executing e₂ before e₁ reaches the exact same state s₂.

            Stable global predicates #

            def Cslib.Distributed.ChandyLamport.IsStablePred {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (sys : System P S M) (Φ : GlobalState P S M → Prop) :

            A global predicate Φ is stable for sys if once Φ holds in a state s, it continues to hold in every successor state s' of sys.lts ([CL85], §1, p. 64, equivalent via IsStablePred.canReach to closure under reachability). Standard examples include deadlock, computation termination, and loss of all tokens in a token ring.

            theorem Cslib.Distributed.ChandyLamport.IsStablePred.canReach {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] {sys : System P S M} {Φ : GlobalState P S M → Prop} (hΦ : IsStablePred sys Φ) {s₁ s₂ : GlobalState P S M} (hr : sys.lts.CanReach s₁ s₂) (hs : Φ s₁) :
            Φ s₂

            A stable predicate persists across arbitrary finite executions (CanReach).

            theorem Cslib.Distributed.ChandyLamport.IsStablePred.not_of_canReach {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] {sys : System P S M} {Φ : GlobalState P S M → Prop} (hΦ : IsStablePred sys Φ) {s₁ s₂ : GlobalState P S M} (hr : sys.lts.CanReach s₁ s₂) (hnot : ¬Φ s₂) :
            ¬Φ s₁

            Contrapositive backward transfer: if a stable predicate fails at a reachable state s₂, it was already false at s₁.

            theorem Cslib.Distributed.ChandyLamport.isStablePred_isTerminal {P : Type u_1} {S : Type u_2} {M : Type u_3} [DecidableEq P] (sys : System P S M) :

            Global deadlock/termination (sys.lts.IsTerminal) is a stable predicate.