Documentation

CslibFrontier.Computability.Distributed.VectorClock.Basic

Asynchronous message-passing executions, happens-before causality, and consistent cuts #

This module formalizes finite causally well-formed asynchronous point-to-point message-passing executions over a process type P, Lamport's happens-before strict partial order [Lam78], causal concurrency, executable causal-past computation, and downward-closed consistent cuts [Mat89].

An Execution P records a finite sequence steps : List (Step P) of process steps:

Events E.Event wrap Fin E.steps.length so that E.Event carries Lamport's causal PartialOrder (≤ for HappensBeforeLe, < for HappensBefore) without colliding with the linear trace-index order on Fin.

Relationship to Cslib.DistributedConsistency #

Upstream Cslib.DistributedConsistency (AbstractExecution.hb) models axiomatic replicated-data consistency following Burckhardt (2014), taking session order and visibility relations over an abstract event set where acyclicity (NoCircularCausality) is an explicit hypothesis. Here Execution P models operational asynchronous message-passing traces whose happens-before relation is unconditionally a PartialOrder / IsStrictOrder with executable O(n²) decidability, supporting operational Lamport scalar clocks, Fidge–Mattern vector clocks, and Charron-Bost's clock-dimension lower bound in companion modules.

Main definitions #

Main results #

References #

A single local or communication step in an asynchronous message-passing execution over process type P. A .recv actor sendIdx step references the trace index sendIdx of the matching .send step whose message is delivered.

  • internal {P : Type u} (actor : P) : Step P

    Internal computation step at process actor.

  • send {P : Type u} (actor dest : P) : Step P

    Point-to-point message send from actor to dest.

  • recv {P : Type u} (actor : P) (sendIdx : ℕ) : Step P

    Receipt at actor of the message sent at trace index sendIdx.

