| 1 | module |
| 2 | |
| 3 | public import E424.Input.Count |
| 4 | |
| 5 | @[expose] public section |
| 6 | |
| 7 | /-! |
| 8 | # Input, part 9: exact slopes `q ^ n`, and the interface used downstream |
| 9 | |
| 10 | `inputK` has the statement of `E424.inputK`, with `q` from this file. `lower_density` is `E424.L3`. |
| 11 | -/ |
| 12 | |
| 13 | set_option linter.style.header false |
| 14 | open Finset |
| 15 | |
| 16 | namespace E424.Inp |
| 17 | |
| 18 | /-- The base slope. -/ |
| 19 | def q : ℕ := 2 ^ 24 * 3 ^ 27 * 5 ^ 12 * 7 ^ 2 |
| 20 | |
| 21 | /-- Append `k` copies of a letter. -/ |
| 22 | theorem append_pow {a : ℕ} (ha : Letter a) (k : ℕ) : ∃ φ : ℕ → ℕ, Function.Injective φ ∧ |
| 23 | (0 < k → ∀ c, 0 < φ c) ∧ ∀ Q c, IsMap Q c → IsMap (a ^ k * Q) (φ c) := by |
| 24 | induction k with |
| 25 | | zero => exact ⟨id, Function.injective_id, by simp, fun Q c h => by simpa using h⟩ |
| 26 | | succ k ih => |
| 27 | obtain ⟨φ, hinj, -, hφ⟩ := ih |
| 28 | refine ⟨fun c => a * φ c + 1, fun c d h => ?_, fun _ c => Nat.succ_pos _, fun Q c h => ?_⟩ |
| 29 | · have h2 := ha.two_le |
| 30 | exact hinj (Nat.eq_of_mul_eq_mul_left (by omega) (Nat.succ_injective h)) |
| 31 | · have := (hφ Q c h).step ha |
| 32 | rwa [← mul_assoc, ← pow_succ'] at this |
| 33 | |
| 34 | /-- Append a fixed word that brings a near exponent vector to `n (24, 27, 12, 2)` exactly. -/ |
| 35 | theorem extend {B m : ℕ} (hB : 1 ≤ B) {ν : Ex} (hν : Near B m ν) : |
| 36 | ∃ φ : ℕ → ℕ, Function.Injective φ ∧ ∀ c, IsMap ν.slope c → |
| 37 | 0 < φ c ∧ IsMap (q ^ (m + B)) (φ c) := by |
| 38 | unfold Near at hν |
| 39 | obtain ⟨d7, e7⟩ : ∃ d, 2 * (m + B) = d + ν.e7 := ⟨2 * (m + B) - ν.e7, by omega⟩ |
| 40 | obtain ⟨d2, e2⟩ : ∃ d, 24 * (m + B) = d + d7 + ν.e2 := ⟨24 * (m + B) - d7 - ν.e2, by omega⟩ |
| 41 | obtain ⟨d3, e3⟩ : ∃ d, 27 * (m + B) = d + ν.e3 := ⟨27 * (m + B) - ν.e3, by omega⟩ |
| 42 | obtain ⟨d5, e5⟩ : ∃ d, 12 * (m + B) = d + ν.e5 := ⟨12 * (m + B) - ν.e5, by omega⟩ |
| 43 | obtain ⟨φ1, i1, -, p1⟩ := append_pow (a := 14) (by simp [Letter]) d7 |
| 44 | obtain ⟨φ2, i2, -, p2⟩ := append_pow (a := 2) (by simp [Letter]) d2 |
| 45 | obtain ⟨φ3, i3, -, p3⟩ := append_pow (a := 3) (by simp [Letter]) d3 |
| 46 | obtain ⟨φ4, i4, pos, p4⟩ := append_pow (a := 5) (by simp [Letter]) d5 |
| 47 | refine ⟨φ4 ∘ φ3 ∘ φ2 ∘ φ1, i4.comp (i3.comp (i2.comp i1)), fun c hc => |
| 48 | ⟨pos (by omega) _, ?_⟩⟩ |
| 49 | have hq : q ^ (m + B) = 5 ^ d5 * (3 ^ d3 * (2 ^ d2 * (14 ^ d7 * ν.slope))) := by |
| 50 | unfold q |
| 51 | simp only [mul_pow, ← pow_mul] |
| 52 | rw [e2, e3, e5, e7, show (14 : ℕ) = 2 * 7 by norm_num, mul_pow, Ex.slope] |
| 53 | simp only [pow_add] |
| 54 | ring |
| 55 | rw [hq] |
| 56 | exact p4 _ _ (p3 _ _ (p2 _ _ (p1 _ _ hc))) |
| 57 | |
| 58 | /-- The appended slope is bounded. -/ |
| 59 | theorem slope_ge {B m : ℕ} {ν : Ex} (hν : Near B m ν) : |
| 60 | q ^ (m + B) ≤ q ^ B * 210 ^ B * ν.slope := by |
| 61 | unfold Near at hν |
| 62 | have h210 : 210 ^ B = 2 ^ B * 3 ^ B * 5 ^ B * 7 ^ B := by simp only [← mul_pow]; norm_num |
| 63 | have hqm : q ^ m = 2 ^ (24 * m) * 3 ^ (27 * m) * 5 ^ (12 * m) * 7 ^ (2 * m) := by |
| 64 | unfold q; simp only [mul_pow, ← pow_mul] |
| 65 | have h2 : 2 ^ (24 * m) ≤ 2 ^ (B + ν.e2) := Nat.pow_le_pow_right (by norm_num) (by omega) |
| 66 | have h3 : 3 ^ (27 * m) ≤ 3 ^ (B + ν.e3) := Nat.pow_le_pow_right (by norm_num) (by omega) |
| 67 | have h5 : 5 ^ (12 * m) ≤ 5 ^ (B + ν.e5) := Nat.pow_le_pow_right (by norm_num) (by omega) |
| 68 | have h7 : 7 ^ (2 * m) ≤ 7 ^ (B + ν.e7) := Nat.pow_le_pow_right (by norm_num) (by omega) |
| 69 | have h : q ^ m ≤ 210 ^ B * ν.slope := by |
| 70 | rw [hqm] |
| 71 | refine (Nat.mul_le_mul (Nat.mul_le_mul (Nat.mul_le_mul h2 h3) h5) h7).trans (le_of_eq ?_) |
| 72 | rw [h210, Ex.slope] |
| 73 | simp only [pow_add] |
| 74 | ring |
| 75 | calc q ^ (m + B) = q ^ B * q ^ m := by rw [pow_add, mul_comm] |
| 76 | _ ≤ q ^ B * (210 ^ B * ν.slope) := Nat.mul_le_mul_left _ h |
| 77 | _ = _ := by ring |
| 78 | |
| 79 | /-- **Input K.** -/ |
| 80 | theorem inputK : ∃ κ > (0 : ℝ), κ ≤ 1 ∧ ∃ K : ℕ, ∀ M : ℕ, 0 < M → ∃ n, M ≤ n ∧ n ≤ M + K ∧ |
| 81 | ∃ 𝒞 : Finset ℕ, κ * (q ^ n : ℕ) ≤ 𝒞.card ∧ ∀ c ∈ 𝒞, 0 < c ∧ c < q ^ n ∧ |
| 82 | ∀ x ∈ genSet, 14 < x → q ^ n * x - c ∈ genSet := by |
| 83 | obtain ⟨B, hB, κ, hκ, h⟩ := exists_dense |
| 84 | have hq0 : (0 : ℝ) < ((q ^ B * 210 ^ B : ℕ) : ℝ) := by |
| 85 | have : 0 < q ^ B * 210 ^ B := by unfold q; positivity |
| 86 | exact_mod_cast this |
| 87 | refine ⟨min 1 (κ / (q ^ B * 210 ^ B : ℕ)), lt_min one_pos (div_pos hκ hq0), min_le_left _ _, B, |
| 88 | fun M _ => ⟨M + B, by omega, le_rfl, ?_⟩⟩ |
| 89 | obtain ⟨ν, hν, S, hS, hmap⟩ := h M |
| 90 | obtain ⟨φ, hinj, hφ⟩ := extend hB hν |
| 91 | refine ⟨S.image φ, ?_, fun c hc => ?_⟩ |
| 92 | · rw [card_image_of_injective _ hinj] |
| 93 | have h1 : ((q ^ (M + B) : ℕ) : ℝ) ≤ ((q ^ B * 210 ^ B : ℕ) : ℝ) * ν.slope := by |
| 94 | exact_mod_cast slope_ge hν |
| 95 | calc min 1 (κ / (q ^ B * 210 ^ B : ℕ)) * ((q ^ (M + B) : ℕ) : ℝ) |
| 96 | ≤ κ / (q ^ B * 210 ^ B : ℕ) * (((q ^ B * 210 ^ B : ℕ) : ℝ) * ν.slope) := |
| 97 | mul_le_mul (min_le_right _ _) h1 (Nat.cast_nonneg _) (div_pos hκ hq0).le |
| 98 | _ = κ * ν.slope := by field_simp |
| 99 | _ ≤ S.card := hS |
| 100 | · obtain ⟨d, hd, rfl⟩ := mem_image.1 hc |
| 101 | obtain ⟨hpos, hm⟩ := hφ d (hmap d hd) |
| 102 | refine ⟨hpos, hm.1, fun x hx h14 => ?_⟩ |
| 103 | rw [mem_iff] at hx ⊢ |
| 104 | exact (hm.2 x hx h14).1 |
| 105 | |
| 106 | open Classical in |
| 107 | /-- **Positive lower density** (from `inputK` at `x = 17`); the counting form of `E424.L3`. -/ |
| 108 | theorem lower_density : ∃ α > (0 : ℝ), α ≤ 1 ∧ ∃ x0 ≥ (1 : ℝ), ∀ x ≥ x0, |
| 109 | α * x ≤ ((Ioc ⌊(0 : ℝ)⌋₊ ⌊x⌋₊).filter (· ∈ genSet)).card := by |
| 110 | obtain ⟨κ, hκ, hκ1, K, hK⟩ := inputK |
| 111 | have hq2 : 2 ≤ q := by norm_num [q] |
| 112 | have hqR : (1 : ℝ) < q := by exact_mod_cast (by omega : 1 < q) |
| 113 | have hq0 : (0 : ℝ) < (q : ℝ) ^ (K + 1) := by positivity |
| 114 | refine ⟨κ / (17 * q ^ (K + 1)), by positivity, ?_, 17 * q ^ (K + 1), ?_, fun x hx => ?_⟩ |
| 115 | · rw [div_le_one (by positivity)] |
| 116 | have := one_le_pow₀ hqR.le (n := K + 1) |
| 117 | linarith |
| 118 | · have := one_le_pow₀ hqR.le (n := K + 1) |
| 119 | linarith |
| 120 | -- `17 q^(t+K) ≤ x < 17 q^(t+K+1)` |
| 121 | have hx1 : (1 : ℝ) ≤ x / (17 * q ^ K) := by |
| 122 | rw [one_le_div (by positivity)] |
| 123 | refine le_trans ?_ hx |
| 124 | rw [pow_succ] |
| 125 | have : (0 : ℝ) < (q : ℝ) ^ K := by positivity |
| 126 | nlinarith |
| 127 | obtain ⟨t, ht1, ht2⟩ := exists_nat_pow_near hx1 hqR |
| 128 | have ht0 : 0 < t := by |
| 129 | rcases Nat.eq_zero_or_pos t with rfl | h |
| 130 | · exfalso |
| 131 | rw [zero_add, pow_one, div_lt_iff₀ (by positivity)] at ht2 |
| 132 | rw [ge_iff_le, pow_succ] at hx |
| 133 | linarith |
| 134 | · exact h |
| 135 | obtain ⟨n, hn1, hn2, 𝒞, hc, h𝒞⟩ := hK t ht0 |
| 136 | have hmem : ∀ c ∈ 𝒞, q ^ n * 17 - c ∈ |
| 137 | (Ioc ⌊(0 : ℝ)⌋₊ ⌊x⌋₊).filter (· ∈ genSet) := by |
| 138 | intro c hcm |
| 139 | obtain ⟨h0, h1, h2⟩ := h𝒞 c hcm |
| 140 | have hA := h2 17 ((mem_iff 17).2 Gen.seventeen) (by norm_num) |
| 141 | rw [mem_filter, mem_Ioc, Nat.floor_zero] |
| 142 | refine ⟨⟨by omega, Nat.le_floor ?_⟩, hA⟩ |
| 143 | rw [le_div_iff₀ (by positivity)] at ht1 |
| 144 | have h3 : ((q ^ n * 17 - c : ℕ) : ℝ) ≤ ((q ^ n * 17 : ℕ) : ℝ) := by |
| 145 | exact_mod_cast Nat.sub_le _ _ |
| 146 | have h4 : (q : ℝ) ^ n ≤ q ^ (t + K) := pow_le_pow_right₀ hqR.le hn2 |
| 147 | rw [pow_add] at h4 |
| 148 | push_cast at h3 |
| 149 | nlinarith |
| 150 | have hinj : Set.InjOn (fun c => q ^ n * 17 - c) (𝒞 : Set ℕ) := by |
| 151 | intro c hc d hd h |
| 152 | have h1 := (h𝒞 c hc).2.1 |
| 153 | have h2 := (h𝒞 d hd).2.1 |
| 154 | simp only at h |
| 155 | omega |
| 156 | have hcard := card_le_card_of_injOn _ hmem hinj |
| 157 | have hcard' : (𝒞.card : ℝ) ≤ |
| 158 | ((Ioc ⌊(0 : ℝ)⌋₊ ⌊x⌋₊).filter (· ∈ genSet)).card := by exact_mod_cast hcard |
| 159 | refine le_trans ?_ hcard' |
| 160 | refine le_trans ?_ hc |
| 161 | rw [div_lt_iff₀ (by positivity)] at ht2 |
| 162 | have h5 : (q : ℝ) ^ t ≤ q ^ n := pow_le_pow_right₀ hqR.le hn1 |
| 163 | rw [div_mul_eq_mul_div, div_le_iff₀ (by positivity)] |
| 164 | push_cast |
| 165 | have h6 : x ≤ q ^ n * (17 * q ^ (K + 1)) := by |
| 166 | calc x ≤ q ^ (t + 1) * (17 * q ^ K) := ht2.le |
| 167 | _ = q ^ t * (17 * q ^ (K + 1)) := by ring |
| 168 | _ ≤ _ := by gcongr |
| 169 | nlinarith [mul_le_mul_of_nonneg_left h6 hκ.le] |
| 170 | |
| 171 | end E424.Inp |
| 172 | |