| | @@ -0,0 +1,87 @@ |
| 1 | +import ErdosSwarm.Erdos530Gap75.Alloc32Table |
| 2 | +import ErdosSwarm.Erdos530Gap75.Data |
| 3 | + |
| 4 | +/-! |
| 5 | +# The published R = 32 allocation for the 74/75 grid |
| 6 | + |
| 7 | +`alloc32Num` computes the integer numerator of formula (5)'s height in |
| 8 | +`experiments/erdos530/upper-smaller-k3/NOTES.md`, §2. The allocation is zero outside |
| 9 | +the table domain `0 ≤ i ≤ l ≤ 512`. |
| 10 | +-/ |
| 11 | + |
| 12 | +namespace ErdosSwarm.Erdos530Gap75 |
| 13 | + |
| 14 | +/-- The six magnitude bands begin at 0, 12, 24, 40, 56 and 80. The first row |
| 15 | +in each band is for nonpositive displacements, including zero. -/ |
| 16 | +def alloc32Band (d : ℤ) : ℕ := |
| 17 | + let n := d.natAbs |
| 18 | + let b := if n < 12 then 0 else if n < 24 then 1 else if n < 40 then 2 |
| 19 | + else if n < 56 then 3 else if n < 80 then 4 else 5 |
| 20 | + 2 * b + if 0 < d then 1 else 0 |
| 21 | + |
| 22 | +theorem alloc32Band_of_large {d : ℤ} (h : 80 ≤ d.natAbs) : |
| 23 | + alloc32Band d = 10 + if 0 < d then 1 else 0 := by |
| 24 | + dsimp only [alloc32Band] |
| 25 | + split_ifs <;> omega |
| 26 | + |
| 27 | +/-- The allocation entry for an overlap, in the order used by the grid certificate. -/ |
| 28 | +def alloc32Row? (l : ℕ) : Option Alloc32Row := |
| 29 | + alloc32Rows.find? fun row => decide (row.lo ≤ l ∧ l ≤ row.hi) |
| 30 | + |
| 31 | +/-- Every grid overlap has a table entry. -/ |
| 32 | +theorem alloc32Row?_isSome {l : ℕ} (hl : l ≤ 512) : (alloc32Row? l).isSome := by |
| 33 | + have h : ∀ l < 513, (alloc32Row? l).isSome = true := by decide +kernel |
| 34 | + exact h l (Nat.lt_succ_of_le hl) |
| 35 | + |
| 36 | +/-- A certificate block using this row can select it by the two endpoint inequalities. -/ |
| 37 | +theorem alloc32Row?_of_mem {l : ℕ} {row : Alloc32Row} (hr : row ∈ alloc32Rows) |
| 38 | + (hlo : row.lo ≤ l) (hhi : l ≤ row.hi) : alloc32Row? l = some row := by |
| 39 | + have ordered : alloc32Rows.Pairwise (fun a b => a.hi < b.lo) := by decide +kernel |
| 40 | + unfold alloc32Row? |
| 41 | + generalize alloc32Rows = rows at hr ordered ⊢ |
| 42 | + induction rows with |
| 43 | + | nil => simp at hr |
| 44 | + | cons a rest ih => |
| 45 | + obtain ⟨prior, later⟩ := List.pairwise_cons.mp ordered |
| 46 | + rcases List.mem_cons.mp hr with rfl | hrest |
| 47 | + · simp [hlo, hhi] |
| 48 | + · have := prior row hrest |
| 49 | + have h : ¬ l ≤ a.hi := by omega |
| 50 | + simpa [List.find?_cons, h] using ih hrest later |
| 51 | + |
| 52 | +private def alloc32BandHeight (l : ℕ) (i : ℤ) (band : ℕ) : Fin 16385 := |
| 53 | + if 0 ≤ i ∧ i ≤ (l : ℤ) then |
| 54 | + match alloc32Row? l with |
| 55 | + | some row => row.height band i.toNat (l - i.toNat) |
| 56 | + | none => 0 |
| 57 | + else 0 |
| 58 | + |
| 59 | +/-- Integer numerator of `P_l(i,d)`, in units of `1/16384`. -/ |
| 60 | +def alloc32Num (l : ℕ) (i d : ℤ) : ℕ := |
| 61 | + (alloc32BandHeight l i (alloc32Band d)).val |
| 62 | + |
| 63 | +theorem alloc32Num_le (l : ℕ) (i d : ℤ) : alloc32Num l i d ≤ 16384 := |
| 64 | + Nat.le_of_lt_succ (alloc32BandHeight l i (alloc32Band d)).isLt |
| 65 | + |
| 66 | +theorem alloc32Num_of_row {l : ℕ} {i d : ℤ} {row : Alloc32Row} |
| 67 | + (h : alloc32Row? l = some row) (h₀ : 0 ≤ i) (h₁ : i ≤ (l : ℤ)) : |
| 68 | + alloc32Num l i d = (row.height (alloc32Band d) i.toNat (l - i.toNat)).val := by |
| 69 | + simp [alloc32Num, alloc32BandHeight, h, h₀, h₁] |
| 70 | + |
| 71 | +theorem alloc32Num_congr_band (l : ℕ) (i : ℤ) {d d' : ℤ} |
| 72 | + (h : alloc32Band d = alloc32Band d') : alloc32Num l i d = alloc32Num l i d' := by |
| 73 | + simp only [alloc32Num, h] |
| 74 | + |
| 75 | +/-- The allocation used by the published coupled-shift grid certificate. -/ |
| 76 | +noncomputable def alloc32 : Allocation where |
| 77 | + height l i d := (alloc32Num l i d : ℝ) / 16384 |
| 78 | + mem l i d := by |
| 79 | + constructor |
| 80 | + · positivity |
| 81 | + · apply (div_le_one (by norm_num : (0 : ℝ) < 16384)).2 |
| 82 | + exact_mod_cast alloc32Num_le l i d |
| 83 | + |
| 84 | +@[simp] theorem alloc32_height (l : ℕ) (i d : ℤ) : |
| 85 | + alloc32.height l i d = (alloc32Num l i d : ℝ) / 16384 := rfl |
| 86 | + |
| 87 | +end ErdosSwarm.Erdos530Gap75 |