Documentation

CslibFrontier.Computability.Distributed.RingElection.Peterson

All-Active Basic Two-Hop Unidirectional FIFO Ring Election Steps #

Intermediate steps for all-initially-active basic two-hop unidirectional asynchronous FIFO ring election on Fin n (n ≥ 1) with injective identifiers uid : Fin n → U from a linear order U (steps towards Peterson, not the spontaneous-wakeup or 1.44 n log₂ n Fibonacci-threshold endpoints of [Peterson1982]).

All n processors start active (twoHopAllActiveInit), hold a current temporary identifier tid, and execute two-hop comparison phases while eliminated processors act as passive FIFO relays (.relay):

  1. First hop (hop1): at the start of a phase, each active processor p emits .hop1 tid_p, which passive relays forward clockwise to the next active processor q. If tid_p = tid_q, tid_q wrapped around the entire ring as the sole remaining active processor, so q becomes .leader tid_q without emitting further messages. Otherwise q records ntid := tid_p (.active2 tid_q tid_p) and emits .hop2 tid_p.
  2. Second hop (hop2): .hop2 tid_p is forwarded clockwise to the next active processor r, which has already received ntid_r = tid_q in .hop1 from q and therefore knows all three consecutive active temporary identifiers (tid_p, tid_q, tid_r). If q is a strict local peak (tid_p < tid_q ∧ tid_r < tid_q), r remains active in the next phase adopting tid' := tid_q and immediately emits .hop1 tid_q; otherwise r becomes a passive .relay.

The proof combines two clean structural ingredients:

Main definitions #

Main results #

References #

Local processor machine and asynchronous FIFO ring LTS #

Message payload in the basic two-hop unidirectional ring election protocol.

  • hop1 {U : Type u_1} (tid : U) : TwoHopMsg U

    First-hop message carrying an active node's current temporary identifier tid.

  • hop2 {U : Type u_1} (ntid : U) : TwoHopMsg U

    Second-hop message carrying the predecessor active node's temporary identifier ntid.

Local state of a processor in the basic two-hop unidirectional ring election protocol.

  • active1 {U : Type u_1} (tid : U) : TwoHopNode U

    Active node at start of phase holding tid, awaiting hop1 from its predecessor.

  • active2 {U : Type u_1} (tid ntid : U) : TwoHopNode U

    Active node holding tid and predecessor's ntid, awaiting hop2 (nnid).

  • relay {U : Type u_1} : TwoHopNode U

    Passive relay node forwarding every incoming message unchanged.

  • leader {U : Type u_1} (maxUid : U) : TwoHopNode U

    Elected leader node holding the global maximum identifier maxUid.

Whether a TwoHopNode is in the elected .leader state.

Output of a single message reception in the basic two-hop protocol: updated processor state and outgoing FIFO messages appended to i → i + 1.

  • nextNode : TwoHopNode U

    Updated local state of the receiving processor.

  • sent : List (TwoHopMsg U)

    Outgoing messages appended to the processor's clockwise channel.

Deterministic local transition handler for the basic two-hop protocol upon receiving msg.

Global configuration of the basic two-hop protocol on an asynchronous FIFO unidirectional n-ring.

  • node : Fin n → TwoHopNode U

    Local state of each node i : Fin n.

  • chan : Fin n → List (TwoHopMsg U)

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

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

Whether node i has declared leadership in configuration cfg.

All-initially-active start configuration for the basic two-hop protocol (a step model towards Peterson): every node i starts active with tid = uid i and injects [.hop1 (uid i)] onto i → i + 1.

