Two timers fire less than δ apart with probability at most about (2δ − 1)/Mmin
ProvedOpenSearchElectionTimer.close_pair_probFor all integers a, b and natural numbers Ma, Mb, Mmin, δ with 1 ≤ Mmin, Mmin ≤ Mb ≤ 2^63 and 1 ≤ δ: the number of pairs of draws (x, y) : Fin (2^64) × Fin (2^64) with |(a + randomDelay Ma x) − (b + randomDelay Mb y)| < δ, divided by (2^64)^2, is at most (2δ − 1) · ⌈2^63 / Mmin⌉ / 2^63, where 2δ − 1 is computed in the natural numbers and ⌈2^63 / Mmin⌉ = (2^63 + Mmin − 1) / Mmin.
Two candidates with offsets a and b and independent uniform draws fire less than δ milliseconds apart with probability at most about (2δ − 1) / Mmin, whatever the offsets and whatever the first candidate's bound Ma, on which nothing is assumed: for each value of the first draw, the second delay must fall among the 2δ − 1 integers less than δ away from a fixed point. With δ = 100 and Mmin = 10000 the bound is about 1.99%.
import Definitions.Def_OpenSearchElectionTimer open OpenSearchPreVote OpenSearchElectionTimer
theorem OpenSearchElectionTimer.close_pair_prob (a b : Int) (Ma Mb Mmin δ : Nat) (hM : 1 ≤ Mmin)
(hMb : Mmin ≤ Mb ∧ Mb ≤ 2 ^ 63) (hδ : 1 ≤ δ) :
((Finset.univ.filter (fun p : Fin (2 ^ 64) × Fin (2 ^ 64) =>
|(a + randomDelay Ma p.1) - (b + randomDelay Mb p.2)| < δ)).card : ℚ) / (2 ^ 64) ^ 2 ≤
(2 * δ - 1 : ℕ) * ((2 ^ 63 + Mmin - 1) / Mmin : ℕ) / 2 ^ 63 := by sorryRead-back
What the Lean code literally says, in plain math · claude-opus-5-5 (independent sub-agent, blind: Lean code + auditor instructions only)
Read-back: OpenSearchElectionTimer.close_pair_prob
Notions used
Draws. A draw is an element of , read as the Java long .
nonNegative. if , and otherwise.
randomDelay. , with the natural-number remainder.
- For the value is in .
- For the value is , since Lean has .
- For , exactly draws give value . This is the content of the sibling theorems
randomDelay_cardandrandomDelay_near_uniform; it is used here only to explain the bound.
contestedBound. in . The present statement does not use the name, but its right-hand side equals , because .
1. Declaration
theorem OpenSearchElectionTimer.close_pair_prob (a b : Int) (Ma Mb Mmin δ : Nat) (hM : 1 ≤ Mmin)
(hMb : Mmin ≤ Mb ∧ Mb ≤ 2 ^ 63) (hδ : 1 ≤ δ) :
((Finset.univ.filter (fun p : Fin (2 ^ 64) × Fin (2 ^ 64) =>
|(a + randomDelay Ma p.1) - (b + randomDelay Mb p.2)| < δ)).card : ℚ) / (2 ^ 64) ^ 2 ≤
(2 * δ - 1 : ℕ) * ((2 ^ 63 + Mmin - 1) / Mmin : ℕ) / 2 ^ 63
Binders: ; .
Hypotheses, in order:
- ;
- ;
- .
Conclusion (in ). For a pair of draws , define the integers
The theorem asserts
How the Lean terms elaborate:
- The difference and the absolute value are computed in , with cast to . So means .
(2 * δ - 1 : ℕ)is a truncated natural subtraction. By it equals .((2 ^ 63 + Mmin - 1) / Mmin : ℕ)is a natural floor division. By it equals .- Both natural numbers are cast to .
Probability reading. and are independent and uniform on . The probability that the two fire times and are less than apart is at most , which is approximately .
2. What is not constrained
-
and are arbitrary integers. The bound does not depend on them.
-
is completely unconstrained. It may be any natural number, including:
- , where Lean's . This is not a value Java produces, since Java asserts
0 < upperBound. - values above .
The hypotheses are asymmetric: only is bounded, from below by and from above by . The bound therefore rests on the randomness of the second draw alone. For each fixed , there are at most integer values with , and each value has at most preimages.
- , where Lean's . This is not a value Java produces, since Java asserts
-
enters only as a lower bound on . The right side does not involve itself.
-
is not needed for truth. For the event is empty, and the right side is (because ). The result is .
-
is needed. For , Lean's division by zero makes the right side , while the left side can be positive.
-
The upper half of () appears not to be needed for truth. For , each delay value has at most preimages, and .
-
Trivial regime. When , roughly , the right side is at least and the statement is trivially true.
-
The bound is attained. Take (so ), , and . Then both sides equal (I computed this exactly). So the inequality cannot be improved in general.
-
Satisfiable, not vacuous. For example .
3. Plain-language summary
Two candidates fire at arbitrary integer offsets plus random delays drawn from two independent uniform 64-bit draws. The probability that they fire less than apart is at most , about . This requires the second candidate's bound to lie between and ; the first candidate's bound is unrestricted.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.