Documentation

CslibFrontier.Computability.Distributed.VectorClock.Clocks

Lamport scalar clocks and Mattern vector clocks #

This module formalizes operational logical clocks over causally well-formed asynchronous message-passing executions (Cslib.Distributed.VectorClock.Execution):

  1. Lamport scalar clocks ([Lam78]): each process maintains a scalar ℕ counter, stepping to L p + 1 on local/send events and max (L p) L_msg + 1 upon message receipt. We prove strict causal monotonicity (lamportClock_strictMono), show that breaking timestamp ties by [LinearOrder P] yields a strict total order extending HappensBefore (instIsStrictTotalOrderLamportTotalOrder, happensBefore_imp_lamportTotalOrder), and prove scalar incompleteness (not_exists_1d_characterization): whenever 2 ≤ Fintype.card P, there exists a valid execution on P whose causal order embeds into no LinearOrder α.

  2. Mattern vector clocks ([Mat89], §§7–8; see also [Fid88] for the asynchronous sender-increment variant): each process maintains Cslib.Distributed.VectorClock P := P → ℕ, taking coordinatewise ⊔ upon message receipt and incrementing its own coordinate at every step (Execution.vc; in contrast, [Fid88]'s asynchronous Rule RA4 additionally increments the sender's coordinate on receive so its single-coordinate test uses < instead of ≤). We prove:

Main definitions #

Main results #

References #

@[reducible, inline]

A vector timestamp over process type P, equipped with Mathlib's coordinatewise product PartialOrder and SemilatticeSup (⊔).

@[instance_reducible]

Decidability of strict vector-clock comparison over a finite process set.

Shared execution clock scanner #

def Cslib.Distributed.VectorClock.Execution.scanStepAux {P : Type u} [DecidableEq P] {α : Type u_1} (E : Execution P) (next : P → α → Option α → α) (k : ℕ) (hk : k < E.steps.length) (hist : List α) (loc : P → α) :
List α × (P → α)

Single step of scanSteps, advancing (hist, loc) across E.steps[k].

def Cslib.Distributed.VectorClock.Execution.scanSteps {P : Type u} [DecidableEq P] {α : Type u_1} (E : Execution P) (init : P → α) (next : P → α → Option α → α) :
ℕ → List α × (P → α)

Prefix scan over the first k steps of E, maintaining recorded step timestamps List α and the per-process local clock P → α. Pattern-matching on the recursive pair and list forces kernel WHNF evaluation once per step during decide.

def Cslib.Distributed.VectorClock.Execution.evalScan {P : Type u} [DecidableEq P] {α : Type u_1} (E : Execution P) (defaultVal : α) (init : P → α) (next : P → α → Option α → α) (e : E.Event) :
α

Evaluate a scanSteps clock at event e (running the prefix up to e.idx + 1).

Lamport scalar clocks ([Lam78]) #

def Cslib.Distributed.VectorClock.Execution.lamportNext {P : Type u} :
P → (cur : ℕ) → (msg? : Option ℕ) → ℕ

Local transition rule for Lamport's scalar logical clock.

Lamport's scalar logical clock E.Event → ℕ ([Lam78]): each local/send event receives L p + 1 and each receive event receives max (L p) L_msg + 1.

Every Lamport timestamp is strictly positive (1 ≤ E.lamportClock e).

Strict causal monotonicity of Lamport clocks ([Lam78]): e₁ ≺ e₂ → E.lamportClock e₁ < E.lamportClock e₂.

Reflexive causal monotonicity of Lamport clocks (e₁ ≼ e₂ → E.lamportClock e₁ ≤ E.lamportClock e₂).

theorem Cslib.Distributed.VectorClock.Execution.lamportClock_actor_injective {P : Type u} [DecidableEq P] (E : Execution P) {e₁ e₂ : E.Event} (hc : E.lamportClock e₁ = E.lamportClock e₂) (ha : e₁.actor = e₂.actor) :
e₁ = e₂

Distinct events on the same process never share a Lamport timestamp, so (lamportClock, actor) uniquely identifies every event.

Lamport's total ordering of events ([Lam78]): order by scalar timestamp and break ties using a linear order on process identifiers.