def Cslib.Distributed.RingElection.twoHopStep {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (target : Fin n) (cfg : TwoHopConfig n U) :

Deliver the oldest message on target - 1 → target to target (no-op if empty).

def Cslib.Distributed.RingElection.twoHopStepMsgs {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (target : Fin n) (cfg : TwoHopConfig n U) :

Number of messages emitted onto target → target + 1 by a single twoHopStep.

def Cslib.Distributed.RingElection.twoHopExec {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (cfg : TwoHopConfig n U) (sched : List (Fin n)) :

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

Cumulative messages emitted onto ring edges during sched starting from cfg.

def Cslib.Distributed.RingElection.twoHopAllActiveExecMsgs {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 twoHopAllActiveInit uid: the n initial .hop1 injections plus all subsequent emissions.

Labelled transition system of enabled FIFO deliveries in the basic two-hop protocol on Fin n.

Strong one-step FIFO confluence and strip lemma #

theorem Cslib.Distributed.RingElection.twoHopStep_comm {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {cfg : TwoHopConfig n U} {i j : Fin n} (hne : i ≠ j) (hi : cfg.chan (i - 1) ≠ []) (hj : cfg.chan (j - 1) ≠ []) :

A one-step FIFO confluence step for the basic two-hop unidirectional ring protocol (a step towards Peterson, not the cited endpoint): whenever two distinct processors i ≠ j both have nonempty incoming channels in cfg, each remains enabled after the other steps, the two delivery orders reach the same global configuration, and their emitted message counts commute.

Active sub-ring geometry and per-phase halving #

Counter-clockwise hop distance d ∈ {1, …, n} from q to the previous element of A, computed via arcLen on the negated set A.image (fun x => -x).

Immediate counter-clockwise active predecessor of q in A.

Immediate clockwise active successor of p in A.

def Cslib.Distributed.RingElection.twoHopSurvivors {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (A : Finset (Fin n)) (tidMap : Fin n → U) :

Surviving active nodes after a two-hop comparison phase on active set A with temporary identifier assignment tidMap: nodes r ∈ A whose predecessor q = prevActive A r is a strict local peak (tidMap (prevActive A q) < tidMap q ∧ tidMap r < tidMap q).

theorem Cslib.Distributed.RingElection.twoHopSurvivors_card_halving {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] (A : Finset (Fin n)) (tidMap : Fin n → U) :
2 * (twoHopSurvivors A tidMap).card ≤ A.card

A combinatorial active-subring halving step for two-hop peak comparison (a step towards Peterson, not the cited endpoint): adjacent active nodes cannot both be strict peaks, so r and prevActive A r for r ∈ twoHopSurvivors A tidMap form disjoint subsets of A, giving 2 * (twoHopSurvivors A tidMap).card ≤ A.card.

Combinatorial state of active nodes and their temporary identifiers at phase k.

  • active : Finset (Fin n)

    Active node set A_k at phase k.

  • tidMap : Fin n → U

    Temporary identifier assignment on Fin n (meaningful on active).

Phase-by-phase combinatorial evolution of the all-initially-active basic two-hop protocol (stabilizing once active.card ≤ 1).

Total number of elimination phases (2 ≤ active.card) executed by the all-initially-active basic two-hop protocol on uid before active.card = 1.

A per-phase active-count halving step for all-initially-active basic two-hop ring election (a step towards Peterson, not the cited endpoint): whenever 2 ≤ (twoHopAllActivePhase uid k).active.card, the next phase has at most half as many active nodes.

A logarithmic phase-bound step for all-initially-active basic two-hop ring election (a step towards Peterson, not the cited endpoint): for any injective uid : Fin n → U, the number of elimination phases satisfies twoHopAllActivePhases uid ≤ Nat.log 2 n, and at phase K = twoHopAllActivePhases uid (as well as at Nat.log 2 n), exactly 1 active processor remains.

Canonical wave execution across passive relays and active nodes #

Canonical full-protocol run and main theorems #

theorem Cslib.Distributed.RingElection.twoHopAllActive_elects_leader {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) :
(∀ (sched : List (Fin n)) (cfg : TwoHopConfig n U), (twoHopLTS n U).MTr (twoHopAllActiveInit uid) sched cfg → ∃ (rem : List (Fin n)) (cfg_term : TwoHopConfig n U), (twoHopLTS n U).MTr cfg rem cfg_term ∧ (twoHopLTS n U).IsTerminal cfg_term) ∧ ∀ (sched : List (Fin n)) (cfg : TwoHopConfig n U), (twoHopLTS n U).MTr (twoHopAllActiveInit uid) sched cfg → (twoHopLTS n U).IsTerminal cfg → ∃! iStar : Fin n, cfg.isLeader iStar = true ∧ (∃ (maxUid : U), cfg.node iStar = TwoHopNode.leader maxUid ∧ (∀ (j : Fin n), uid j ≤ maxUid) ∧ ∃ (j₀ : Fin n), uid j₀ = maxUid) ∧ ∀ (j : Fin n), j ≠ iStar → cfg.node j = TwoHopNode.relay

A bounded-termination and unique-leader election step for all-initially-active basic two-hop unidirectional FIFO ring election (a step towards Peterson, not the spontaneous-wakeup or Fibonacci-threshold endpoint): for any injective uid : Fin n → U on Fin n:

  1. Every configuration reachable from twoHopAllActiveInit uid extends to a quiescent (LTS.IsTerminal) configuration;
  2. Every quiescent configuration reachable from twoHopAllActiveInit uid coincides with the unique terminal configuration where a single node i* holds .leader maxUid (maxUid = max_j (uid j)) and all j ≠ i* are passive .relays (∃! i*, cfg.isLeader i* = true).
theorem Cslib.Distributed.RingElection.twoHopAllActive_execMsgs_eq {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) {sched : List (Fin n)} {cfg : TwoHopConfig n U} (hmtr : (twoHopLTS n U).MTr (twoHopAllActiveInit uid) sched cfg) (hterm : (twoHopLTS n U).IsTerminal cfg) :

A complete-run message-accounting step for all-initially-active basic two-hop unidirectional FIFO ring election (a step towards Peterson, not the cited endpoint): every complete execution (twoHopLTS n U).MTr (twoHopAllActiveInit uid) sched cfg (IsTerminal cfg) transmits 2 * n * twoHopAllActivePhases uid + n messages regardless of the asynchronous FIFO delivery order.

theorem Cslib.Distributed.RingElection.twoHopAllActive_messages_le {n : ℕ} [NeZero n] {U : Type u_1} [LinearOrder U] {uid : Fin n → U} (huid : Function.Injective uid) {sched : List (Fin n)} {cfg : TwoHopConfig n U} (hmtr : (twoHopLTS n U).MTr (twoHopAllActiveInit uid) sched cfg) :
twoHopAllActiveExecMsgs uid sched ≤ 2 * n * Nat.log 2 n + n

An asynchronous message-bound step for all-initially-active basic two-hop unidirectional FIFO ring election (a step towards Peterson, not the spontaneous-wakeup or 1.44 n log₂ n Fibonacci-threshold endpoint): in every execution (twoHopLTS n U).MTr (twoHopAllActiveInit uid) sched cfg (partial or complete), total messages transmitted across all edges satisfy twoHopAllActiveExecMsgs uid sched ≤ 2 * n * Nat.log 2 n + n.