Documentation

CslibFrontier.Computability.Distributed.RingElection.ChangRoberts

All-Initiator Unidirectional FIFO Ring Election Steps #

Intermediate steps for unidirectional asynchronous FIFO ring election on Fin n (n ≥ 1) with injective identifiers uid : Fin n → U when all n nodes initiate simultaneously and the election pass ends upon the maximum-identifier node receiving its own identifier back (steps towards Chang and Roberts, not the arbitrary-initiator or announcement-pass endpoints of [ChangRoberts1979]).

Initially every node i : Fin n injects its own identifier uid i into its outgoing clockwise FIFO channel i → i + 1 (crAllInit). Whenever the channel target - 1 → target is nonempty, its oldest message m may be delivered to target (crStep, crLTS):

Because each node's forwarding decision compares m only against its static identifier uid target, every token uid s traverses a schedule-independent clockwise arc of length crHops uid s ∈ {1, …, n} until hitting the first node j with uid s ≤ uid j. Tracking per-node delivery progress yields:

  1. Safety and termination steps (crAllInit_isLeader_le, crAllInit_isLeader_iff_max, crAllInit_terminates): in every state reachable from crAllInit uid, only a uid-maximizer can set isLeader = true; every execution terminates in at most ∑ s, crHops uid s deliveries; and every quiescent reachable state elects the unique uid-maximizing node i* while all j ≠ i* have isLeader j = false.
  2. Worst-case and best-case message steps (crAllInit_messages_le, crAllInit_totalMsgs_rev_eq, crAllInit_totalMsgs_id_eq): total messages transmitted from crAllInit uid satisfy crAllInitMsgs uid sched ≤ n * (n + 1) / 2, attaining n * (n + 1) / 2 on Fin.rev and 2 * n - 1 on id.
  3. Average-case step (crAllInit_avg_totalMsgs_eq): over uniform random identifier permutations σ : Equiv.Perm (Fin n), the average of crAllInitTotalMsgs equals ∑ k ∈ Finset.Icc 1 n, (n : ℚ) / k, proved via clockwise arc partitioning (sum_arcLen_eq) and left-composition with Equiv.swap v u within upper-level sets.

Main definitions #

Main results #

References #

Operational asynchronous FIFO ring model #

structure Cslib.Distributed.RingElection.CRConfig (n : ℕ) (U : Type u_1) :
Type u_1

Global configuration of unidirectional FIFO ring election on Fin n.

  • isLeader : Fin n → Bool

    Whether node i has received its own identifier back and declared leadership.

  • chan : Fin n → List U

    Clockwise FIFO channel on directed edge i → i + 1 (head is oldest, tail is newest).

theorem Cslib.Distributed.RingElection.CRConfig.ext {n : ℕ} {U : Type u_1} {x y : CRConfig n U} (isLeader : x.isLeader = y.isLeader) (chan : x.chan = y.chan) :
x = y

Number of messages currently in flight across all n ring channels.

def Cslib.Distributed.RingElection.crAllInit {n : ℕ} {U : Type u_1} (uid : Fin n → U) :

Simultaneous all-initiator start configuration: every node i injects [uid i] onto i → i + 1.

def Cslib.Distributed.RingElection.crStep {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) (target : Fin n) (cfg : CRConfig n U) :

Deliver the oldest message on channel target - 1 → target to node target (no-op if empty): forward if uid target < m, drop if m < uid target, and set isLeader target := true if m = uid target.

def Cslib.Distributed.RingElection.crStepMsgs {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) (target : Fin n) (cfg : CRConfig n U) :

Number of messages forwarded (transmitted onto target → target + 1) by a single crStep.

def Cslib.Distributed.RingElection.crExec {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) (cfg : CRConfig n U) (sched : List (Fin n)) :

Execute a finite delivery schedule sched : List (Fin n) starting from cfg.

def Cslib.Distributed.RingElection.crForwardedMsgs {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) (cfg : CRConfig n U) :
List (Fin n) → ℕ

Cumulative messages forwarded during sched starting from cfg.

def Cslib.Distributed.RingElection.crAllInitMsgs {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) (sched : List (Fin n)) :

Total messages transmitted across edges in schedule sched from crAllInit uid: the n initial identifier injections plus all subsequent message forwardings.

def Cslib.Distributed.RingElection.crLTS {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) :
LTS (CRConfig n U) (Fin n)

Labelled transition system of enabled FIFO deliveries for crStep uid on Fin n.

Clockwise arc lengths and per-token hop counts #

Clockwise hop distance d ∈ {1, …, n} from a : Fin n to the next element of A along the ring (a + 1, a + 2, …, a + n = a).

