Documentation

CslibFrontier.Computability.Distributed.ApproxAgreement.TrimmedMidpoint

Trimmed-extremes midpoint operator for approximate Byzantine agreement #

This module defines the computable trimmed-extremes midpoint operator midTrim over any linearly ordered field K and proves the convex-hull validity and factor-1/2 contraction properties used by the unit-interval, fixed-horizon synchronous (n > 3t) and single-hop asynchronous (n > 5t) protocols in CslibFrontier.Computability.Distributed.ApproxAgreement.Protocol (milestone steps toward #7116 and #3261, after Section 2 of Dolev, Lynch, Pinter, Stark and Weihl):

  1. Convex-hull validity (midTrim_mem_Icc): given a list xs of length m > 2t in which at least m - t entries lie in [lo, hi] (so at most t entries come from Byzantine processes outside [lo, hi]), sorting xs and dropping its t smallest and t largest entries (trimmed t xs, corresponding to reduce^t in Section 2.1, Lemmas 3–4 of [DLP+86]) leaves only values in [lo, hi], and their extreme-value midpoint midTrim t xs also lies in [lo, hi].
  2. Factor-1/2 contraction (abs_midTrim_sub_le): given two lists xs and ys (not necessarily of equal length) each having at most t entries outside [lo, hi] and sharing strictly more than 2t entries with multiplicity (2 * t < (xs ∩ ys).card as multisets), |midTrim t xs - midTrim t ys| ≤ (hi - lo) / 2.

Both regimes of CslibFrontier.Computability.Distributed.ApproxAgreement.Protocol instantiate the same Finset-indexed multiset corollaries (multisetMidTrim_map_mem_Icc and abs_multisetMidTrim_map_sub_le):

Comparison with multi-step representative averaging #

Section 2.2 (p. 503, Lemma 5) of [DLP+86] defines the parameterized family of approximation functions f_{k, t}(V) = mean(select_k(reduce^t(V))) that sort the received multiset, discard t extremes on each end (reduce^t), select every k-th surviving point (select_k), and take the arithmetic mean of those c(m - 2t, k) = ⌊(m - 2t - 1) / k⌋ + 1 representatives, achieving per-round contraction 1 / c(m - 2t, k) (with k = t synchronously and k = 2t asynchronously). Taking the midpoint (min + max) / 2 of the trimmed multiset (midTrim) averages just the two extreme surviving points: it agrees with f_{t, t} at n = 3t + 1 and with f_{2t, t} at n = 5t + 1 (where c = 2), while trading sharper 1 / c contraction at larger n / t for one uniform formula across both 3t < n and 5t < n with no variable-arity division and a uniform contraction factor of 1 / 2 per round.

To ensure kernel reduction (decide +kernel) works inside module clients (where Lean's well-founded List.mergeSort and Mathlib's unexposed List.insertionSort do not unfold), sorting is implemented structurally by sortLE (@[expose]) and equated to List.mergeSort (· ≤ ·) in sortLE_eq_mergeSort.

Main definitions #

Main results #

References #

Kernel-reducible sorting and trimming #

Insert a into a sorted list l in nondecreasing order. Marked @[expose] so kernel evaluation (decide +kernel) unfolds trimmed and midTrim in downstream module clients.

Structural insertion sort on List K, equal to List.mergeSort (· ≤ ·) (sortLE_eq_mergeSort) and marked @[expose] for kernel reduction.

theorem Cslib.Distributed.ApproxAgreement.sortLE_eq_mergeSort {K : Type u_1} [LinearOrder K] (xs : List K) :
sortLE xs = xs.mergeSort fun (x1 x2 : K) => decide (x1 ≤ x2)

Sort xs in nondecreasing order and discard the t smallest and t largest entries.

theorem Cslib.Distributed.ApproxAgreement.trimmed_eq_mergeSort {K : Type u_1} [LinearOrder K] (t : ℕ) (xs : List K) :
trimmed t xs = List.take (xs.length - 2 * t) (List.drop t (xs.mergeSort fun (x1 x2 : K) => decide (x1 ≤ x2)))
@[simp]
theorem Cslib.Distributed.ApproxAgreement.length_trimmed {K : Type u_1} [LinearOrder K] (t : ℕ) (xs : List K) :
(trimmed t xs).length = xs.length - 2 * t
theorem Cslib.Distributed.ApproxAgreement.trimmed_ne_nil {K : Type u_1} [LinearOrder K] {t : ℕ} {xs : List K} (h : 2 * t < xs.length) :
theorem Cslib.Distributed.ApproxAgreement.trimmed_eq_of_perm {K : Type u_1} [LinearOrder K] {xs ys : List K} (h : xs.Perm ys) (t : ℕ) :
trimmed t xs = trimmed t ys

Order-statistic bounds on sortLE #

theorem Cslib.Distributed.ApproxAgreement.mem_Icc_of_mem_trimmed {K : Type u_1} [LinearOrder K] {t : ℕ} {xs : List K} {lo hi z : K} (hcnt : xs.length - t ≤ List.countP (fun (x : K) => decide (lo ≤ x ∧ x ≤ hi)) xs) (hz : z ∈ trimmed t xs) :
z ∈ Set.Icc lo hi

Trimmed-range validity: if at least xs.length - t entries of xs lie in [lo, hi], then every entry of trimmed t xs lies in [lo, hi].

Midpoint operator midTrim and contraction lemmas #

The trimmed-extremes midpoint operator: sort xs, discard the t smallest and t largest entries (trimmed t xs), and return (head + last) / 2 (or 0 when xs.length ≤ 2 * t).

theorem Cslib.Distributed.ApproxAgreement.midTrim_eq_of_perm {K : Type u_1} [Field K] [LinearOrder K] {xs ys : List K} (h : xs.Perm ys) (t : ℕ) :
midTrim t xs = midTrim t ys

Permutation-invariant lift of midTrim t to Multiset K. Because Quot.liftOn reduces directly on quotient constructors, decide +kernel evaluates multisetMidTrim on concrete multisets and Finset.val.map images in module clients.

theorem Cslib.Distributed.ApproxAgreement.midTrim_eq_endpoints {K : Type u_1} [Field K] [LinearOrder K] {t : ℕ} {xs : List K} (h2t : 2 * t < xs.length) :
midTrim t xs = ((sortLE xs)[t] + (sortLE xs)[xs.length - 1 - t]) / 2

Explicit endpoint formula for midTrim t xs when 2 * t < xs.length.

theorem Cslib.Distributed.ApproxAgreement.midTrim_mem_Icc {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {t : ℕ} {xs : List K} {lo hi : K} (h2t : 2 * t < xs.length) (hcnt : xs.length - t ≤ List.countP (fun (x : K) => decide (lo ≤ x ∧ x ≤ hi)) xs) :
midTrim t xs ∈ Set.Icc lo hi

Convex-hull validity (midTrim_mem_Icc): if 2 * t < xs.length and at least xs.length - t entries of xs lie in [lo, hi], then midTrim t xs ∈ [lo, hi].

theorem Cslib.Distributed.ApproxAgreement.abs_midTrim_sub_le {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {t : ℕ} {xs ys : List K} {lo hi : K} (hinter : 2 * t < (↑xs ∩ ↑ys).card) (hxs : xs.length - t ≤ List.countP (fun (x : K) => decide (lo ≤ x ∧ x ≤ hi)) xs) (hys : ys.length - t ≤ List.countP (fun (x : K) => decide (lo ≤ x ∧ x ≤ hi)) ys) :
|midTrim t xs - midTrim t ys| ≤ (hi - lo) / 2

Trimmed-midpoint contraction (abs_midTrim_sub_le): extreme-endpoint specialization after Section 2.2, Lemma 5 of Dolev, Lynch, Pinter, Stark and Weihl (using (min + max) / 2 in place of f_{k, t}'s c-point select_k mean): if xs and ys each have at most t entries outside [lo, hi] and share strictly more than 2 * t multiset entries, then |midTrim t xs - midTrim t ys| ≤ (hi - lo) / 2.

Unified Finset-sender multiset validity and contraction #

theorem Cslib.Distributed.ApproxAgreement.multisetMidTrim_map_mem_Icc {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {P : Type u_2} {F S : Finset P} {t : ℕ} (hF : F.card ≤ t) (hS : 2 * t < S.card) {f : P → K} {lo hi : K} (hval : ∀ p ∈ S, p ∉ F → f p ∈ Set.Icc lo hi) :

Sender-multiset validity: if 2 * t < S.card, F.card ≤ t, and every correct sender p ∈ S \ F reports a value f p ∈ [lo, hi], then multisetMidTrim t (S.val.map f) ∈ [lo, hi].

theorem Cslib.Distributed.ApproxAgreement.abs_multisetMidTrim_map_sub_le {K : Type u_1} [Field K] [LinearOrder K] [IsStrictOrderedRing K] {P : Type u_2} [Fintype P] {F S₁ S₂ : Finset P} {t : ℕ} (hF : F.card ≤ t) (hcard : Fintype.card P + 3 * t < S₁.card + S₂.card) {val f₁ f₂ : P → K} {lo hi : K} (hval : ∀ p ∉ F, val p ∈ Set.Icc lo hi) (hf₁ : ∀ p ∈ S₁, p ∉ F → f₁ p = val p) (hf₂ : ∀ p ∈ S₂, p ∉ F → f₂ p = val p) :
|multisetMidTrim t (Multiset.map f₁ S₁.val) - multisetMidTrim t (Multiset.map f₂ S₂.val)| ≤ (hi - lo) / 2

Sender-multiset contraction: suppose F.card ≤ t, two recipients collect values f₁, f₂ from sender sets S₁, S₂ with Fintype.card P + 3 * t < S₁.card + S₂.card (which holds both synchronously when S₁ = S₂ = univ and 3 * t < |P|, and asynchronously when |S₁|, |S₂| ≥ |P| - t and 5 * t < |P|), and every correct sender p ∉ F sends a common value val p ∈ [lo, hi] to whichever recipient hears from it. Then |multisetMidTrim t (S₁.val.map f₁) - multisetMidTrim t (S₂.val.map f₂)| ≤ (hi - lo) / 2.