Instances For
    @[instance_reducible]
    def Cslib.Distributed.VectorClock.instDecidableEqStep.decEq {P✝ : Type u_1} [DecidableEq P✝] (x✝ x✝¹ : Step P✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    instance Cslib.Distributed.VectorClock.instReprStep {P✝ : Type u_1} [Repr P✝] :
    Repr (Step P✝)

    The process executing a given Step.

    @[simp]
    theorem Cslib.Distributed.VectorClock.Step.actor_send {P : Type u} (p dest : P) :
    (send p dest).actor = p
    @[simp]
    theorem Cslib.Distributed.VectorClock.Step.actor_recv {P : Type u} (p : P) (sIdx : ℕ) :
    (recv p sIdx).actor = p
    def Cslib.Distributed.VectorClock.Step.map {P : Type u} {Q : Type u_1} (f : P → Q) :
    Step P → Step Q

    Rename process identifiers in a Step.

    @[simp]
    theorem Cslib.Distributed.VectorClock.Step.actor_map {P : Type u} {Q : Type u_1} (f : P → Q) (s : Step P) :
    (map f s).actor = f s.actor

    A finite causally well-formed asynchronous point-to-point message-passing execution over processes P. Every .recv actor sIdx step references a strictly earlier .send src actor step (sIdx < i), and each sent message is delivered at most once (recv_injective).

    theorem Cslib.Distributed.VectorClock.Execution.ext {P : Type u} {x y : Execution P} (steps : x.steps = y.steps) :
    x = y

    The empty execution with zero events.

    Communication-free execution consisting solely of internal steps on procs.

    Per-index causal well-formedness check on steps : List (Step P).

    Executable Boolean check certifying that steps : List (Step P) forms a causally well-formed Execution P (enabling Execution.ofValidSteps steps (by decide) in module clients).

    Construct an Execution P from a step list certified by IsValidSteps steps = true.

    An event of execution E, wrapping its trace index in E.steps so that E.Event carries Lamport's causal happens-before PartialOrder without conflicting with the trace-index linear order on Fin E.steps.length.

    Instances For
      theorem Cslib.Distributed.VectorClock.Execution.Event.ext {P : Type u} {E : Execution P} {x y : E.Event} (idx : x.idx = y.idx) :
      x = y

      Equivalence between E.Event and Fin E.steps.length.

      The Step P performed at event e.

      The process at which event e occurs.

      theorem Cslib.Distributed.VectorClock.Execution.recv_sendEvent {P : Type u} {E : Execution P} {e : E.Event} {p : P} {sIdx : ℕ} (hrecv : e.step = Step.recv p sIdx) :
      ∃ (eSend : E.Event), ↑eSend.idx = sIdx ∧ eSend.idx < e.idx ∧ p = e.actor ∧ ∃ (src : P), eSend.step = Step.send src p

      Every receive event e has a unique earlier matching send event addressed to e.actor.

      Direct causality and Lamport's happens-before poset #

      Same-process program order: e₁ and e₂ occur at the same process with e₁.idx < e₂.idx.

      Instances For

        Point-to-point message order: e₂ receives the message sent at e₁.

        Instances For

          Single-step causal precedence: either program order on the same process or message send-to-receive order.

          Instances For

            Lamport's strict happens-before relation ([Lam78]), defined as the transitive closure of CausalStep.

            Instances For

              Reflexive-transitive causal ordering on events (e₁ = e₂ ∨ E.HappensBefore e₁ e₂).

              Instances For
                theorem Cslib.Distributed.VectorClock.Execution.messageOrder_of_recv {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} {p : P} (h : e₂.step = Step.recv p ↑e₁.idx) :
                E.MessageOrder e₁ e₂

                If e₂.step = .recv p e₁.idx.val, then MessageOrder e₁ e₂ holds.

                theorem Cslib.Distributed.VectorClock.Execution.causalStep_idx_lt {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.CausalStep e₁ e₂) :
                e₁.idx < e₂.idx

                Direct causal steps strictly advance the execution trace index.

                theorem Cslib.Distributed.VectorClock.Execution.happensBefore_idx_lt {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.HappensBefore e₁ e₂) :
                e₁.idx < e₂.idx

                Causal precedence strictly respects trace indices (e₁ ≺ e₂ → e₁.idx < e₂.idx), witnessing acyclicity of happens-before in every well-formed execution.

                theorem Cslib.Distributed.VectorClock.Execution.happensBeforeLe_idx_le {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.HappensBeforeLe e₁ e₂) :
                e₁.idx ≤ e₂.idx

                Reflexive causal precedence implies non-strict trace-index ordering.

                theorem Cslib.Distributed.VectorClock.Execution.HappensBefore.trans {P : Type u} {E : Execution P} {e₁ e₂ e₃ : E.Event} (h₁₂ : E.HappensBefore e₁ e₂) (h₂₃ : E.HappensBefore e₂ e₃) :
                E.HappensBefore e₁ e₃

                Strict HappensBefore is transitive.

                theorem Cslib.Distributed.VectorClock.Execution.happensBefore_asymm {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.HappensBefore e₁ e₂) :
                ¬E.HappensBefore e₂ e₁

                Strict HappensBefore is asymmetric.

                theorem Cslib.Distributed.VectorClock.Execution.happensBeforeLe_iff {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} :
                E.HappensBeforeLe e₁ e₂ ↔ e₁ = e₂ ∨ E.HappensBefore e₁ e₂

                HappensBeforeLe holds iff the events are equal or related by strict HappensBefore.

                theorem Cslib.Distributed.VectorClock.Execution.HappensBeforeLe.trans {P : Type u} {E : Execution P} {e₁ e₂ e₃ : E.Event} (h₁₂ : E.HappensBeforeLe e₁ e₂) (h₂₃ : E.HappensBeforeLe e₂ e₃) :
                E.HappensBeforeLe e₁ e₃

                HappensBeforeLe is transitive.

                theorem Cslib.Distributed.VectorClock.Execution.happensBeforeLe_antisymm {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h₁₂ : E.HappensBeforeLe e₁ e₂) (h₂₁ : E.HappensBeforeLe e₂ e₁) :
                e₁ = e₂

                HappensBeforeLe is antisymmetric.

                Every strict HappensBefore edge implies HappensBeforeLe.

                theorem Cslib.Distributed.VectorClock.Execution.happensBefore_of_happensBeforeLe_of_ne {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.HappensBeforeLe e₁ e₂) (hne : e₁ ≠ e₂) :
                E.HappensBefore e₁ e₂

                Distinct events related by HappensBeforeLe are related by strict HappensBefore.

                theorem Cslib.Distributed.VectorClock.Execution.programOrder_happensBefore {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (hact : e₁.actor = e₂.actor) (hlt : e₁.idx < e₂.idx) :
                E.HappensBefore e₁ e₂

                Same-process program order implies HappensBefore.

                theorem Cslib.Distributed.VectorClock.Execution.programOrder_happensBeforeLe {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (hact : e₁.actor = e₂.actor) (hle : e₁.idx ≤ e₂.idx) :
                E.HappensBeforeLe e₁ e₂

                Non-strict same-process trace order implies HappensBeforeLe.

                theorem Cslib.Distributed.VectorClock.Execution.messageOrder_happensBefore {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.MessageOrder e₁ e₂) :
                E.HappensBefore e₁ e₂

                Point-to-point message order implies HappensBefore.

                theorem Cslib.Distributed.VectorClock.Execution.sameActor_happensBeforeLe_iff {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (hact : e₁.actor = e₂.actor) :
                E.HappensBeforeLe e₁ e₂ ↔ e₁.idx ≤ e₂.idx

                Same-process events are ordered by HappensBeforeLe iff their trace indices are ordered.

                theorem Cslib.Distributed.VectorClock.Execution.sameActor_happensBefore_iff {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (hact : e₁.actor = e₂.actor) :
                E.HappensBefore e₁ e₂ ↔ e₁.idx < e₂.idx

                Same-process events are ordered by HappensBefore iff their trace indices are strictly ordered.

                theorem Cslib.Distributed.VectorClock.Execution.ofInternal_happensBeforeLe_iff {P : Type u} {procs : List P} {e₁ e₂ : (ofInternal procs).Event} :
                (ofInternal procs).HappensBeforeLe e₁ e₂ ↔ e₁ = e₂ ∨ e₁.actor = e₂.actor ∧ e₁.idx < e₂.idx

                In Execution.ofInternal procs, causal ordering reduces purely to same-process program order.

                @[simp]
                theorem Cslib.Distributed.VectorClock.Execution.event_le_iff {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} :
                e₁ ≤ e₂ ↔ E.HappensBeforeLe e₁ e₂
                @[simp]
                theorem Cslib.Distributed.VectorClock.Execution.event_lt_iff {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} :
                e₁ < e₂ ↔ E.HappensBefore e₁ e₂

                Concurrency #

                Two events in E are causally concurrent if neither happens before or equals the other.

                Instances For

                  Concurrency is irreflexive.

                  theorem Cslib.Distributed.VectorClock.Execution.Concurrent.ne {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} (h : E.Concurrent e₁ e₂) :
                  e₁ ≠ e₂

                  Concurrent events are distinct.

                  theorem Cslib.Distributed.VectorClock.Execution.concurrent_symm {P : Type u} {E : Execution P} {e₁ e₂ : E.Event} :
                  E.Concurrent e₁ e₂ ↔ E.Concurrent e₂ e₁

                  Concurrency is symmetric.

                  theorem Cslib.Distributed.VectorClock.Execution.causal_trichotomy {P : Type u} (E : Execution P) (e₁ e₂ : E.Event) :
                  e₁ = e₂ ∨ E.HappensBefore e₁ e₂ ∨ E.HappensBefore e₂ e₁ ∨ E.Concurrent e₁ e₂

                  Causal trichotomy: any two events in E are equal, strictly ordered by HappensBefore in one direction, or Concurrent.

                  Executable causal-past dynamic programming and decidability #

                  @[instance_reducible]
                  @[instance_reducible]
                  @[instance_reducible]

                  Single dynamic-programming step appending the reflexive causal past (as trace indices) of step k to prev.

                  Forward dynamic-programming table computing, for the first k events of E, the reflexive causal-past index list of each event < k. Pattern-matching on the recursive list forces kernel WHNF evaluation once per step during decide.

                  Executable Boolean decision procedure for E.HappensBeforeLe e₁ e₂.

                  The computable Finset of events in the reflexive causal past of e ({x | x ≼ e}).

                  The computable Finset of events in the strict causal past of e ({x | x ≺ e}).

                  @[instance_reducible]
                  @[instance_reducible]
                  @[instance_reducible]

                  Consistent cuts #

                  A subset of events C : Finset E.Event is a consistent cut ([Mat89]) if it is downward closed under HappensBefore: whenever e₂ ∈ C and e₁ ≺ e₂, e₁ ∈ C.

                  Instances For
                    theorem Cslib.Distributed.VectorClock.Execution.isConsistentCut_iff_happensBeforeLe {P : Type u} {E : Execution P} {C : Finset E.Event} :
                    E.IsConsistentCut C ↔ ∀ ⦃e₁ e₂ : E.Event⦄, E.HappensBeforeLe e₁ e₂ → e₂ ∈ C → e₁ ∈ C

                    Characterization of consistent cuts via reflexive HappensBeforeLe.

                    theorem Cslib.Distributed.VectorClock.Execution.IsConsistentCut.mem_of_happensBeforeLe {P : Type u} {E : Execution P} {C : Finset E.Event} (hc : E.IsConsistentCut C) {e₁ e₂ : E.Event} (hle : E.HappensBeforeLe e₁ e₂) (he₂ : e₂ ∈ C) :
                    e₁ ∈ C

                    Consistent cuts are downward closed under HappensBeforeLe.

                    theorem Cslib.Distributed.VectorClock.Execution.IsConsistentCut.union {P : Type u} {E : Execution P} {C₁ C₂ : Finset E.Event} (h₁ : E.IsConsistentCut C₁) (h₂ : E.IsConsistentCut C₂) :
                    E.IsConsistentCut (C₁ ∪ C₂)

                    Consistent cuts are closed under binary union.

                    theorem Cslib.Distributed.VectorClock.Execution.IsConsistentCut.inter {P : Type u} {E : Execution P} {C₁ C₂ : Finset E.Event} (h₁ : E.IsConsistentCut C₁) (h₂ : E.IsConsistentCut C₂) :
                    E.IsConsistentCut (C₁ ∩ C₂)

                    Consistent cuts are closed under binary intersection.

                    The strict causal past of any event is a consistent cut.

                    The reflexive causal past of any event is a consistent cut.

                    theorem Cslib.Distributed.VectorClock.Execution.IsConsistentCut.send_mem_of_recv_mem {P : Type u} {E : Execution P} {C : Finset E.Event} (hc : E.IsConsistentCut C) {e : E.Event} (he : e ∈ C) {p : P} {sIdx : ℕ} (hrecv : e.step = Step.recv p sIdx) :
                    ∃ eSend ∈ C, ↑eSend.idx = sIdx ∧ ∃ (src : P), eSend.step = Step.send src p

                    Absence of orphan receives: if a consistent cut C contains a receive event e, it also contains the matching earlier send event eSend.

                    Process renaming functoriality #

                    def Cslib.Distributed.VectorClock.Execution.map {P : Type u} {Q : Type u_1} (f : P → Q) (E : Execution P) :

                    Push forward an execution E : Execution P along a process map f : P → Q.

                    def Cslib.Distributed.VectorClock.Execution.mapEvent {P : Type u} {Q : Type u_1} (f : P → Q) {E : Execution P} (e : E.Event) :
                    (map f E).Event

                    Transport an event of E to the corresponding event of E.map f.

                    def Cslib.Distributed.VectorClock.Execution.unmapEvent {P : Type u} {Q : Type u_1} (f : P → Q) {E : Execution P} (e' : (map f E).Event) :

                    Inverse event transport from E.map f back to E.

                    theorem Cslib.Distributed.VectorClock.Execution.map_happensBeforeLe_iff {P : Type u} {Q : Type u_1} {f : P → Q} (hf : Function.Injective f) {E : Execution P} {e₁ e₂ : E.Event} :
                    (map f E).HappensBeforeLe (mapEvent f e₁) (mapEvent f e₂) ↔ E.HappensBeforeLe e₁ e₂

                    An injective process renaming preserves and reflects HappensBeforeLe.