def Cslib.Distributed.RingElection.crHops {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (uid : Fin n → U) (s : Fin n) :

Clockwise hop count made by node s's initial message uid s before reaching the first node j with uid s ≤ uid j (1 ≤ crHops uid s ≤ n).

Total number of edge transmissions in a complete election pass from crAllInit uid.

theorem Cslib.Distributed.RingElection.arcLen_bounds_and_mem {n : ℕ} [NeZero n] {A : Finset (Fin n)} {a : Fin n} (ha : a ∈ A) :
1 ≤ arcLen A a ∧ arcLen A a ≤ n ∧ a + Fin.ofNat n (arcLen A a) ∈ A ∧ ∀ (k : ℕ), 1 ≤ k → k < arcLen A a → a + Fin.ofNat n k ∉ A
theorem Cslib.Distributed.RingElection.arcLen_eq_of_isFirst {n : ℕ} [NeZero n] {A : Finset (Fin n)} {a : Fin n} (ha : a ∈ A) {d : ℕ} (hd1 : 1 ≤ d) (hmem : a + Fin.ofNat n d ∈ A) (hmin : ∀ (k : ℕ), 1 ≤ k → k < d → a + Fin.ofNat n k ∉ A) :
arcLen A a = d

Message conservation and reachable-state invariant #

Correctness and termination theorems #

theorem Cslib.Distributed.RingElection.crAllInit_isLeader_le {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) {sched : List (Fin n)} {cfg : CRConfig n U} (hmtr : (crLTS uid).MTr (crAllInit uid) sched cfg) {i : Fin n} (hi : cfg.isLeader i = true) (j : Fin n) :
uid j ≤ uid i

A safety step for simultaneous all-initiator unidirectional FIFO ring election (a step towards Chang and Roberts, not the arbitrary-initiator endpoint): in any configuration reachable from crAllInit uid, if cfg.isLeader i = true then uid i maximizes uid.

theorem Cslib.Distributed.RingElection.crAllInit_isLeader_iff_max {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) {sched : List (Fin n)} {cfg : CRConfig n U} (hmtr : (crLTS uid).MTr (crAllInit uid) sched cfg) (hterm : (crLTS uid).IsTerminal cfg) (i : Fin n) :
cfg.isLeader i = true ↔ ∀ (j : Fin n), uid j ≤ uid i

A quiescent-characterization step for simultaneous all-initiator unidirectional FIFO ring election (a step towards Chang and Roberts, not the arbitrary-initiator endpoint): at any quiescent (LTS.IsTerminal) state reachable from crAllInit uid, cfg.isLeader i = true iff uid i is the global maximum identifier.

theorem Cslib.Distributed.RingElection.crAllInit_execMsgs_eq_totalMsgs {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) {sched : List (Fin n)} {cfg : CRConfig n U} (hmtr : (crLTS uid).MTr (crAllInit uid) sched cfg) (hterm : (crLTS uid).IsTerminal cfg) :

A complete-run message-count step for simultaneous all-initiator unidirectional FIFO ring election (a step towards Chang and Roberts, not the cited endpoint): every quiescent configuration reachable from crAllInit uid was reached in crAllInitTotalMsgs uid deliveries and transmitted crAllInitTotalMsgs uid messages in total.

theorem Cslib.Distributed.RingElection.crAllInit_terminates {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) :
(∀ (sched : List (Fin n)) (cfg : CRConfig n U), (crLTS uid).MTr (crAllInit uid) sched cfg → ∃ (tail : List (Fin n)) (cfg' : CRConfig n U), (crLTS uid).MTr cfg tail cfg' ∧ (crLTS uid).IsTerminal cfg') ∧ (∃! iStar : Fin n, ∀ (j : Fin n), uid j ≤ uid iStar) ∧ ∀ (sched : List (Fin n)) (cfg : CRConfig n U), (crLTS uid).MTr (crAllInit uid) sched cfg → (crLTS uid).IsTerminal cfg → ∃! iStar : Fin n, cfg.isLeader iStar = true

A bounded-termination and unique-leader step for simultaneous all-initiator unidirectional FIFO ring election (a step towards Chang and Roberts, not the arbitrary-initiator endpoint): every configuration reachable from crAllInit uid extends to quiescence, and every reachable quiescent state elects the unique uid-maximizing node i*.

Tight worst-case and best-case message bounds #

theorem Cslib.Distributed.RingElection.crAllInit_messages_le {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) {sched : List (Fin n)} {cfg : CRConfig n U} (hmtr : (crLTS uid).MTr (crAllInit uid) sched cfg) :
crAllInitMsgs uid sched ≤ n * (n + 1) / 2

A worst-case operational message-bound step for simultaneous all-initiator unidirectional FIFO ring election (a step towards Chang and Roberts, not the cited endpoint): in every execution (crLTS uid).MTr (crAllInit uid) sched cfg, total messages transmitted satisfy crAllInitMsgs uid sched ≤ n * (n + 1) / 2.

A reverse-ordered evaluation step for crAllInitTotalMsgs (a step towards Chang and Roberts, not the cited endpoint): when identifiers decrease along the clockwise traversal direction (Fin.rev : Fin n → Fin n), every node s sends its token n - s.val hops to node 0, giving n * (n + 1) / 2 total messages.

An increasing-order evaluation step for crAllInitTotalMsgs (a step towards Chang and Roberts, not the cited endpoint): when identifiers increase clockwise (id : Fin n → Fin n), nodes 0, …, n - 2 travel 1 hop while node n - 1 travels n hops, giving 2 * n - 1 total messages.

Exact n H_n average-case message complexity #

theorem Cslib.Distributed.RingElection.sum_arcLen_eq {n : ℕ} [NeZero n] {A : Finset (Fin n)} (hA : A.Nonempty) :
∑ a ∈ A, arcLen A a = n

For any nonempty subset A ⊆ Fin n, the clockwise distances arcLen A a between consecutive elements of A around the n-ring sum to n.

theorem Cslib.Distributed.RingElection.crAllInit_avg_totalMsgs_eq (n : ℕ) [NeZero n] :
(∑ σ : Equiv.Perm (Fin n), ↑(crAllInitTotalMsgs ⇑σ)) / ↑n.factorial = ∑ k ∈ Finset.Icc 1 n, ↑n / ↑k

An average-case step for simultaneous all-initiator unidirectional FIFO ring election (a step towards Chang and Roberts, not the cited endpoint): averaged uniformly over all n! identifier permutations σ : Equiv.Perm (Fin n), crAllInitTotalMsgs equals ∑ k ∈ Finset.Icc 1 n, (n : ℚ) / k.