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):
Lamport scalar clocks ([Lam78]): each process maintains a scalar
ℕcounter, stepping toL p + 1on local/send events andmax (L p) L_msg + 1upon message receipt. We prove strict causal monotonicity (lamportClock_strictMono), show that breaking timestamp ties by[LinearOrder P]yields a strict total order extendingHappensBefore(instIsStrictTotalOrderLamportTotalOrder,happensBefore_imp_lamportTotalOrder), and prove scalar incompleteness (not_exists_1d_characterization): whenever2 ≤ Fintype.card P, there exists a valid execution onPwhose causal order embeds into noLinearOrder α.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:- Exact order-isomorphism (
happensBeforeLe_iff_vc_le,happensBefore_iff_vc_lt):e₁ ≼ e₂ ↔ E.vc e₁ ≤ E.vc e₂ande₁ ≺ e₂ ↔ E.vc e₁ < E.vc e₂, - Single-coordinate comparison of given timestamps (
happensBeforeLe_iff_coord_le,happensBefore_iff_coord_le):e₁ ≼ e₂ ↔ E.vc e₁ e₁.actor ≤ E.vc e₂ e₁.actor, and fore₁ ≠ e₂,e₁ ≺ e₂ ↔ E.vc e₁ e₁.actor ≤ E.vc e₂ e₁.actor, - Exact concurrency detection (
concurrent_iff_vc_incomparable), and - Mattern's frontier cut characterization (
isConsistentCut_cutOfFrontier_iff): the cut induced by per-process frontier eventsfrontier : P → E.Eventis consistent iff every process's own coordinate is maximized at its own frontier event (∀ p q, E.vc (frontier q) p ≤ E.vc (frontier p) p).
- Exact order-isomorphism (
Main definitions #
Cslib.Distributed.VectorClock:P-indexedℕtimestamp vectorP → ℕ.Cslib.Distributed.VectorClock.Execution.lamportClock: Lamport scalar timestampE.Event → ℕ.Cslib.Distributed.VectorClock.Execution.lamportTotalOrder: tie-broken strict total order onE.EventextendingHappensBefore.Cslib.Distributed.VectorClock.Execution.vc: Mattern vector timestampE.Event → VectorClock P.Cslib.Distributed.VectorClock.Execution.cutOfFrontier: global event prefix induced by a per-process frontierP → E.Event.
Main results #
Cslib.Distributed.VectorClock.Execution.lamportClock_strictMono:e₁ ≺ e₂ → E.lamportClock e₁ < E.lamportClock e₂.Cslib.Distributed.VectorClock.Execution.instIsStrictTotalOrderLamportTotalOrder,Cslib.Distributed.VectorClock.Execution.happensBefore_imp_lamportTotalOrder:lamportTotalOrderis a strict total order extendingHappensBefore.Cslib.Distributed.VectorClock.not_exists_1d_characterization: for2 ≤ Fintype.card P, no singleLinearOrder-valued clock characterizesHappensBeforeLeacross executions onP.Cslib.Distributed.VectorClock.Execution.happensBeforeLe_iff_coord_le,Cslib.Distributed.VectorClock.Execution.happensBefore_iff_coord_le: causality characterization by single-coordinate comparison of given timestamps ate₁.actor.Cslib.Distributed.VectorClock.Execution.happensBeforeLe_iff_vc_le,Cslib.Distributed.VectorClock.Execution.happensBefore_iff_vc_lt: exact order-isomorphism between happens-before and the product order onVectorClock P.Cslib.Distributed.VectorClock.Execution.concurrent_iff_vc_incomparable: exact concurrency detection from vector-clock incomparability.Cslib.Distributed.VectorClock.Execution.isConsistentCut_cutOfFrontier_iff: Mattern's owner-maximum frontier criterion for consistent cuts.
References #
A vector timestamp over process type P, equipped with Mathlib's coordinatewise product
PartialOrder and SemilatticeSup (⊔).
Decidability of strict vector-clock comparison over a finite process set.
Shared execution clock scanner #
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.
Evaluate a scanSteps clock at event e (running the prefix up to e.idx + 1).
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₂).
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.
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 α.
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.
Vector clocks are monotone with respect to HappensBeforeLe.
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₂.
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.
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).
Vector-clock strict order-isomorphism (≺) ([Mat89], §8, Theorem 10):
e₁ ≺ 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 #
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).