| | @@ -0,0 +1,146 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap.Row |
| 2 | + |
| 3 | +/-! |
| 4 | +# The 1/135 covering row and deletion parameters for Erdős #530 |
| 5 | + |
| 6 | +The kernels, cut probabilities, grid ordinates and dyadic charges are those of |
| 7 | +§§1–4 of `experiments/erdos530/upper-smaller-k/NOTES.md`. The rational and real |
| 8 | +calculations share the same tent and envelope definitions. |
| 9 | +-/ |
| 10 | + |
| 11 | +namespace ErdosSwarm.Erdos530Gap428 |
| 12 | + |
| 13 | +open Finset ErdosSwarm.Erdos530Gap |
| 14 | + |
| 15 | +noncomputable section |
| 16 | + |
| 17 | +def sigma : ℝ := 1 / 135 |
| 18 | +def s : ℚ := 3689 / 100 |
| 19 | +def K : ℝ := 359 / 10 |
| 20 | +def scale (M : ℕ) : ℝ := sigma * Real.sqrt M |
| 21 | +def pos (M x : ℕ) : ℝ := 135 * Row.position M x |
| 22 | + |
| 23 | +/-- Width in mesh steps, forward height, reverse height. One step is 1/28. |
| 24 | +The last tent has total height 298 · 28 and forward share 13/25. -/ |
| 25 | +def windows : List (ℕ × ℚ × ℚ) := |
| 26 | + [(1344, 134/100, 0), (672, 671/100, 2/100), (336, 1270/100, 348/100), |
| 27 | + (168, 2337/100, 169/100), (84, 2961/100, 719/100), (42, 3175/100, 2420/100), |
| 28 | + (14, 709/100, 376/100), (1, 298 * 28 * 13/25, 298 * 28 * 12/25)] |
| 29 | + |
| 30 | +section OrderedField |
| 31 | + |
| 32 | +variable {F : Type*} [Field F] [LinearOrder F] [IsStrictOrderedRing F] |
| 33 | + |
| 34 | +def weight (forward : Bool) (v : F) : F := |
| 35 | + (windows.map fun (d, p, n) => |
| 36 | + ((if forward then p else n : ℚ) : F) * max (1 - 28 * |v| / d) 0).sum |
| 37 | + |
| 38 | +def W (v : F) : F := weight true v + weight false v |
| 39 | + |
| 40 | +/-- All weights in this row lie in [0, 89029/20]. A minimizing positive |
| 41 | +integer is at most 67. Keeping the first 135 lines gives the same envelope |
| 42 | +and works over both ℚ and ℝ. -/ |
| 43 | +def envelope (w : F) : F := |
| 44 | + (univ : Finset (Fin 135)).inf' univ_nonempty fun j => |
| 45 | + ((j.val : F) + w / (j.val + 1 : F)) |
| 46 | + |
| 47 | +def g (forward : Bool) (v : F) : F := envelope (weight forward v) |
| 48 | + |
| 49 | +/-- Distribution function of a uniform cut on [19,116], extended to the line. -/ |
| 50 | +def cdf (u : F) : F := min 1 (max 0 ((u - 19) / 97)) |
| 51 | + |
| 52 | +end OrderedField |
| 53 | + |
| 54 | +/-- The peak is the forward envelope at zero, attained by the line with |
| 55 | +positive index 67. The reverse peak is 403873/3200. -/ |
| 56 | +def peak : ℚ := 177469 / 1340 |
| 57 | + |
| 58 | +def centerWeight : ℚ := W (0 : ℚ) |
| 59 | + |
| 60 | +/-- Integral over the whole real line of the even kernel W. -/ |
| 61 | +def area : ℚ := (windows.map fun (d, p, n) => (p + n) * (d : ℚ) / 28).sum |
| 62 | + |
| 63 | +/-- Expected score of one witness. Points tested by the counting lemma are outside S. -/ |
| 64 | +def localScore (t y : ℝ) : ℝ := |
| 65 | + if t < y then |
| 66 | + (1 - (cdf t + cdf y) / 2) * g true (y - t) + cdf t * g false (y - t) |
| 67 | + else if y < t then |
| 68 | + (cdf t + cdf y) / 2 * g true (t - y) + (1 - cdf t) * g false (t - y) |
| 69 | + else 0 |
| 70 | + |
| 71 | +def score (M : ℕ) (S : Finset ℕ) (x : ℕ) : ℝ := |
| 72 | + ∑ a ∈ S, localScore (pos M x) (pos M a) |
| 73 | + |
| 74 | +def missing (M : ℕ) (S : Finset ℕ) : ℝ := |
| 75 | + ∑ d ∈ (host M).filter (fun d => differenceStarts S d = ∅), W (135 * (d : ℝ) / M) |
| 76 | + |
| 77 | +def shifts (S : Finset ℕ) (left : ℕ → Bool) (free : Bool) (x : ℕ) : Finset ℤ := |
| 78 | + (S.filter (fun a => left x = free ∨ left a = left x)).image fun a : ℕ => |
| 79 | + if left x then (a : ℤ) - x else (x : ℤ) - a |
| 80 | + |
| 81 | +def seedEnergy (S : Finset ℕ) (y : ℕ → ℝ) (b : ℝ) : ℝ := |
| 82 | + (∑ a ∈ S, ∑ k ∈ S, W (y a - y k)) / b ^ 2 |
| 83 | + |
| 84 | +abbrev Cell := Fin 1891 |
| 85 | +abbrev Node := Fin 3782 |
| 86 | + |
| 87 | +def node (j : Node) : ℚ := (j.val : ℚ) / 28 |
| 88 | +def charge (a : Node → ℤ) (j : Node) : ℚ := (a j : ℚ) / 2 ^ 20 |
| 89 | + |
| 90 | +def gridPotential (a : Node → ℤ) (j : Node) : ℚ := |
| 91 | + ∑ k : Node, charge a k * W (node j - node k) |
| 92 | + |
| 93 | +def gridEnergy (a : Node → ℤ) : ℚ := ∑ j : Node, charge a j * gridPotential a j |
| 94 | + |
| 95 | +def potential (a : Node → ℤ) (y : ℝ) : ℝ := |
| 96 | + ∑ k : Node, (charge a k : ℝ) * W (y - (node k : ℝ)) |
| 97 | + |
| 98 | +/-- A downward rounding to multiples of 2⁻²⁰. The two successive roundings |
| 99 | +in `ordinate` implement the floors in `scores` and `node_bounds`. -/ |
| 100 | +def roundDown (x : ℚ) : ℚ := (⌊(2 ^ 20 : ℚ) * x⌋ : ℤ) / (2 ^ 20 : ℚ) |
| 101 | + |
| 102 | +def ordinate (i : Cell) (j : Node) : ℚ := |
| 103 | + let t := (i.val : ℚ) / 28 |
| 104 | + let y := node j |
| 105 | + let p := roundDown (s * g true (y - t)) |
| 106 | + let n := roundDown (s * g false (y - t)) |
| 107 | + let low := cdf (t - 1/28) |
| 108 | + let high := cdf t |
| 109 | + let right := (1 - (high + cdf (y + 1/28)) / 2) * p + low * n |
| 110 | + let left := (low + cdf (y - 2/28)) / 2 * p + (1 - high) * n |
| 111 | + roundDown (if i.val < j.val then right else if j.val < i.val then left else min left right) |
| 112 | + |
| 113 | +/-- Reflect the right half and translate to put the center at i/28. -/ |
| 114 | +def shifted (t : ℝ) (i : Cell) (y : ℝ) : ℝ := |
| 115 | + (i.val : ℝ) / 28 + (if t ≤ 135/2 then y - t else t - y) |
| 116 | + |
| 117 | +/-- Prefix arrays have an initial zero and one entry after each node. -/ |
| 118 | +abbrev PrefixIndex := Fin 3783 |
| 119 | + |
| 120 | +def clipped (P : PrefixIndex → ℤ) (n : ℕ) : ℤ := |
| 121 | + P ⟨min n 3782, Nat.lt_succ_of_le (min_le_right _ _)⟩ |
| 122 | + |
| 123 | +/-- Sum (d - |j-k|)₊ aₖ by splitting the support at j. Natural subtraction |
| 124 | +clips the left endpoint at zero. All coefficients of the prefixes are signed. -/ |
| 125 | +def tentSum (P H : ℕ → ℤ) (d j : ℕ) : ℤ := |
| 126 | + let l := j + 1 - d |
| 127 | + let m := j + 1 |
| 128 | + let r := j + d |
| 129 | + ((d : ℤ) - j) * (P m - P l) + (H m - H l) + |
| 130 | + ((d : ℤ) + j) * (P r - P m) - (H r - H m) |
| 131 | + |
| 132 | +def prefixPotential (P H : PrefixIndex → ℤ) (j : Node) : ℚ := |
| 133 | + (windows.map fun (d, p, n) => |
| 134 | + (p + n) * (tentSum (clipped P) (clipped H) d j.val : ℚ) / ((d : ℚ) * 2 ^ 20)).sum |
| 135 | + |
| 136 | +def gap : ℝ := 3 / 100000 |
| 137 | +def tail : ℝ := 1 / 50000 |
| 138 | +def reserve : ℝ := 1 / 10 ^ 11 |
| 139 | +def eta : ℝ := 1 / 10 ^ 8 |
| 140 | +def delta : unitInterval := ⟨20081 / 1982000, by constructor <;> norm_num⟩ |
| 141 | +def keep : ℝ := 1 - (delta : ℝ) - eta |
| 142 | +def host428 (N : ℕ) : ℕ := ⌊(N : ℝ) / keep⌋₊ |
| 143 | + |
| 144 | +end |
| 145 | + |
| 146 | +end ErdosSwarm.Erdos530Gap428 |