| | @@ -0,0 +1,129 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap.WindowCertificate |
| 2 | +import Batteries.Tactic.OpenPrivate |
| 3 | + |
| 4 | +/-! |
| 5 | +# The uniform row with allowance `r = 1/100` (Erdős #530, brief B3d) |
| 6 | + |
| 7 | +`Erdos530Gap.row_margin` certifies `48 + Row.peak / 10000 < Row.lowerScore τ κ z`. The |
| 8 | +window transfer (12) of `experiments/erdos530/upper-deletion-constant/NOTES.md` §4 needs |
| 9 | +the allowance `r = 1/100`: `48 + Row.peak / 100 < Row.lowerScore τ κ z`. The row, the |
| 10 | +quadrature and the variance bound are the accepted ones; only the rational cell test is |
| 11 | +rerun, with the larger cost and a finer list of cells near the left edge (ends `j/8` for |
| 12 | +`j ≤ 24`, then the integers `4, …, 50`): the cell `[3/2, 2]` of the accepted list fails at |
| 13 | +`r = 1/100`. |
| 14 | + |
| 15 | +The three private lemmas `moment`, `variance_le` and `integral_prefix` of |
| 16 | +`Erdos530Gap/WindowCertificate.lean` are used through `open private`, so the accepted file |
| 17 | +is not changed. |
| 18 | +-/ |
| 19 | + |
| 20 | +namespace ErdosSwarm.Erdos530Gap78.WindowMargin |
| 21 | + |
| 22 | +open ErdosSwarm.Erdos530Gap ErdosSwarm.Erdos530Gap.WindowQuadrature |
| 23 | + |
| 24 | +open private moment variance_le integral_prefix from ErdosSwarm.Erdos530Gap.WindowCertificate |
| 25 | + |
| 26 | +/-- The cost of `WindowQuadrature.cost` with the target `48 + peak / 100`. -/ |
| 27 | +def cost100 : ℚ := cost + 491 / 25 * (1 / 100 - 1 / 10000) |
| 28 | + |
| 29 | +theorem cost100_eq : |
| 30 | + (18785187 / 20000 + 54166941056067 / 16000000000 : ℝ) / 48 + |
| 31 | + Row.smoothingError + (48 + Row.peak / 100) = (cost100 : ℝ) := by |
| 32 | + have e : (cost100 : ℝ) = cost + 491 / 25 * (1 / 100 - 1 / 10000) := by |
| 33 | + rw [cost100]; push_cast; ring |
| 34 | + rw [e, ← cost_eq, Row.peak]; ring |
| 35 | + |
| 36 | +/-- Check the sign before squaring and a squared margin of at least `1`. -/ |
| 37 | +def good100 (a b : ℚ) (near : Bool) : Bool := |
| 38 | + let A := 99 / 100 * qMass a - cost100 |
| 39 | + let V := qSquares b - 2 * (99 / 100) / 48 * (if near then qOverlap a b else 0) |
| 40 | + decide (0 < A ∧ 2001 / 1000 * V + 1 ≤ A ^ 2) |
| 41 | + |
| 42 | +def ends100 : List ℚ := |
| 43 | + (List.range 24).map (fun j => ((j : ℚ) + 1) / 8) ++ (List.range 47).map (fun j => (j : ℚ) + 4) |
| 44 | + |
| 45 | +def chain100 (a : ℚ) : List ℚ → Bool |
| 46 | + | [] => decide (a = 50) |
| 47 | + | b::bs => decide (0 ≤ a ∧ a ≤ b ∧ b ≤ 50) && good100 a b true && chain100 b bs |
| 48 | + |
| 49 | +set_option maxHeartbeats 0 in |
| 50 | +set_option maxRecDepth 30000 in |
| 51 | +theorem all_cells100 : chain100 0 ends100 = true := by decide +kernel |
| 52 | + |
| 53 | +set_option maxHeartbeats 0 in |
| 54 | +theorem last_cell100 : good100 50 50 false = true := by decide +kernel |
| 55 | + |
| 56 | +lemma chain100_covers {t : ℝ} (ht : t < 50) (a : ℚ) (bs : List ℚ) |
| 57 | + (h : chain100 a bs = true) (ha : (a : ℝ) ≤ t) : |
| 58 | + ∃ i j : ℚ, 0 ≤ i ∧ i ≤ j ∧ j ≤ 50 ∧ i ≤ t ∧ t ≤ j ∧ good100 i j true = true := by |
| 59 | + induction bs generalizing a with |
| 60 | + | nil => |
| 61 | + simp [chain100] at h |
| 62 | + subst a |
| 63 | + norm_num at ha |
| 64 | + linarith |
| 65 | + | cons b bs ih => |
| 66 | + simp only [chain100, Bool.and_eq_true, decide_eq_true_eq] at h |
| 67 | + rcases h with ⟨⟨⟨ha₀, hab, hb⟩, hgood⟩, htail⟩ |
| 68 | + rcases le_or_gt t b with h | h |
| 69 | + · exact ⟨a, b, ha₀, hab, hb, ha, h, hgood⟩ |
| 70 | + · exact ih _ htail h.le |
| 71 | + |
| 72 | +theorem exists_cell100 {t : ℝ} (ht : 0 ≤ t) : |
| 73 | + ∃ (a b : ℚ) (near : Bool), 0 ≤ a ∧ b ≤ 50 ∧ (a : ℝ) ≤ min t 50 ∧ |
| 74 | + min t 50 ≤ b ∧ (near = true → t ≤ b) ∧ good100 a b near = true := by |
| 75 | + rcases lt_or_ge t 50 with ht' | ht' |
| 76 | + · obtain ⟨a, b, ha, _, hb, hat, htb, h⟩ := |
| 77 | + chain100_covers ht' 0 ends100 all_cells100 (by simpa using ht) |
| 78 | + exact ⟨a, b, true, ha, hb, by simpa [min_eq_left ht'.le] using hat, |
| 79 | + by simpa [min_eq_left ht'.le] using htb, fun _ => htb, h⟩ |
| 80 | + · exact ⟨50, 50, false, by norm_num, le_rfl, by simp [min_eq_right ht'], |
| 81 | + by simp [min_eq_right ht'], by simp, last_cell100⟩ |
| 82 | + |
| 83 | +theorem cell_inequalities100 {a b : ℚ} {near : Bool} (ha : 0 ≤ a) (hb : 0 ≤ b) |
| 84 | + (h : good100 a b near = true) : |
| 85 | + let A := 99 / 100 * mass a - (cost100 : ℝ) |
| 86 | + let V := squares b - 2 * (99 / 100) / 48 * (if near then overlap a b else 0) |
| 87 | + 0 < A ∧ 2001 / 1000 * V + 1 ≤ A ^ 2 := by |
| 88 | + simp only [good100, decide_eq_true_eq] at h |
| 89 | + cases near <;> simp only [Bool.false_eq_true, ↓reduceIte] at h ⊢ |
| 90 | + all_goals |
| 91 | + rw [← qMass_cast ha, ← qSquares_cast hb] |
| 92 | + try rw [← qOverlap_cast ha] |
| 93 | + exact ⟨by simpa using (Rat.cast_lt (K := ℝ)).mpr h.1, |
| 94 | + by simpa using (Rat.cast_le (K := ℝ)).mpr h.2⟩ |
| 95 | + |
| 96 | +/-- The five-window lower score exceeds the threshold with allowance `r = 1/100` at every |
| 97 | +position on the left half, uniformly for all deficits up to one percent. -/ |
| 98 | +theorem row_margin_100 {τ κ z : ℝ} (hτ : 0 < τ) (hτ' : τ ≤ 1 / 100) |
| 99 | + (hκ : 1 - τ ≤ κ) (hκ' : κ ≤ 1) (hz : 0 ≤ z) (hz' : z ≤ 1 / 2) : |
| 100 | + 48 + Row.peak / 100 < Row.lowerScore τ κ z := by |
| 101 | + have hκ₀ : (99 : ℝ) / 100 ≤ κ := by linarith |
| 102 | + have ht : 0 ≤ z / τ := div_nonneg hz hτ.le |
| 103 | + have hn : (100 : ℝ) ≤ 1 / τ := (le_div_iff₀ hτ).mpr (by linarith) |
| 104 | + have hspan : (50 : ℝ) ≤ 1 / τ - z / τ := by |
| 105 | + rw [← sub_div, le_div_iff₀ hτ]; linarith |
| 106 | + obtain ⟨a, b, near, ha, _, hat, htb, hnear, hgood⟩ := exists_cell100 ht |
| 107 | + have ha' : (0 : ℝ) ≤ a := by exact_mod_cast ha |
| 108 | + have hb' : 0 ≤ b := by exact_mod_cast (ha'.trans (hat.trans htb)) |
| 109 | + obtain ⟨hA, hV⟩ := cell_inequalities100 ha hb' hgood |
| 110 | + have hbound := variance_le hτ hκ₀ hκ' hn ht hspan ha' hat htb hnear |
| 111 | + have hm := moment ht hspan id continuous_id rfl |
| 112 | + have hI : mass a ≤ Row.integralKernel τ z := by |
| 113 | + rw [Row.integralKernel, rescale (fun _ w => w) hτ z] |
| 114 | + simp only [id_eq] at hm |
| 115 | + rw [hm, mass] |
| 116 | + exact add_le_add le_rfl (integral_prefix continuous_backward backward_nonneg ha' hat) |
| 117 | + have hI₀ : 0 ≤ mass a := add_nonneg |
| 118 | + (intervalIntegral.integral_nonneg_of_forall (by norm_num) forward_nonneg) |
| 119 | + (intervalIntegral.integral_nonneg_of_forall ha' backward_nonneg) |
| 120 | + have hmass : 99 / 100 * mass a ≤ κ * Row.integralKernel τ z := |
| 121 | + mul_le_mul hκ₀ hI hI₀ (by linarith) |
| 122 | + have hs : Real.sqrt (2001 / 1000 * Row.varianceBound τ κ z) < |
| 123 | + 99 / 100 * mass a - (cost100 : ℝ) := |
| 124 | + (Real.sqrt_lt' hA).mpr ((mul_le_mul_of_nonneg_left hbound (by norm_num)).trans_lt |
| 125 | + (lt_of_lt_of_le (lt_add_of_pos_right _ (by norm_num : (0 : ℝ) < 1)) hV)) |
| 126 | + unfold Row.lowerScore |
| 127 | + linarith only [hmass, hs, cost100_eq] |
| 128 | + |
| 129 | +end ErdosSwarm.Erdos530Gap78.WindowMargin |