Instances For

    Lamport's tie-broken event relation is a strict total order on E.Event.

    lamportTotalOrder is a linear extension of HappensBefore.

    theorem Cslib.Distributed.VectorClock.not_exists_1d_characterization {P : Type u} [Fintype P] (hP : 2 ≤ Fintype.card P) :
    ∃ (E : Execution P), ∀ {α : Type v} [inst : LinearOrder α] (f : E.Event → α), ¬∀ (e₁ e₂ : E.Event), E.HappensBeforeLe e₁ e₂ ↔ f e₁ ≤ f e₂

    Scalar incompleteness of one-dimensional clocks (original two-process communication-free counterexample witnessing [Lam78], p. 560): whenever 2 ≤ Fintype.card P, there is a causally well-formed execution on P admitting no order-embedding into any LinearOrder α.

    Mattern vector clocks ([Mat89]; see also [Fid88]) #

    Local transition rule for Mattern vector clocks ([Mat89], §7): coordinatewise ⊔ with the incoming message vector (if any), followed by incrementing the executing process's own entry.

    Mattern vector clock E.Event → VectorClock P ([Mat89], §7; cf. [Fid88], Rules RA1–RA4, which additionally increment the sender's entry upon receive).

    At every event e, its executing process's own vector-clock entry is strictly positive.

    theorem Cslib.Distributed.VectorClock.Execution.vc_actor_strictMono_of_sameActor {P : Type u} [DecidableEq P] {E : Execution P} {e₁ e₂ : E.Event} (hact : e₁.actor = e₂.actor) (hlt : e₁.idx < e₂.idx) :
    E.vc e₁ e₁.actor < E.vc e₂ e₂.actor

    Along events of the same process, that process's vector-clock coordinate is strictly increasing.

    Vector clocks are monotone with respect to HappensBeforeLe.

    theorem Cslib.Distributed.VectorClock.Execution.happensBeforeLe_iff_coord_le {P : Type u} [DecidableEq P] {E : Execution P} {e₁ e₂ : E.Event} :
    E.HappensBeforeLe e₁ e₂ ↔ E.vc e₁ e₁.actor ≤ E.vc e₂ e₁.actor

    Single-coordinate comparison of given timestamps (≼) ([Mat89], §8, Theorem 11): e₁ ≼ e₂ iff e₁'s own process coordinate in vc e₁ is at most that in vc e₂.

    theorem Cslib.Distributed.VectorClock.Execution.happensBefore_iff_coord_le {P : Type u} [DecidableEq P] {E : Execution P} {e₁ e₂ : E.Event} (hne : e₁ ≠ e₂) :
    E.HappensBefore e₁ e₂ ↔ E.vc e₁ e₁.actor ≤ E.vc e₂ e₁.actor

    Single-coordinate comparison of given timestamps (≺) ([Mat89], §8, Theorem 11): for distinct events e₁ ≠ e₂, e₁ ≺ e₂ iff E.vc e₁ e₁.actor ≤ E.vc e₂ e₁.actor.

    theorem Cslib.Distributed.VectorClock.Execution.happensBeforeLe_iff_vc_le {P : Type u} [DecidableEq P] {E : Execution P} {e₁ e₂ : E.Event} :
    E.HappensBeforeLe e₁ e₂ ↔ E.vc e₁ ≤ E.vc e₂

    Vector-clock order-isomorphism (≼) ([Mat89], §8, Theorem 10): e₁ ≼ e₂ ↔ E.vc e₁ ≤ E.vc e₂.

    Vector timestamps uniquely identify events (Function.Injective E.vc).

    theorem Cslib.Distributed.VectorClock.Execution.happensBefore_iff_vc_lt {P : Type u} [DecidableEq P] {E : Execution P} {e₁ e₂ : E.Event} :
    E.HappensBefore e₁ e₂ ↔ E.vc e₁ < E.vc e₂

    Vector-clock strict order-isomorphism (≺) ([Mat89], §8, Theorem 10): e₁ ≺ e₂ ↔ E.vc e₁ < E.vc e₂.

    theorem Cslib.Distributed.VectorClock.Execution.concurrent_iff_vc_incomparable {P : Type u} [DecidableEq P] {E : Execution P} {e₁ e₂ : E.Event} :
    E.Concurrent e₁ e₂ ↔ ¬E.vc e₁ ≤ E.vc e₂ ∧ ¬E.vc e₂ ≤ E.vc e₁

    Exact concurrency detection: two events are causally concurrent iff their vector timestamps are coordinatewise incomparable.

    Mattern's frontier vector-clock criterion for consistent cuts #

    The cut induced by a per-process frontier frontier : P → E.Event, containing every event e occurring on its process at or before frontier e.actor.

    @[simp]
    theorem Cslib.Distributed.VectorClock.Execution.mem_cutOfFrontier {P : Type u} {E : Execution P} {frontier : P → E.Event} {e : E.Event} :
    e ∈ E.cutOfFrontier frontier ↔ e.idx ≤ (frontier e.actor).idx
    theorem Cslib.Distributed.VectorClock.Execution.isConsistentCut_cutOfFrontier_iff {P : Type u} [DecidableEq P] {E : Execution P} {frontier : P → E.Event} (hact : ∀ (p : P), (frontier p).actor = p) :
    E.IsConsistentCut (E.cutOfFrontier frontier) ↔ ∀ (p q : P), E.vc (frontier q) p ≤ E.vc (frontier p) p

    Mattern's frontier cut characterization ([Mat89]): when frontier p is an event on process p for every p : P, E.cutOfFrontier frontier is a consistent cut iff every process's own vector-clock coordinate across the frontier is maximized at its own frontier event (∀ p q, E.vc (frontier q) p ≤ E.vc (frontier p) p).