Documentation

CslibFrontier.Foundations.NumberTheory.DoublingSign

Recovering a sign by the first flagged doubling #

Successive doublings of a small nonzero rational eventually enter a prescribed magnitude window. A sufficiently accurate approximation modulo one is then flagged, and its first flag lies on the correct side of one half. The threshold, flag margin, error and final index are parameters. In particular, a caller supplies the magnitude/product and precision bounds, not a correctness assertion about the sign procedure.

This is the mathematical first-flag argument of Section 2 of [OAI26f], generalized beyond its fixed constants. There is no complexity membership claim.

Main definitions #

Main results #

References #

An approximation is flagged when it stays at least t away from either endpoint.

def Cslib.FirstCircleFlag (t : ℚ) (w : ℕ → ℚ) (k : ℕ) :

Index k is flagged and every preceding index is unflagged.

theorem Cslib.CircleClose.not_flag_zero {ε t w : ℚ} (h : CircleClose ε w 0) (hε : ε < t) :

No approximation of zero can be flagged when the error is below the flag margin.

theorem Cslib.CircleClose.sign_of_flag {ε t b w q : ℚ} (h : CircleClose ε w q) (hf : CircleFlag t w) (hε : ε < t) (hb : b + ε ≤ 1 / 2) (hq : |q| < b) :
(0 < q ↔ w < 1 / 2) ∧ (q < 0 ↔ 1 / 2 < w)

A flag excludes wrapping at zero; a small target has the sign indicated by the side of one half. This also rules out a flag for a zero target.

theorem Cslib.CircleClose.flag_of_magnitude {ε t a b w q : ℚ} (h : CircleClose ε w q) (hw : 0 ≤ w ∧ w < 1) (hlo : t + ε ≤ a) (hhi : b + ε ≤ 1 - t) (ht : 0 < t) (hqlo : a ≤ |q|) (hqhi : |q| < b) :

A target whose magnitude is between a and b must be flagged, provided the rounding error fits between that window and the endpoints.

theorem Cslib.exists_first_doubling_magnitude {q a : ℚ} {K : ℕ} (hstart : |q| < a) (hend : a ≤ |2 ^ K * q|) :
∃ k ≤ K, a ≤ |2 ^ k * q| ∧ ∀ j ≤ k, |2 ^ j * q| < 2 * a

At the first doubling reaching magnitude a, the magnitude is still below 2a. The final-index condition is a numerical bound, not a first-flag correctness premise.

theorem Cslib.firstCircleFlag_sign {q a ε t : ℚ} {K : ℕ} (w : ℕ → ℚ) (hstart : |q| < a) (hend : a ≤ |2 ^ K * q|) (ht : 0 < t) (hε : ε < t) (hlo : t + ε ≤ a) (hhi : 2 * a + ε ≤ 1 / 2) (hw : ∀ k ≤ K, 0 ≤ w k ∧ w k < 1) (happrox : ∀ k ≤ K, CircleClose ε (w k) (2 ^ k * q)) :
∃ k ≤ K, FirstCircleFlag t w k ∧ (0 < q ↔ w k < 1 / 2) ∧ (q < 0 ↔ 1 / 2 < w k)

Mathematical correctness of first-flag sign recovery. Approximation, magnitude, precision, flag margin and cutoff conditions are independent explicit inputs.

theorem Cslib.FirstCircleFlag.unique {t : ℚ} {w : ℕ → ℚ} {j k : ℕ} (hj : FirstCircleFlag t w j) (hk : FirstCircleFlag t w k) :
j = k

The first flagged index is unique, without any approximation hypotheses.

theorem Cslib.FirstCircleFlag.sign {q a ε t : ℚ} {K k : ℕ} {w : ℕ → ℚ} (hf : FirstCircleFlag t w k) (hstart : |q| < a) (hend : a ≤ |2 ^ K * q|) (ht : 0 < t) (hε : ε < t) (hlo : t + ε ≤ a) (hhi : 2 * a + ε ≤ 1 / 2) (hw : ∀ j ≤ K, 0 ≤ w j ∧ w j < 1) (happrox : ∀ j ≤ K, CircleClose ε (w j) (2 ^ j * q)) :
k ≤ K ∧ (0 < q ↔ w k < 1 / 2) ∧ (q < 0 ↔ 1 / 2 < w k)

Any first flagged index has the correct sign, under the numerical doubling bounds.