AFTD Auto-Formalizing Theoretical Domains

op2468_blackburn_stability_lower_bound_eventually

theoremverifiedoriginal

For an integer n >= 2, let lambda = (n - 1) / n, c_n = lambda^(n - 1) / n, and K_n = 2 * sqrt(2 / (n - 1)) * lambda^((n + 1) / 2). With non-overlapping codes, optimal Blackburn codes (I^(n-1) J and J I^(n-1) with |I| = lambda q), code_dist the normalized symmetric-difference distance to the nearest optimal Blackburn code, max_dist q epsilon its supremum over non-overlapping codes of size at least (c_n - epsilon) q^n, and M epsilon the limsup over q = m n of max_dist, the liminf of M epsilon / sqrt epsilon as epsilon tends to 0 from above is at least K_n (in the extended reals): for every eta > 0, eventually as epsilon tends to 0 from above, (K_n - eta) sqrt epsilon <= M epsilon.

Statement

theorem op2468_blackburn_stability_lower_bound_eventually (n : ℕ) (hn : 2 ≤ n) :
    let lam : ℝ := (n - 1 : ℝ) / n
    let c_n : ℝ := lam ^ (n - 1) / (n : ℝ)
    let K_n : ℝ := 2 * Real.sqrt (2 / (n - 1 : ℝ)) * lam ^ (((n : ℝ) + 1) / 2)
    let is_nonoverlapping (q : ℕ) (C : Finset (Fin n → Fin q)) : Prop :=
      ∀ u ∈ C, ∀ v ∈ C, ¬ ∃ (k : ℕ) (_ : 0 < k) (_ : k < n),
        ∀ i : Fin k, u ⟨i.val, by omega⟩ = v ⟨n - k + i.val, by omega⟩
    let optimal_blackburn (q : ℕ) : Set (Finset (Fin n → Fin q)) :=
      { B | ∃ (I : Finset (Fin q)), n * I.card = (n - 1) * q ∧
        (B = Finset.filter (fun w => (∀ (i : Fin n), i.val < n - 1 → w i ∈ I) ∧
          w ⟨n - 1, by omega⟩ ∉ I) Finset.univ ∨
         B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧
          (∀ (i : Fin n), 0 < i.val → w i ∈ I)) Finset.univ) }
    let code_dist (q : ℕ) (C : Finset (Fin n → Fin q)) : ℝ :=
      sInf { ((symmDiff C B).card : ℝ) / (q : ℝ) ^ n | B ∈ optimal_blackburn q }
    let max_dist (q : ℕ) (ε : ℝ) : ℝ :=
      sSup { d | ∃ C : Finset (Fin n → Fin q),
        is_nonoverlapping q C ∧ (c_n - ε) * (q : ℝ) ^ n ≤ C.card ∧ d = code_dist q C }
    let M (ε : ℝ) : ℝ :=
      Filter.limsup (fun m : ℕ => max_dist (m * n) ε) Filter.atTop
    ∀ η : ℝ, 0 < η → ∀ᶠ ε in nhdsWithin (0 : ℝ) (Set.Ioi 0), (K_n - η) * Real.sqrt ε ≤ M ε
Related work
OP-2468 (proposed here, building on the theorem that optimal Blackburn codes attain the maximum size of non-overlapping codes): the lower-bound half of the conjectured stability modulus K_n, via perturbed Blackburn codes. Faithful restatement of the retired op2468_blackburn_stability_lower_bound, whose real-valued liminf also forced an upper bound.
Verified
29 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 2
  • TotalPreorderA total preorder: a preorder where ≤ is total (complete). This is weaker than LinearOrder — it does NOT require antisymmetry or…
  • LinearOrder.toTotalPreorderEvery LinearOrder is a TotalPreorder.

Read back from the Lean

For any natural number $n \ge 2$: Define the constants: * $\lambda = \frac{n - 1}{n}$, * $c_n = \frac{\lambda^{n-1}}{n}$, * $K_n = 2 \sqrt{\frac{2}{n - 1}} \lambda^{(n + 1)/2}$. For an alphabet size $q \in \mathbb{N}$ and code length $n$, define: * A code $C \subseteq (\mathrm{Fin}\,n \to \mathrm{Fin}\,q)$ is **non-overlapping** (is_nonoverlapping q C) if for all $u, v \in C$, there is no integer $k$ with $0 < k < n$ such that the length-$k$ prefix of $u$ equals the length-$k$ suffix of $v$ (that is, $\forall i \in \{0, \dots, k-1\}, u(i) = v(n - k + i)$). * The set of **optimal Blackburn codes** (optimal_blackburn q) consists of codes $B \subseteq (\mathrm{Fin}\,n \to \mathrm{Fin}\,q)$ for which there exists a subset $I \subseteq \mathrm{Fin}\,q$ with $n |I| = (n - 1) q$ such that either: 1. $B = \{w \mid (\forall i < n - 1, w(i) \in I) \wedge w(n-1) \notin I\}$, or 2. $B = \{w \mid w(0) \notin I \wedge (\forall i > 0, w(i) \in I)\}$. * For a code $C$, its normalized distance to the optimal Blackburn codes is $\mathrm{code\_dist}(q, C) = \inf \{ \frac{|C \mathbin{\triangle} B|}{q^n} \mid B \in \mathrm{optimal\_blackburn}(q) \}$, where $\triangle$ denotes symmetric difference. * For $\varepsilon \in \mathbb{R}$, $\mathrm{max\_dist}(q, \varepsilon)$ is the supremum of $\mathrm{code\_dist}(q, C)$ over all non-overlapping codes $C \subseteq (\mathrm{Fin}\,n \to \mathrm{Fin}\,q)$ with cardinality $|C| \ge (c_n - \varepsilon) q^n$. * $M(\varepsilon) = \limsup_{m \to \infty} \mathrm{max\_dist}(m \cdot n, \varepsilon)$. Then the theorem asserts: For every $\eta > 0$, for all sufficiently small $\varepsilon > 0$ (i.e., eventually in the right-neighborhood filter of $0$, $\mathcal{N}_{(0, \infty)}(0)$): $$(K_n - \eta) \sqrt{\varepsilon} \le M(\varepsilon)$$

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The theorem establishes a sharp lower bound on the stability of Blackburn's theorem for non-overlapping codes: as the size defect ε tends to 0 from above, the asymptotic normalized distance M(ε) to the nearest optimal Blackburn code satisfies M(ε) ≥ (K_n - η) √ε eventually, where K_n = 2 √(2 / (n - 1)) ((n - 1) / n)^((n + 1) / 2). The argument works by perturbing the alphabet partition in Blackburn's optimal code: instead of taking a set of size λ q = N m, one takes S of size N m + x with x ≈ θ √ε N m, forming the code C = S^N × Sᶜ. A truncated binomial expansion keeps the size defect below ε q^n while pushing the distance to any optimal Blackburn code up by at least (2 c_n N θ - O(1/m)) √ε - ε. Taking the limsup over m → ∞ eliminates the alphabet discretization error O(1/m), and choosing θ ≈ K_n / (2 c_n N) achieves the constant K_n via the algebraic identity K_n^2 (N + 1) = 8 c_n N.

  1. The Cartesian product of N + 1 finite sets where the first N have size at most a and the last has size at most c has cardinality at most a^N * c.

    By rewriting the cardinality of the product of finite sets as the product of their individual cardinalities, we factor out the last term (Fin.last N) and bound the remaining N factors by a and the final factor by c.

    lines 1–8

    uses Fintype.card_piFinset, Fin.prod_univ_castSucc, Nat.mul_le_mul, Finset.prod_le_prod

    lemma in1284_pi_card_le {N q : ℕ} (A : Fin (N+1) → Finset (Fin q)) (a c : ℕ)
        (h1 : ∀ i : Fin N, (A i.castSucc).card ≤ a) (h2 : (A (Fin.last N)).card ≤ c) :
        (Fintype.piFinset A).card ≤ a ^ N * c := by
      rw [Fintype.card_piFinset, Fin.prod_univ_castSucc]
      apply Nat.mul_le_mul _ h2
      calc ∏ i : Fin N, (A i.castSucc).card ≤ ∏ _i : Fin N, a :=
            Finset.prod_le_prod (fun i _ => Nat.zero_le _) (fun i _ => h1 i)
        _ = a ^ N := by simp
  2. The Cartesian product of N sets of size a followed by one set of size c has cardinality exactly a^N * c.

    Splitting the product of cardinalities over Fin (N + 1) into the product over the first N coordinates and the final coordinate, then substituting the exact sizes, gives a^N * c.

    lines 9–15

    uses Fintype.card_piFinset, Fin.prod_univ_castSucc

    lemma in1284_pi_card_eq {N q : ℕ} (A : Fin (N+1) → Finset (Fin q)) (a c : ℕ)
        (h1 : ∀ i : Fin N, (A i.castSucc).card = a) (h2 : (A (Fin.last N)).card = c) :
        (Fintype.piFinset A).card = a ^ N * c := by
      rw [Fintype.card_piFinset, Fin.prod_univ_castSucc]
      simp [h1, h2]
    
  3. The Cartesian product of one set of size c followed by N sets of size a has cardinality exactly c * a^N.

    Splitting the product of cardinalities at index 0 and evaluating the remaining N factors of size a yields c * a^N.

    lines 16–21

    uses Fintype.card_piFinset, Fin.prod_univ_succ

    lemma in1284_pi_card_eq' {N q : ℕ} (A : Fin (N+1) → Finset (Fin q)) (a c : ℕ)
        (h1 : (A 0).card = c) (h2 : ∀ i : Fin N, (A i.succ).card = a) :
        (Fintype.piFinset A).card = c * a ^ N := by
      rw [Fintype.card_piFinset, Fin.prod_univ_succ]
      simp [h1, h2]
    
  4. For all u ≥ 0 and N ∈ ℕ, 1 + N * u + (N * (N - 1) / 2) * u^2 ≤ (1 + u)^N.

    By induction on N. The base case N = 0 is immediate (1 ≤ 1). For the inductive step, multiplying the hypothesis by 1 + u ≥ 0 gives (1 + u)^(k + 1) ≥ (1 + k * u + (k * (k - 1) / 2) * u^2) * (1 + u) = 1 + (k + 1) * u + ((k + 1) * k / 2) * u^2 + (k * (k - 1) / 2) * u^3. Since u ≥ 0 and k ≥ 0, the cubic term is non-negative, and nonlinear arithmetic establishes the claim.

    lines 22–37

    uses pow_succ, Nat.eq_zero_or_pos, mul_le_mul_of_nonneg_right

    lemma in1284_binom (N : ℕ) (u : ℝ) (hu : 0 ≤ u) :
        1 + N * u + (N * (N - 1) / 2) * u ^ 2 ≤ (1 + u) ^ N := by
      induction N with
      | zero => simp
      | succ k ih =>
        rw [pow_succ (1 + u) k]
        push_cast
        have h0 : 0 ≤ (k:ℝ) := by positivity
        have h1 : 0 ≤ (k * (k - 1) / 2 : ℝ) * u ^ 3 := by
          rcases Nat.eq_zero_or_pos k with rfl | hk
          · simp
          · have : (1:ℝ) ≤ k := by exact_mod_cast hk
            have : 0 ≤ (k * (k - 1) / 2 : ℝ) := by nlinarith
            positivity
        nlinarith [mul_le_mul_of_nonneg_right ih (by linarith : (0:ℝ) ≤ 1 + u)]
    
  5. There exists a code C = S^N × Sᶜ of cardinality (N * m + x)^N * (m - x) over an alphabet of size m * (N + 1).

    Choose a subset S of the alphabet of size N * m + x; its complement Sᶜ has size m - x. Define C as the product of N copies of S and one copy of Sᶜ. By in1284_pi_card_eq, its cardinality is (N * m + x)^N * (m - x).

    lines 38–65

    uses Finset.exists_subset_card_eq, Finset.card_compl, Fintype.card_fin, Fin.ext, in1284_pi_card_eq

    /-- the perturbed code: first `N` symbols in `S`, the last outside. -/
    lemma in1284_code (N m x : ℕ) (hN : 1 ≤ N) (hx : x ≤ m) :
        ∃ C : Finset (Fin (N+1) → Fin (m * (N+1))),
          C.card = (N * m + x) ^ N * (m - x) ∧
          (∀ u ∈ C, ∀ v ∈ C, ∀ k : ℕ, 0 < k → k < N + 1 →
            ∀ hk1 : k - 1 < N + 1, ∀ hk2 : N + 1 - k + (k - 1) < N + 1,
              u ⟨k - 1, hk1⟩ ≠ v ⟨N + 1 - k + (k - 1), hk2⟩) ∧
          ∀ B : Finset (Fin (N+1) → Fin (m * (N+1))),
            (∃ (I : Finset (Fin (m * (N+1)))), (N + 1) * I.card = (N + 1 - 1) * (m * (N+1)) ∧
              (B = Finset.filter (fun w => (∀ (i : Fin (N+1)), i.val < N + 1 - 1 → w i ∈ I) ∧
                w ⟨N + 1 - 1, by omega⟩ ∉ I) Finset.univ ∨
               B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧
                (∀ (i : Fin (N+1)), 0 < i.val → w i ∈ I)) Finset.univ)) →
            B.card = (N * m) ^ N * m ∧ (C ∩ B).card ≤ (N * m) ^ N * (m - x) := by
      classical
      obtain ⟨S, -, hS⟩ := Finset.exists_subset_card_eq
        (s := (Finset.univ : Finset (Fin (m * (N+1))))) (n := N * m + x)
        (by simp; nlinarith)
      have hSc : Sᶜ.card = m - x := by
        rw [Finset.card_compl, Fintype.card_fin, hS]
        have : m * (N + 1) = N * m + m := by ring
        omega
      have hlast : ∀ h : N + 1 - 1 < N + 1, (⟨N + 1 - 1, h⟩ : Fin (N+1)) = Fin.last N :=
        fun h => Fin.ext (by simp)
      refine ⟨Fintype.piFinset (fun i : Fin (N+1) => if i.val < N then S else Sᶜ), ?_, ?_, ?_⟩
      · apply in1284_pi_card_eq
        · intro i; simp [hS]
        · simp [hSc]
  6. The perturbed code C is non-overlapping: no prefix of length k matches a suffix of length k for any 1 ≤ k ≤ N.

    For any prefix of length k, its last symbol is at coordinate k - 1 < N, which belongs to S by definition of C. For any suffix of length k, its last symbol is at the final coordinate N, which belongs to Sᶜ. Since S and Sᶜ are disjoint, no prefix can equal a suffix.

    lines 66–73

    uses Fintype.mem_piFinset, Finset.mem_compl

      · intro u hu v hv k hk0 hkn hk1 hk2 he
        rw [Fintype.mem_piFinset] at hu hv
        have h1 := hu ⟨k - 1, hk1⟩
        have h2 := hv ⟨N + 1 - k + (k - 1), hk2⟩
        have e1 : k - 1 < N := by omega
        have e2 : ¬ (N + 1 - k + (k - 1) < N) := by omega
        simp only [e1, e2, if_true, if_false, Finset.mem_compl] at h1 h2
        exact h2 (he ▸ h1)
  7. Any optimal Blackburn code B of the first type (I^N × Iᶜ) has cardinality (N * m)^N * m, and |C ∩ B| ≤ (N * m)^N * (m - x).

    The condition (N + 1) * |I| = N * (m * (N + 1)) implies |I| = N * m and |Iᶜ| = m, so B = I^N × Iᶜ has cardinality (N * m)^N * m. Any codeword in C ∩ B has its first N symbols in S ∩ I ⊆ I and its last symbol in Sᶜ ∩ Iᶜ ⊆ Sᶜ. Applying in1284_pi_card_le with bounds |I| = N * m and |Sᶜ| = m - x yields |C ∩ B| ≤ (N * m)^N * (m - x).

    lines 74–120

    uses Nat.eq_of_mul_eq_mul_left, Finset.card_compl, Fintype.card_fin, Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset, Fin.ext, Finset.mem_compl, in1284_pi_card_eq, Finset.card_le_card, in1284_pi_card_le

      · rintro B ⟨I, hI, hB⟩
        have hIc : I.card = N * m := by
          have : (N + 1 - 1) * (m * (N + 1)) = (N + 1) * (N * m) := by
            rw [show N + 1 - 1 = N by omega]; ring
          rw [this] at hI
          exact Nat.eq_of_mul_eq_mul_left (by omega) hI
        have hIcc : Iᶜ.card = m := by
          rw [Finset.card_compl, Fintype.card_fin, hIc]
          have : m * (N + 1) = N * m + m := by ring
          omega
        rcases hB with rfl | rfl
        · constructor
          · rw [show Finset.filter (fun w : Fin (N+1) → Fin (m * (N+1)) =>
                (∀ (i : Fin (N+1)), i.val < N + 1 - 1 → w i ∈ I) ∧
                w ⟨N + 1 - 1, by omega⟩ ∉ I) Finset.univ
                = Fintype.piFinset (fun i : Fin (N+1) => if i.val < N then I else Iᶜ) by
              ext w
              simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset]
              constructor
              · rintro ⟨h1, h2⟩ i
                split_ifs with h
                · exact h1 i (by omega)
                · have : i = ⟨N + 1 - 1, by omega⟩ := Fin.ext (by simp; omega)
                  rw [this, Finset.mem_compl]; exact h2
              · intro h
                refine ⟨fun i hi => ?_, ?_⟩
                · have := h i
                  rwa [if_pos (by omega)] at this
                · have := h ⟨N + 1 - 1, by omega⟩
                  rw [if_neg (by simp)] at this
                  exact Finset.mem_compl.1 this]
            apply in1284_pi_card_eq
            · intro i; simp [hIc]
            · simp [hIcc]
          · refine (Finset.card_le_card (t := Fintype.piFinset
              (fun i : Fin (N+1) => if i.val < N then I else Sᶜ)) ?_).trans ?_
            · intro w hw
              simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and,
                Fintype.mem_piFinset] at hw ⊢
              intro i
              split_ifs with h
              · exact hw.2.1 i (by omega)
              · have := hw.1 i
                rwa [if_neg h] at this
            · apply in1284_pi_card_le
              · intro i; simp [hIc]
              · simp [hSc]
  8. Any optimal Blackburn code B of the second type (Iᶜ × I^N) has cardinality (N * m)^N * m, and |C ∩ B| ≤ (N * m)^N * (m - x).

    As in the first case, |I| = N * m and |Iᶜ| = m, so by in1284_pi_card_eq', |B| = m * (N * m)^N. Codewords in C ∩ B have coordinate 0 in S ∩ Iᶜ (size ≤ m), coordinates 1 to N - 1 in S ∩ I (size ≤ N * m), and coordinate N in Sᶜ ∩ I (size ≤ |Sᶜ| = m - x). Applying in1284_pi_card_le with bounds N * m and m - x gives |C ∩ B| ≤ (N * m)^N * (m - x).

    lines 121–164

    uses Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset, Fin.ext, Finset.mem_compl, in1284_pi_card_eq', Finset.card_le_card, in1284_pi_card_le

        · constructor
          · rw [show Finset.filter (fun w : Fin (N+1) → Fin (m * (N+1)) => w ⟨0, by omega⟩ ∉ I ∧
                (∀ (i : Fin (N+1)), 0 < i.val → w i ∈ I)) Finset.univ
                = Fintype.piFinset (fun i : Fin (N+1) => if i.val = 0 then Iᶜ else I) by
              ext w
              simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset]
              constructor
              · rintro ⟨h1, h2⟩ i
                split_ifs with h
                · have : i = ⟨0, by omega⟩ := Fin.ext h
                  rw [this, Finset.mem_compl]; exact h1
                · exact h2 i (by omega)
              · intro h
                refine ⟨?_, fun i hi => ?_⟩
                · have := h ⟨0, by omega⟩
                  rw [if_pos rfl] at this
                  exact Finset.mem_compl.1 this
                · have := h i
                  rwa [if_neg (by omega)] at this]
            rw [in1284_pi_card_eq' _ (N * m) m]
            · ring
            · simp [hIcc]
            · intro i; simp [hIc]
          · refine (Finset.card_le_card (t := Fintype.piFinset
              (fun i : Fin (N+1) => if i.val = 0 then Iᶜ else if i.val < N then I else Sᶜ)) ?_).trans ?_
            · intro w hw
              simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and,
                Fintype.mem_piFinset] at hw ⊢
              intro i
              split_ifs with h h'
              · have : i = ⟨0, by omega⟩ := Fin.ext h
                rw [this, Finset.mem_compl]; exact hw.2.1
              · exact hw.2.2 i (by omega)
              · have := hw.1 i
                rwa [if_neg h'] at this
            · apply in1284_pi_card_le
              · intro i
                by_cases h : (i.castSucc : Fin (N+1)).val = 0
                · rw [if_pos h, hIcc]
                  nlinarith
                · rw [if_neg h, if_pos (by simp)]
                  simp [hIc]
              · have h1 : ¬ ((Fin.last N : Fin (N+1)).val = 0) := by simp; omega
                rw [if_neg h1, if_neg (by simp), hSc]
  9. Under the analytic conditions on s, θ, x, the perturbed code size satisfies (c - ε) * (m * (N + 1))^(N + 1) ≤ (N * m + x)^N * (m - x).

    Set Q = N * m, T = (m * (N + 1))^(N + 1), and u = x / Q ≤ θ * s. Factoring (Q + x)^N * (m - x) = Q^N * m * (1 + u)^N * (1 - N * u) and applying in1284_binom shows that (1 + u)^N * (1 - N * u) ≥ 1 - A * u^2 - Dd * N * u^3 with A = N * (N + 1) / 2 and Dd = N * (N - 1) / 2. Since u ≤ θ * s, the higher-order deficit is at most ε * T, leaving the code size at least (c - ε) * T.

    lines 165–236

    uses div_le_one, div_le_iff₀, in1284_binom, mul_pow, mul_le_mul_of_nonneg_left, pow_le_pow_left₀, sq_nonneg

    lemma in1284_real (N m x : ℕ) (hN : 1 ≤ N) (hm : 1 ≤ m) (hxm : x ≤ m) (c ε s θ : ℝ)
        (hc : c * ((m:ℝ) * (N + 1)) ^ (N + 1) = ((N:ℝ) * m) ^ N * m) (hc0 : 0 < c)
        (hs : 0 ≤ s) (hε : ε = s ^ 2) (hθ : 0 ≤ θ)
        (hcond : c * (N * (N + 1) / 2) * θ ^ 2 + c * (N * (N - 1) / 2) * N * θ ^ 3 * s ≤ 1)
        (hxle : (x:ℝ) ≤ θ * s * N * m) (hxge : θ * s * N * m - 1 < x) :
        (c - ε) * ((m:ℝ) * (N + 1)) ^ (N + 1) ≤ ((N:ℝ) * m + x) ^ N * ((m:ℝ) - x) ∧
        ∀ D CB : ℝ, D + 2 * CB = ((N:ℝ) * m + x) ^ N * ((m:ℝ) - x) + ((N:ℝ) * m) ^ N * m →
          CB ≤ ((N:ℝ) * m) ^ N * ((m:ℝ) - x) →
          2 * c * N * θ * s - ε - 2 * c / m ≤ D / ((m:ℝ) * (N + 1)) ^ (N + 1) := by
      have hNR : (1:ℝ) ≤ N := by exact_mod_cast hN
      have hmR : (1:ℝ) ≤ m := by exact_mod_cast hm
      have hxmR : (x:ℝ) ≤ m := by exact_mod_cast hxm
      have hx0 : (0:ℝ) ≤ x := by positivity
      set Q : ℝ := (N:ℝ) * m with hQ
      have hQ0 : 0 < Q := by positivity
      set T : ℝ := ((m:ℝ) * (N + 1)) ^ (N + 1) with hT
      have hT0 : 0 < T := by positivity
      set u : ℝ := x / Q with hu
      have hu0 : 0 ≤ u := by positivity
      have hQu : Q + x = Q * (1 + u) := by rw [hu]; field_simp
      have hmu : (m:ℝ) - x = m * (1 - N * u) := by
        rw [hu, hQ]; field_simp
      have hNu : N * u ≤ 1 := by
        rw [hu, hQ, mul_div_assoc', div_le_one (by positivity)]
        nlinarith
      have huθ : u ≤ θ * s := by
        rw [hu, div_le_iff₀ hQ0, hQ]; nlinarith
      have hbin := in1284_binom N u hu0
      set A : ℝ := (N * (N + 1) / 2)
      set Dd : ℝ := (N * (N - 1) / 2)
      have hDd : 0 ≤ Dd := by
        have : 0 ≤ (N:ℝ) - 1 := by linarith
        positivity
      have hP : Q ^ N * m * (1 - A * u ^ 2 - Dd * N * u ^ 3) ≤ (Q + x) ^ N * ((m:ℝ) - x) := by
        rw [hQu, hmu, mul_pow Q (1 + u) N]
        have h1 : (1 - A * u ^ 2 - Dd * N * u ^ 3) = (1 + N * u + Dd * u ^ 2) * (1 - N * u) := by
          simp only [A, Dd]; ring
        rw [h1]
        have h2 : 0 ≤ 1 - N * u := by linarith
        have h3 : 0 ≤ Q ^ N * m := by positivity
        calc Q ^ N * m * ((1 + N * u + Dd * u ^ 2) * (1 - N * u))
            = Q ^ N * m * (1 - N * u) * (1 + N * u + Dd * u ^ 2) := by ring
          _ ≤ Q ^ N * m * (1 - N * u) * (1 + u) ^ N := by
              apply mul_le_mul_of_nonneg_left hbin; positivity
          _ = Q ^ N * (1 + u) ^ N * (m * (1 - N * u)) := by ring
      have hsmall : c * (A * u ^ 2 + Dd * N * u ^ 3) ≤ ε := by
        have hA0 : 0 ≤ A := by positivity
        have e1 : u ^ 2 ≤ (θ * s) ^ 2 := pow_le_pow_left₀ hu0 huθ 2
        have e2 : u ^ 3 ≤ (θ * s) ^ 3 := pow_le_pow_left₀ hu0 huθ 3
        have e3 : c * (A * u ^ 2 + Dd * N * u ^ 3) ≤ c * (A * (θ * s) ^ 2 + Dd * N * (θ * s) ^ 3) := by
          apply mul_le_mul_of_nonneg_left _ hc0.le
          have : 0 ≤ Dd * N := by positivity
          nlinarith
        have e4 : c * (A * (θ * s) ^ 2 + Dd * N * (θ * s) ^ 3)
            = s ^ 2 * (c * A * θ ^ 2 + c * Dd * N * θ ^ 3 * s) := by ring
        have e5 : s ^ 2 * (c * A * θ ^ 2 + c * Dd * N * θ ^ 3 * s) ≤ s ^ 2 * 1 :=
          mul_le_mul_of_nonneg_left hcond (sq_nonneg s)
        rw [hε]
        linarith
      have hPT : Q ^ N * m - ε * T ≤ (Q + x) ^ N * ((m:ℝ) - x) := by
        have : Q ^ N * m * (A * u ^ 2 + Dd * N * u ^ 3) ≤ ε * T := by
          rw [← hc]
          calc c * T * (A * u ^ 2 + Dd * N * u ^ 3) = T * (c * (A * u ^ 2 + Dd * N * u ^ 3)) := by ring
            _ ≤ T * ε := mul_le_mul_of_nonneg_left hsmall hT0.le
            _ = ε * T := by ring
        have e6 : Q ^ N * m * (1 - A * u ^ 2 - Dd * N * u ^ 3)
            = Q ^ N * m - Q ^ N * m * (A * u ^ 2 + Dd * N * u ^ 3) := by ring
        linarith
      have hcT : c * T = Q ^ N * m := hc
      refine ⟨by have e7 : (c - ε) * T = c * T - ε * T := by ring
                 linarith, ?_⟩
  10. The normalized distance satisfies D / T ≥ 2 * c * N * θ * s - ε - 2 * c / m whenever D + 2 * CB = (N * m + x)^N * (m - x) + (N * m)^N * m and CB ≤ (N * m)^N * (m - x).

    From D = |C| + |B| - 2 * |C ∩ B|, substituting |C| ≥ c * T - ε * T, |B| = c * T, and |C ∩ B| ≤ Q^N * (m - x) gives D ≥ c * T - ε * T + c * T - 2 * Q^N * (m - x) = 2 * Q^N * x - ε * T. Since x > θ * s * N * m - 1, the linear term 2 * Q^N * x provides at least 2 * c * N * θ * s * T - 2 * c * T / m. Dividing by T yields the lower bound.

    lines 237–254

    uses le_div_iff₀

      intro D CB hD hCB
      rw [le_div_iff₀ hT0]
      have hcm : c * T = Q ^ N * m := hc
      have hQx : 2 * c * N * θ * s * T - 2 * c / m * T ≤ 2 * Q ^ N * x := by
        have : 2 * c / m * T = 2 * Q ^ N := by
          field_simp
          linarith [hcm]
        rw [this]
        have h5 : 2 * c * N * θ * s * T = 2 * Q ^ N * (θ * s * N * m) := by
          have : 2 * c * N * θ * s * T = 2 * (c * T) * (θ * s * N) := by ring
          rw [this, hcm]; ring
        rw [h5]
        have : 0 ≤ 2 * Q ^ N := by positivity
        nlinarith
      have hQm : Q ^ N * ((m:ℝ) - x) = Q ^ N * m - Q ^ N * x := by ring
      have e8 : (2 * c * N * θ * s - ε - 2 * c / m) * T
          = 2 * c * N * θ * s * T - ε * T - 2 * c / m * T := by ring
      linarith
  11. For any finite sets C and B, |C Δ B| + 2 * |C ∩ B| = |C| + |B|.

    Decompose C Δ B into the disjoint union of C \ B and B \ C. Since |C \ B| = |C| - |C ∩ B| and |B \ C| = |B| - |C ∩ B|, summing them gives |C Δ B| = |C| + |B| - 2 * |C ∩ B|.

    lines 255–262

    uses symmDiff_def, Finset.sup_eq_union, Finset.card_union_of_disjoint, disjoint_sdiff_sdiff, Finset.card_sdiff_add_card_inter, Finset.inter_comm

    lemma in1284_symm {α : Type*} [DecidableEq α] (C B : Finset α) :
        (symmDiff C B).card + 2 * (C ∩ B).card = C.card + B.card := by
      rw [symmDiff_def, Finset.sup_eq_union, Finset.card_union_of_disjoint disjoint_sdiff_sdiff]
      have h1 := Finset.card_sdiff_add_card_inter C B
      have h2 := Finset.card_sdiff_add_card_inter B C
      rw [Finset.inter_comm] at h2
      omega
  12. The normalized symmetric difference |C Δ B| / q^(N + 1) is at most 2 for any codes C, B ⊆ Fin(q)^(N + 1).

    Both C and B are subsets of Fin(q)^(N + 1), which has size q^(N + 1). Thus |C Δ B| ≤ |C| + |B| ≤ 2 * q^(N + 1), and dividing by q^(N + 1) gives at most 2.

    lines 263–274

    uses in1284_symm, Fintype.card_fun, Finset.card_le_univ, div_le_iff₀

    lemma in1284_le_two {N q : ℕ} (hq : 0 < q) (C B : Finset (Fin (N+1) → Fin q)) :
        ((symmDiff C B).card : ℝ) / (q : ℝ) ^ (N + 1) ≤ 2 := by
      have h := in1284_symm C B
      have hC : C.card ≤ q ^ (N + 1) := by
        simpa [Fintype.card_fun] using Finset.card_le_univ C
      have hB : B.card ≤ q ^ (N + 1) := by
        simpa [Fintype.card_fun] using Finset.card_le_univ B
      have h3 : (symmDiff C B).card ≤ 2 * q ^ (N + 1) := by omega
      have h4 : ((symmDiff C B).card : ℝ) ≤ 2 * (q : ℝ) ^ (N + 1) := by exact_mod_cast h3
      rw [div_le_iff₀ (by positivity)]
      linarith
  13. Setting N = n - 1 ≥ 1, the constants satisfy c_n * (m * (N + 1))^(N + 1) = (N * m)^N * m and K_n^2 * (N + 1) = 8 * c_n * N, with K_n > 0.

    Reparameterize n as N + 1 with N ≥ 1. By expanding the definitions of λ = N / (N + 1), c_n = λ^N / (N + 1), and K_n = 2 * √(2 / N) * λ^((N + 2) / 2), direct algebraic manipulation confirms c_n * (m * (N + 1))^(N + 1) = (N * m)^N * m and K_n^2 * (N + 1) = (8 / N) * λ^(N + 2) * (N + 1) = 8 * c_n * N. Positivity of K_n follows from λ > 0 and N ≥ 1.

    lines 275–340

    uses Nat.add_sub_cancel, div_pow, mul_pow, pow_succ, Real.rpow_mul_natCast, Real.rpow_natCast, Real.sq_sqrt, pow_add, Real.sqrt_nonneg, Real.rpow_nonneg

    theorem op2468_blackburn_stability_lower_bound_eventually (n : ℕ) (hn : 2 ≤ n) :
        let lam : ℝ := (n - 1 : ℝ) / n
        let c_n : ℝ := lam ^ (n - 1) / (n : ℝ)
        let K_n : ℝ := 2 * Real.sqrt (2 / (n - 1 : ℝ)) * lam ^ (((n : ℝ) + 1) / 2)
        let is_nonoverlapping (q : ℕ) (C : Finset (Fin n → Fin q)) : Prop :=
          ∀ u ∈ C, ∀ v ∈ C, ¬ ∃ (k : ℕ) (_ : 0 < k) (_ : k < n),
            ∀ i : Fin k, u ⟨i.val, by omega⟩ = v ⟨n - k + i.val, by omega⟩
        let optimal_blackburn (q : ℕ) : Set (Finset (Fin n → Fin q)) :=
          { B | ∃ (I : Finset (Fin q)), n * I.card = (n - 1) * q ∧
            (B = Finset.filter (fun w => (∀ (i : Fin n), i.val < n - 1 → w i ∈ I) ∧
              w ⟨n - 1, by omega⟩ ∉ I) Finset.univ ∨
             B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧
              (∀ (i : Fin n), 0 < i.val → w i ∈ I)) Finset.univ) }
        let code_dist (q : ℕ) (C : Finset (Fin n → Fin q)) : ℝ :=
          sInf { ((symmDiff C B).card : ℝ) / (q : ℝ) ^ n | B ∈ optimal_blackburn q }
        let max_dist (q : ℕ) (ε : ℝ) : ℝ :=
          sSup { d | ∃ C : Finset (Fin n → Fin q),
            is_nonoverlapping q C ∧ (c_n - ε) * (q : ℝ) ^ n ≤ C.card ∧ d = code_dist q C }
        let M (ε : ℝ) : ℝ :=
          Filter.limsup (fun m : ℕ => max_dist (m * n) ε) Filter.atTop
        ∀ η : ℝ, 0 < η → ∀ᶠ ε in nhdsWithin (0 : ℝ) (Set.Ioi 0), (K_n - η) * Real.sqrt ε ≤ M ε := by
      obtain ⟨N, rfl⟩ : ∃ N, n = N + 1 := ⟨n - 1, by omega⟩
      have hN : 1 ≤ N := by omega
      intro lam c_n K_n is_nonoverlapping optimal_blackburn code_dist max_dist M η hη
      have hNR : (1:ℝ) ≤ N := by exact_mod_cast hN
      have hN1 : (0:ℝ) < (N:ℝ) + 1 := by positivity
      have hlam : lam = (N:ℝ) / (N + 1) := by
        show (((N + 1 : ℕ) : ℝ) - 1) / ((N + 1 : ℕ) : ℝ) = _
        push_cast; ring
      have hlam0 : 0 < lam := by rw [hlam]; positivity
      have hc : c_n = lam ^ N / (N + 1) := by
        show lam ^ (N + 1 - 1) / ((N + 1 : ℕ) : ℝ) = _
        rw [Nat.add_sub_cancel]; push_cast; ring
      have hc0 : 0 < c_n := by rw [hc]; positivity
      have hcT : ∀ m : ℕ, c_n * ((m:ℝ) * (N + 1)) ^ (N + 1) = ((N:ℝ) * m) ^ N * m := by
        intro m
        rw [hc, hlam, div_pow, mul_pow, mul_pow, pow_succ ((N:ℝ) + 1)]
        field_simp
        ring
      have hK2 : K_n ^ 2 * (N + 1) = 8 * c_n * N := by
        have hr : (lam ^ ((((N + 1 : ℕ) : ℝ) + 1) / 2)) ^ 2 = lam ^ (N + 2) := by
          rw [← Real.rpow_mul_natCast hlam0.le]
          rw [show (((N + 1 : ℕ) : ℝ) + 1) / 2 * ((2 : ℕ) : ℝ) = ((N + 2 : ℕ) : ℝ) by
            push_cast; ring]
          exact Real.rpow_natCast _ _
        have hs2 : (Real.sqrt (2 / (((N + 1 : ℕ) : ℝ) - 1))) ^ 2 = 2 / N := by
          rw [Real.sq_sqrt (by push_cast; simp only [add_sub_cancel_right]; positivity)]
          push_cast; ring
        show (2 * Real.sqrt (2 / (((N + 1 : ℕ) : ℝ) - 1)) *
          lam ^ ((((N + 1 : ℕ) : ℝ) + 1) / 2)) ^ 2 * (N + 1) = 8 * c_n * N
        rw [mul_pow, mul_pow, hs2, hr, hc, pow_add, hlam]
        have : (N:ℝ) ≠ 0 := by positivity
        field_simp
        ring
      have hK0' : 0 ≤ K_n := by
        show 0 ≤ 2 * Real.sqrt (2 / (((N + 1 : ℕ) : ℝ) - 1)) * lam ^ ((((N + 1 : ℕ) : ℝ) + 1) / 2)
        exact mul_nonneg (mul_nonneg (by norm_num) (Real.sqrt_nonneg _))
          (Real.rpow_nonneg hlam0.le _)
      have hK0 : 0 < K_n := by
        rcases hK0'.lt_or_eq with h | h
        · exact h
        · exfalso
          rw [← h] at hK2
          have : 0 < 8 * c_n * N := by positivity
          linarith [show (0:ℝ) ^ 2 * (N + 1) = 0 by ring]
  14. The parameter θ = max(0, (K_n - η / 2) / (2 * c_n * N)) satisfies K_n - η / 2 ≤ 2 * c_n * N * θ < K_n and c_n * (N * (N + 1) / 2) * θ^2 < 1, providing a positive slack radius r > 0.

    By definition, 2 * c_n * N * θ < K_n. Squaring this inequality and multiplying by N + 1 yields (2 * c_n * N * θ)^2 * (N + 1) < K_n^2 * (N + 1) = 8 * c_n * N, which simplifies to c_n * (N * (N + 1) / 2) * θ^2 < 1. Hence γ = 1 - c_n * (N * (N + 1) / 2) * θ^2 > 0, and we choose r > 0 small enough to control both the cubic remainder and alphabet scaling constraints.

    lines 341–374

    uses le_max_left, le_max_right, div_le_iff₀, max_lt_iff, div_lt_div_of_pos_right, lt_div_iff₀, pow_lt_pow_left₀, mul_lt_mul_of_pos_right, mul_le_mul_of_nonneg_left, lt_min

      have hcN : 0 < 2 * c_n * N := by positivity
      set θ : ℝ := max 0 ((K_n - η / 2) / (2 * c_n * N)) with hθdef
      have hθ0 : 0 ≤ θ := le_max_left _ _
      have hθ1 : K_n - η / 2 ≤ 2 * c_n * N * θ := by
        have := le_max_right 0 ((K_n - η / 2) / (2 * c_n * N))
        rw [← hθdef] at this
        rw [div_le_iff₀ hcN] at this
        linarith
      have hθ2 : 2 * c_n * N * θ < K_n := by
        have : θ < K_n / (2 * c_n * N) := by
          rw [hθdef, max_lt_iff]
          exact ⟨by positivity, by apply div_lt_div_of_pos_right _ hcN; linarith⟩
        rw [lt_div_iff₀ hcN] at this
        linarith
      have hA : c_n * (N * (N + 1) / 2) * θ ^ 2 < 1 := by
        have hsq : (2 * c_n * N * θ) ^ 2 < K_n ^ 2 :=
          pow_lt_pow_left₀ hθ2 (by positivity) (by norm_num)
        have h := mul_lt_mul_of_pos_right hsq hN1
        have h8 : 0 < 8 * c_n * N := by positivity
        have e : 8 * c_n * N * (c_n * (N * (N + 1) / 2) * θ ^ 2) = (2 * c_n * N * θ) ^ 2 * (N + 1) := by
          ring
        by_contra hcon
        push_neg at hcon
        have := mul_le_mul_of_nonneg_left hcon h8.le
        linarith
      set γ : ℝ := 1 - c_n * (N * (N + 1) / 2) * θ ^ 2 with hγ
      have hγ0 : 0 < γ := by linarith
      set β : ℝ := c_n * (N * (N - 1) / 2) * N * θ ^ 3 with hβ
      have hβ0 : 0 ≤ β := by
        have : 0 ≤ (N:ℝ) - 1 := by linarith
        positivity
      set r : ℝ := min (η / 2) (min (γ / (β + 1)) (1 / (θ * N + 1))) with hr
      have hr0 : 0 < r := by
        apply lt_min (by positivity) (lt_min (by positivity) (by positivity))
  15. For ε in a punctured right-neighborhood of 0, s = √ε satisfies s < r, s ≤ η / 2, and the analytic hypothesis of in1284_real.

    Because √ε → 0 as ε → 0⁺, for ε in a suitable right-neighborhood of 0, s = √ε is strictly less than r. By choice of r, this implies s ≤ η / 2 and the higher-order deficit bound c_n * (N * (N + 1) / 2) * θ^2 + c_n * (N * (N - 1) / 2) * N * θ^3 * s ≤ 1.

    lines 375–395

    uses nhdsWithin_le_nhds, self_mem_nhdsWithin, Iio_mem_nhds, Real.sqrt_nonneg, Real.sq_sqrt, min_le_left, min_le_right, le_div_iff₀

      have hlim : Filter.Tendsto (fun ε : ℝ => Real.sqrt ε) (nhdsWithin 0 (Set.Ioi 0)) (nhds 0) := by
        have := (Real.continuous_sqrt.tendsto 0).mono_left
          (nhdsWithin_le_nhds (s := Set.Ioi (0:ℝ)))
        simpa using this
      filter_upwards [self_mem_nhdsWithin, hlim (Iio_mem_nhds hr0)] with ε hε hsr
      simp only [Set.mem_Ioi] at hε
      simp only [Set.mem_preimage, Set.mem_Iio] at hsr
      set s := Real.sqrt ε with hsdef
      have hs0 : 0 ≤ s := Real.sqrt_nonneg ε
      have hεs : ε = s ^ 2 := (Real.sq_sqrt hε.le).symm
      have hs1 : s ≤ η / 2 := le_trans hsr.le (min_le_left _ _)
      have hs2 : s ≤ γ / (β + 1) := le_trans hsr.le ((min_le_right _ _).trans (min_le_left _ _))
      have hs3 : s ≤ 1 / (θ * N + 1) := le_trans hsr.le ((min_le_right _ _).trans (min_le_right _ _))
      have hcond : c_n * (N * (N + 1) / 2) * θ ^ 2 + c_n * (N * (N - 1) / 2) * N * θ ^ 3 * s ≤ 1 := by
        rw [le_div_iff₀ (by positivity)] at hs2
        have : β * s ≤ γ := by nlinarith
        rw [hβ] at this
        linarith
      have hθs : θ * s * N ≤ 1 := by
        rw [le_div_iff₀ (by positivity)] at hs3
        nlinarith
  16. For every m ≥ 1, the code C constructed with x = ⌊θ * s * N * m⌋ satisfies 2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ max_dist(m * (N + 1), ε) ≤ 2.

    For any integer m ≥ 1, set x = ⌊θ * s * N * m⌋. Lemma in1284_code supplies a non-overlapping code C of size bounded below by (c_n - ε) * q^n via in1284_real. Furthermore, for every optimal Blackburn code B, in1284_real bounds the normalized symmetric difference distance from below by 2 * c_n * N * θ * s - ε - 2 * c_n / m. Taking the infimum over B and supremum over valid codes gives the bounds on max_dist.

    lines 396–463

    uses Nat.floor_le, Nat.sub_one_lt_floor, in1284_code, in1284_real, Nat.cast_sub, Finset.exists_subset_card_eq, Finset.card_univ, Fintype.card_fin, csInf_le, in1284_le_two, le_csInf, in1284_symm, le_csSup, csSup_le

      -- per m
      have hmd : ∀ m : ℕ, 1 ≤ m →
          2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ max_dist (m * (N + 1)) ε ∧
          max_dist (m * (N + 1)) ε ≤ 2 := by
        intro m hm
        classical
        have hmR : (1:ℝ) ≤ m := by exact_mod_cast hm
        have hq : 0 < m * (N + 1) := by positivity
        set x := ⌊θ * s * N * m⌋₊ with hxdef
        have hxle : (x:ℝ) ≤ θ * s * N * m := Nat.floor_le (by positivity)
        have hxge : θ * s * N * m - 1 < x := Nat.sub_one_lt_floor _
        have hxm : x ≤ m := by
          have : (x:ℝ) ≤ m := by nlinarith
          exact_mod_cast this
        obtain ⟨C, hCc, hCno, hCB⟩ := in1284_code N m x hN hxm
        obtain ⟨h1, h2⟩ := in1284_real N m x hN hm hxm c_n ε s θ (hcT m) hc0 hs0 hεs hθ0
          hcond hxle hxge
        have hC1 : is_nonoverlapping (m * (N + 1)) C := by
          rintro u hu v hv ⟨k, hk0, hk2, hk⟩
          exact hCno u hu v hv k hk0 hk2 (by omega) (by omega) (hk ⟨k - 1, by omega⟩)
        have hC2 : (c_n - ε) * (((m * (N + 1) : ℕ) : ℝ)) ^ (N + 1) ≤ C.card := by
          rw [hCc]
          push_cast [Nat.cast_sub hxm]
          exact h1
        obtain ⟨I0, -, hI0⟩ := Finset.exists_subset_card_eq
          (s := (Finset.univ : Finset (Fin (m * (N + 1))))) (n := N * m)
          (by rw [Finset.card_univ, Fintype.card_fin, Nat.mul_comm m, Nat.add_mul, Nat.one_mul]
              exact Nat.le_add_right _ _)
        have hB0 : Finset.filter (fun w : Fin (N + 1) → Fin (m * (N + 1)) =>
            (∀ (i : Fin (N + 1)), i.val < N + 1 - 1 → w i ∈ I0) ∧
              w ⟨N + 1 - 1, by omega⟩ ∉ I0) Finset.univ ∈ optimal_blackburn (m * (N + 1)) :=
          ⟨I0, by rw [hI0, show N + 1 - 1 = N by omega]; ring, Or.inl rfl⟩
        have hcd2 : ∀ C' : Finset (Fin (N + 1) → Fin (m * (N + 1))), code_dist (m * (N + 1)) C' ≤ 2 := by
          intro C'
          refine le_trans (csInf_le ⟨0, ?_⟩ ⟨_, hB0, rfl⟩) (in1284_le_two hq C' _)
          rintro _ ⟨B, -, rfl⟩
          exact div_nonneg (Nat.cast_nonneg _) (pow_nonneg (Nat.cast_nonneg _) _)
        have hcdl : 2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ code_dist (m * (N + 1)) C := by
          apply le_csInf
          · exact ⟨_, _, hB0, rfl⟩
          rintro _ ⟨B, hB, rfl⟩
          obtain ⟨hBc, hCBc⟩ := hCB B hB
          have hid := in1284_symm C B
          have hid' : ((symmDiff C B).card : ℝ) + 2 * ((C ∩ B).card : ℝ)
              = ((N:ℝ) * m + x) ^ N * ((m:ℝ) - x) + ((N:ℝ) * m) ^ N * m := by
            have : ((symmDiff C B).card : ℝ) + 2 * ((C ∩ B).card : ℝ) = C.card + B.card := by
              exact_mod_cast hid
            rw [this, hCc, hBc]
            push_cast [Nat.cast_sub hxm]
            ring
          have hCB' : ((C ∩ B).card : ℝ) ≤ ((N:ℝ) * m) ^ N * ((m:ℝ) - x) := by
            have : ((C ∩ B).card : ℝ) ≤ (((N * m) ^ N * (m - x) : ℕ) : ℝ) := by exact_mod_cast hCBc
            push_cast [Nat.cast_sub hxm] at this
            exact this
          have := h2 _ _ hid' hCB'
          push_cast
          exact this
        have hmem : code_dist (m * (N + 1)) C ∈ {d | ∃ C : Finset (Fin (N + 1) → Fin (m * (N + 1))),
            is_nonoverlapping (m * (N + 1)) C ∧
              (c_n - ε) * (((m * (N + 1) : ℕ) : ℝ)) ^ (N + 1) ≤ C.card ∧
                d = code_dist (m * (N + 1)) C} := ⟨C, hC1, hC2, rfl⟩
        have hub : ∀ d ∈ {d | ∃ C : Finset (Fin (N + 1) → Fin (m * (N + 1))),
            is_nonoverlapping (m * (N + 1)) C ∧
              (c_n - ε) * (((m * (N + 1) : ℕ) : ℝ)) ^ (N + 1) ≤ C.card ∧
                d = code_dist (m * (N + 1)) C}, d ≤ 2 := by
          rintro _ ⟨C', -, -, rfl⟩
          exact hcd2 C'
        exact ⟨hcdl.trans (le_csSup ⟨2, hub⟩ hmem), csSup_le ⟨_, hmem⟩ hub⟩
  17. Taking the limsup over m → ∞ yields 2 * c_n * N * θ * s - ε ≤ M(ε).

    As m → ∞, the discretization term 2 * c_n / m tends to 0, so the sequence of lower bounds converges to 2 * c_n * N * θ * s - ε. Since max_dist is bounded above by 2, Filter.limsup_le_limsup preserves the inequality, proving that M(ε) is at least 2 * c_n * N * θ * s - ε.

    lines 464–478

    uses Filter.eventually_atTop, Filter.isBoundedUnder_of_eventually_le, tendsto_const_div_atTop_nhds_zero_nat, Filter.limsup_le_limsup

      have hev : ∀ᶠ m : ℕ in Filter.atTop,
          2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ max_dist (m * (N + 1)) ε ∧
          max_dist (m * (N + 1)) ε ≤ 2 :=
        Filter.eventually_atTop.2 ⟨1, fun m hm => hmd m hm⟩
      have hbu : Filter.IsBoundedUnder (· ≤ ·) Filter.atTop
          (fun m : ℕ => max_dist (m * (N + 1)) ε) :=
        Filter.isBoundedUnder_of_eventually_le (hev.mono fun m h => h.2)
      have hg : Filter.Tendsto (fun m : ℕ => 2 * c_n * N * θ * s - ε - 2 * c_n / m)
          Filter.atTop (nhds (2 * c_n * N * θ * s - ε)) := by
        have h0 : Filter.Tendsto (fun m : ℕ => (2 * c_n) / (m : ℝ)) Filter.atTop (nhds 0) :=
          tendsto_const_div_atTop_nhds_zero_nat (2 * c_n)
        simpa using h0.const_sub (2 * c_n * N * θ * s - ε)
      have hl := Filter.limsup_le_limsup (hev.mono fun m h => h.1) hg.isCoboundedUnder_le hbu
      rw [hg.limsup_eq] at hl
      have hM : 2 * c_n * N * θ * s - ε ≤ M ε := hl
  18. Eventually as ε → 0⁺, (K_n - η) * √ε ≤ M(ε).

    From 2 * c_n * N * θ ≥ K_n - η / 2, we have 2 * c_n * N * θ * s ≥ (K_n - η / 2) * s. Since ε = s^2 ≤ (η / 2) * s, subtracting ε gives 2 * c_n * N * θ * s - ε ≥ (K_n - η / 2) * s - (η / 2) * s = (K_n - η) * s = (K_n - η) * √ε, completing the proof.

    lines 479–484

    uses mul_le_mul_of_nonneg_right, pow_two

      have e1 := mul_le_mul_of_nonneg_right hθ1 hs0
      have e2 : ε ≤ η / 2 * s := by
        rw [hεs, pow_two]
        exact mul_le_mul_of_nonneg_right hs1 hs0
      have e3 : (K_n - η) * s = (K_n - η / 2) * s - η / 2 * s := by ring
      linarith
Fintype.card_piFinset
The cardinality of a Cartesian product of finite sets is the product of their cardinalities.
Fin.prod_univ_castSucc
A product over Fin (n + 1) splits into the product over the first n elements and the final element Fin.last n.
Nat.mul_le_mul
If a ≤ b and c ≤ d in ℕ, then a * c ≤ b * d.
Finset.prod_le_prod
If f(i) ≤ g(i) and f(i) ≥ 0 for all i in a finite set, then ∏ f(i) ≤ ∏ g(i).
Fin.prod_univ_succ
A product over Fin (n + 1) splits into the first element (index 0) and the product over the remaining elements.
pow_succ
For any element in a monoid, a^(n+1) = a^n * a.
Nat.eq_zero_or_pos
Every natural number is either zero or strictly positive.
mul_le_mul_of_nonneg_right
If b ≤ c and 0 ≤ a in a preordered ring, then b * a ≤ c * a.
Finset.exists_subset_card_eq
Any finite set has a subset of every cardinality up to its own size.
Finset.card_compl
The cardinality of the complement of a subset of a finite type is the type's cardinality minus the subset's cardinality.
Fintype.card_fin
The cardinality of Fin n is n.
Fin.ext
Two elements of Fin n are equal if and only if their underlying natural numbers are equal.
in1284_pi_card_eq
Cartesian product of N copies of a set of size a and one set of size c has size a^N * c.
Fintype.mem_piFinset
A function belongs to a Cartesian product of finite sets if and only if each coordinate value belongs to the corresponding set.
Finset.mem_compl
An element belongs to the complement of a set if and only if it does not belong to the set.
Nat.eq_of_mul_eq_mul_left
If n * m = n * k and n > 0 in ℕ, then m = k.
Finset.mem_filter
An element belongs to a filtered set if and only if it belongs to the base set and satisfies the predicate.
Finset.mem_univ
Every element of a finite type belongs to its universal finset.
true_and
The proposition True ∧ p is equivalent to p.
Finset.card_le_card
If s ⊆ t for finite sets, then |s| ≤ |t|.
in1284_pi_card_le
Cartesian product of N sets of size at most a and one set of size at most c has size at most a^N * c.
in1284_pi_card_eq'
Cartesian product of one set of size c and N sets of size a has size c * a^N.
in1284_binom
For any real u ≥ 0 and natural number N, 1 + N*u + (N*(N-1)/2)*u^2 ≤ (1+u)^N.
mul_pow
In a commutative monoid, (a * b)^n = a^n * b^n.
mul_le_mul_of_nonneg_left
If b ≤ c and 0 ≤ a in a preordered ring, then a * b ≤ a * c.
pow_le_pow_left₀
If 0 ≤ a ≤ b, then a^n ≤ b^n.
sq_nonneg
The square of any element in an ordered semiring is non-negative.
le_div_iff₀
For positive c, a ≤ b / c is equivalent to a * c ≤ b.
symmDiff_def
The symmetric difference of two sets is the union of their relative complements.
Finset.sup_eq_union
The supremum in the lattice of finsets is given by set union.
Finset.card_union_of_disjoint
The cardinality of the union of two disjoint finite sets is the sum of their cardinalities.
disjoint_sdiff_sdiff
The relative complements s \ t and t \ s are disjoint.
Finset.card_sdiff_add_card_inter
For finite sets s and t, |s \ t| + |s ∩ t| = |s|.
Finset.inter_comm
Intersection of finite sets is commutative.
in1284_symm
For finite sets C and B, |C Δ B| + 2 |C ∩ B| = |C| + |B|.
Fintype.card_fun
The number of functions from a finite type α to a finite type β is |β|^|α|.
Finset.card_le_univ
The cardinality of any finset in a finite type is at most the cardinality of the type.
div_le_iff₀
For positive c, b / c ≤ a is equivalent to b ≤ a * c.
Nat.add_sub_cancel
For a natural number n, (n + 1) - 1 = n.
div_pow
In a division monoid, (a / b)^n = a^n / b^n.
Real.rpow_mul_natCast
For non-negative real x, (x^y)^n = x^(y * n) for natural n.
Real.rpow_natCast
For real x and natural n, x^(n:ℝ) = x^n.
Real.sq_sqrt
For non-negative real x, (sqrt x)^2 = x.
pow_add
In a monoid, a^(m + n) = a^m * a^n.
Real.sqrt_nonneg
The square root of any real number is non-negative.
Real.rpow_nonneg
Non-negative powers of non-negative reals are non-negative.
le_max_left
For any a and b in a linear order, a ≤ max a b.
le_max_right
For any a and b in a linear order, b ≤ max a b.
max_lt_iff
max a b < c is equivalent to a < c and b < c.
div_lt_div_of_pos_right
If a < b and c > 0, then a / c < b / c.
lt_div_iff₀
For positive c, a < b / c is equivalent to a * c < b.
pow_lt_pow_left₀
If 0 ≤ a < b and n > 0, then a^n < b^n.
mul_lt_mul_of_pos_right
If a < b and c > 0, then a * c < b * c.
lt_min
If a < b and a < c, then a < min b c.
nhdsWithin_le_nhds
The neighborhood within a subset is contained in the ambient neighborhood filter.
self_mem_nhdsWithin
The set s belongs to the filter of neighborhoods of x within s.
Iio_mem_nhds
The open interval (-∞, a) is a neighborhood of any point less than a.
min_le_left
For any a and b in a linear order, min a b ≤ a.
min_le_right
For any a and b in a linear order, min a b ≤ b.
Nat.floor_le
For any real number x, ⌊x⌋ ≤ x.
Nat.sub_one_lt_floor
For any real number x, x - 1 < ⌊x⌋.
in1284_code
Existence of the perturbed code C with controlled cardinality, non-overlapping property, and intersection bounds with optimal Blackburn codes.
in1284_real
Analytical lower bounds for perturbed Blackburn codes on code size and distance to optimal codes.
Nat.cast_sub
For a ≤ b in ℕ, (b - a : ℝ) = (b : ℝ) - (a : ℝ).
csInf_le
Every element of a set bounded below is greater than or equal to the infimum of the set.
in1284_le_two
The normalized symmetric difference between two length-(N+1) codes over an alphabet of size q is at most 2.
le_csInf
If every element of a non-empty set is at least a, then its infimum is at least a.
le_csSup
Every element of a set bounded above is at most the supremum of the set.
csSup_le
If every element of a non-empty set is at most a, then its supremum is at most a.
Filter.eventually_atTop
A property holds eventually at infinity on ℕ if and only if it holds for all sufficiently large n.
Filter.isBoundedUnder_of_eventually_le
If a sequence is eventually bounded above by a constant, it is bounded under the order at infinity.
tendsto_const_div_atTop_nhds_zero_nat
For any constant C, the sequence C / n tends to 0 as n tends to infinity.
Filter.limsup_le_limsup
If sequence u is eventually at most sequence v, then limsup u ≤ limsup v.
pow_two
For any element a in a monoid, a^2 = a * a.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

Lean’s trace was cut to the first 400 of 501 tactics.

lemma in1284_pi_card_le {N q : ℕ} (A : Fin (N+1) → Finset (Fin q)) (a c : ℕ)    (h1 : ∀ i : Fin N, (A i.castSucc).card ≤ a) (h2 : (A (Fin.last N)).card ≤ c) :    (Fintype.piFinset A).card ≤ a ^ N * c := by  rw [Fintype.card_piFinset, Fin.prod_univ_castSucc]  apply Nat.mul_le_mul _ h2  calc ∏ i : Fin N, (A i.castSucc).card ≤ ∏ _i : Fin N, a :=        Finset.prod_le_prod (fun i _ => Nat.zero_le _) (fun i _ => h1 i)    _ = a ^ N := by simplemma in1284_pi_card_eq {N q : ℕ} (A : Fin (N+1) → Finset (Fin q)) (a c : ℕ)    (h1 : ∀ i : Fin N, (A i.castSucc).card = a) (h2 : (A (Fin.last N)).card = c) :    (Fintype.piFinset A).card = a ^ N * c := by  rw [Fintype.card_piFinset, Fin.prod_univ_castSucc]  simp [h1, h2]lemma in1284_pi_card_eq' {N q : ℕ} (A : Fin (N+1) → Finset (Fin q)) (a c : ℕ)    (h1 : (A 0).card = c) (h2 : ∀ i : Fin N, (A i.succ).card = a) :    (Fintype.piFinset A).card = c * a ^ N := by  rw [Fintype.card_piFinset, Fin.prod_univ_succ]  simp [h1, h2]lemma in1284_binom (N : ℕ) (u : ℝ) (hu : 0 ≤ u) :    1 + N * u + (N * (N - 1) / 2) * u ^ 2 ≤ (1 + u) ^ N := by  induction N with  | zero => simp  | succ k ih =>    rw [pow_succ (1 + u) k]    push_cast    have h0 : 0 ≤ (k:ℝ) := by positivity    have h1 : 0 ≤ (k * (k - 1) / 2 : ℝ) * u ^ 3 := by      rcases Nat.eq_zero_or_pos k with rfl | hk      · simp      · have : (1:ℝ) ≤ k := by exact_mod_cast hk        have : 0 ≤ (k * (k - 1) / 2 : ℝ) := by nlinarith        positivity    nlinarith [mul_le_mul_of_nonneg_right ih (by linarith : (0:ℝ) ≤ 1 + u)]/-- the perturbed code: first `N` symbols in `S`, the last outside. -/lemma in1284_code (N m x : ℕ) (hN : 1 ≤ N) (hx : x ≤ m) :    ∃ C : Finset (Fin (N+1) → Fin (m * (N+1))),      C.card = (N * m + x) ^ N * (m - x) ∧      (∀ u ∈ C, ∀ v ∈ C, ∀ k : ℕ, 0 < k → k < N + 1 →        ∀ hk1 : k - 1 < N + 1, ∀ hk2 : N + 1 - k + (k - 1) < N + 1,          u ⟨k - 1, hk1⟩ ≠ v ⟨N + 1 - k + (k - 1), hk2⟩) ∧      ∀ B : Finset (Fin (N+1) → Fin (m * (N+1))),        (∃ (I : Finset (Fin (m * (N+1)))), (N + 1) * I.card = (N + 1 - 1) * (m * (N+1)) ∧          (B = Finset.filter (fun w => (∀ (i : Fin (N+1)), i.val < N + 1 - 1 → w i ∈ I) ∧            w ⟨N + 1 - 1, by omega⟩ ∉ I) Finset.univ ∨           B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧            (∀ (i : Fin (N+1)), 0 < i.val → w i ∈ I)) Finset.univ)) →        B.card = (N * m) ^ N * m ∧ (C ∩ B).card ≤ (N * m) ^ N * (m - x) := by  classical  obtain ⟨S, -, hS⟩ := Finset.exists_subset_card_eq    (s := (Finset.univ : Finset (Fin (m * (N+1))))) (n := N * m + x)    (by simp; nlinarith)  have hSc : Sᶜ.card = m - x := by    rw [Finset.card_compl, Fintype.card_fin, hS]    have : m * (N + 1) = N * m + m := by ring    omega  have hlast : ∀ h : N + 1 - 1 < N + 1, (⟨N + 1 - 1, h⟩ : Fin (N+1)) = Fin.last N :=    fun h => Fin.ext (by simp)  refine ⟨Fintype.piFinset (fun i : Fin (N+1) => if i.val < N then S else Sᶜ), ?_, ?_, ?_⟩  · apply in1284_pi_card_eq    · intro i; simp [hS]    · simp [hSc]  · intro u hu v hv k hk0 hkn hk1 hk2 he    rw [Fintype.mem_piFinset] at hu hv    have h1 := hu ⟨k - 1, hk1⟩    have h2 := hv ⟨N + 1 - k + (k - 1), hk2⟩    have e1 : k - 1 < N := by omega    have e2 : ¬ (N + 1 - k + (k - 1) < N) := by omega    simp only [e1, e2, if_true, if_false, Finset.mem_compl] at h1 h2    exact h2 (he ▸ h1)  · rintro B ⟨I, hI, hB⟩    have hIc : I.card = N * m := by      have : (N + 1 - 1) * (m * (N + 1)) = (N + 1) * (N * m) := by        rw [show N + 1 - 1 = N by omega]; ring      rw [this] at hI      exact Nat.eq_of_mul_eq_mul_left (by omega) hI    have hIcc : Iᶜ.card = m := by      rw [Finset.card_compl, Fintype.card_fin, hIc]      have : m * (N + 1) = N * m + m := by ring      omega    rcases hB with rfl | rfl    · constructor      · rw [show Finset.filter (fun w : Fin (N+1) → Fin (m * (N+1)) =>            (∀ (i : Fin (N+1)), i.val < N + 1 - 1 → w i ∈ I) ∧            w ⟨N + 1 - 1, by omega⟩ ∉ I) Finset.univ            = Fintype.piFinset (fun i : Fin (N+1) => if i.val < N then I else Iᶜ) by          ext w          simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset]          constructor          · rintro ⟨h1, h2⟩ i            split_ifs with h            · exact h1 i (by omega)            · have : i = ⟨N + 1 - 1, by omega⟩ := Fin.ext (by simp; omega)              rw [this, Finset.mem_compl]; exact h2          · intro h            refine ⟨fun i hi => ?_, ?_⟩            · have := h i              rwa [if_pos (by omega)] at this            · have := h ⟨N + 1 - 1, by omega⟩              rw [if_neg (by simp)] at this              exact Finset.mem_compl.1 this]        apply in1284_pi_card_eq        · intro i; simp [hIc]        · simp [hIcc]      · refine (Finset.card_le_card (t := Fintype.piFinset          (fun i : Fin (N+1) => if i.val < N then I else Sᶜ)) ?_).trans ?_        · intro w hw          simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and,            Fintype.mem_piFinset] at hw ⊢          intro i          split_ifs with h          · exact hw.2.1 i (by omega)          · have := hw.1 i            rwa [if_neg h] at this        · apply in1284_pi_card_le          · intro i; simp [hIc]          · simp [hSc]    · constructor      · rw [show Finset.filter (fun w : Fin (N+1) → Fin (m * (N+1)) => w ⟨0, by omega⟩ ∉ I ∧            (∀ (i : Fin (N+1)), 0 < i.val → w i ∈ I)) Finset.univ            = Fintype.piFinset (fun i : Fin (N+1) => if i.val = 0 then Iᶜ else I) by          ext w          simp only [Finset.mem_filter, Finset.mem_univ, true_and, Fintype.mem_piFinset]          constructor          · rintro ⟨h1, h2⟩ i            split_ifs with h            · have : i = ⟨0, by omega⟩ := Fin.ext h              rw [this, Finset.mem_compl]; exact h1            · exact h2 i (by omega)          · intro h            refine ⟨?_, fun i hi => ?_⟩            · have := h ⟨0, by omega⟩              rw [if_pos rfl] at this              exact Finset.mem_compl.1 this            · have := h i              rwa [if_neg (by omega)] at this]        rw [in1284_pi_card_eq' _ (N * m) m]        · ring        · simp [hIcc]        · intro i; simp [hIc]      · refine (Finset.card_le_card (t := Fintype.piFinset          (fun i : Fin (N+1) => if i.val = 0 then Iᶜ else if i.val < N then I else Sᶜ)) ?_).trans ?_        · intro w hw          simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and,            Fintype.mem_piFinset] at hw ⊢          intro i          split_ifs with h h'          · have : i = ⟨0, by omega⟩ := Fin.ext h            rw [this, Finset.mem_compl]; exact hw.2.1          · exact hw.2.2 i (by omega)          · have := hw.1 i            rwa [if_neg h'] at this        · apply in1284_pi_card_le          · intro i            by_cases h : (i.castSucc : Fin (N+1)).val = 0            · rw [if_pos h, hIcc]              nlinarith            · rw [if_neg h, if_pos (by simp)]              simp [hIc]          · have h1 : ¬ ((Fin.last N : Fin (N+1)).val = 0) := by simp; omega            rw [if_neg h1, if_neg (by simp), hSc]lemma in1284_real (N m x : ℕ) (hN : 1 ≤ N) (hm : 1 ≤ m) (hxm : x ≤ m) (c ε s θ : ℝ)    (hc : c * ((m:ℝ) * (N + 1)) ^ (N + 1) = ((N:ℝ) * m) ^ N * m) (hc0 : 0 < c)    (hs : 0 ≤ s) (hε : ε = s ^ 2) (hθ : 0 ≤ θ)    (hcond : c * (N * (N + 1) / 2) * θ ^ 2 + c * (N * (N - 1) / 2) * N * θ ^ 3 * s ≤ 1)    (hxle : (x:ℝ) ≤ θ * s * N * m) (hxge : θ * s * N * m - 1 < x) :    (c - ε) * ((m:ℝ) * (N + 1)) ^ (N + 1) ≤ ((N:ℝ) * m + x) ^ N * ((m:ℝ) - x) ∧    ∀ D CB : ℝ, D + 2 * CB = ((N:ℝ) * m + x) ^ N * ((m:ℝ) - x) + ((N:ℝ) * m) ^ N * m →      CB ≤ ((N:ℝ) * m) ^ N * ((m:ℝ) - x) →      2 * c * N * θ * s - ε - 2 * c / m ≤ D / ((m:ℝ) * (N + 1)) ^ (N + 1) := by  have hNR : (1:ℝ) ≤ N := by exact_mod_cast hN  have hmR : (1:ℝ) ≤ m := by exact_mod_cast hm  have hxmR : (x:ℝ) ≤ m := by exact_mod_cast hxm  have hx0 : (0:ℝ) ≤ x := by positivity  set Q : ℝ := (N:ℝ) * m with hQ  have hQ0 : 0 < Q := by positivity  set T : ℝ := ((m:ℝ) * (N + 1)) ^ (N + 1) with hT  have hT0 : 0 < T := by positivity  set u : ℝ := x / Q with hu  have hu0 : 0 ≤ u := by positivity  have hQu : Q + x = Q * (1 + u) := by rw [hu]; field_simp  have hmu : (m:ℝ) - x = m * (1 - N * u) := by    rw [hu, hQ]; field_simp  have hNu : N * u ≤ 1 := by    rw [hu, hQ, mul_div_assoc', div_le_one (by positivity)]    nlinarith  have huθ : u ≤ θ * s := by    rw [hu, div_le_iff₀ hQ0, hQ]; nlinarith  have hbin := in1284_binom N u hu0  set A : ℝ := (N * (N + 1) / 2)  set Dd : ℝ := (N * (N - 1) / 2)  have hDd : 0 ≤ Dd := by    have : 0 ≤ (N:ℝ) - 1 := by linarith    positivity  have hP : Q ^ N * m * (1 - A * u ^ 2 - Dd * N * u ^ 3) ≤ (Q + x) ^ N * ((m:ℝ) - x) := by    rw [hQu, hmu, mul_pow Q (1 + u) N]    have h1 : (1 - A * u ^ 2 - Dd * N * u ^ 3) = (1 + N * u + Dd * u ^ 2) * (1 - N * u) := by      simp only [A, Dd]; ring    rw [h1]    have h2 : 0 ≤ 1 - N * u := by linarith    have h3 : 0 ≤ Q ^ N * m := by positivity    calc Q ^ N * m * ((1 + N * u + Dd * u ^ 2) * (1 - N * u))        = Q ^ N * m * (1 - N * u) * (1 + N * u + Dd * u ^ 2) := by ring      _ ≤ Q ^ N * m * (1 - N * u) * (1 + u) ^ N := by          apply mul_le_mul_of_nonneg_left hbin; positivity      _ = Q ^ N * (1 + u) ^ N * (m * (1 - N * u)) := by ring  have hsmall : c * (A * u ^ 2 + Dd * N * u ^ 3) ≤ ε := by    have hA0 : 0 ≤ A := by positivity    have e1 : u ^ 2 ≤ (θ * s) ^ 2 := pow_le_pow_left₀ hu0 huθ 2    have e2 : u ^ 3 ≤ (θ * s) ^ 3 := pow_le_pow_left₀ hu0 huθ 3    have e3 : c * (A * u ^ 2 + Dd * N * u ^ 3) ≤ c * (A * (θ * s) ^ 2 + Dd * N * (θ * s) ^ 3) := by      apply mul_le_mul_of_nonneg_left _ hc0.le      have : 0 ≤ Dd * N := by positivity      nlinarith    have e4 : c * (A * (θ * s) ^ 2 + Dd * N * (θ * s) ^ 3)        = s ^ 2 * (c * A * θ ^ 2 + c * Dd * N * θ ^ 3 * s) := by ring    have e5 : s ^ 2 * (c * A * θ ^ 2 + c * Dd * N * θ ^ 3 * s) ≤ s ^ 2 * 1 :=      mul_le_mul_of_nonneg_left hcond (sq_nonneg s)    rw [hε]    linarith  have hPT : Q ^ N * m - ε * T ≤ (Q + x) ^ N * ((m:ℝ) - x) := by    have : Q ^ N * m * (A * u ^ 2 + Dd * N * u ^ 3) ≤ ε * T := by      rw [← hc]      calc c * T * (A * u ^ 2 + Dd * N * u ^ 3) = T * (c * (A * u ^ 2 + Dd * N * u ^ 3)) := by ring        _ ≤ T * ε := mul_le_mul_of_nonneg_left hsmall hT0.le        _ = ε * T := by ring    have e6 : Q ^ N * m * (1 - A * u ^ 2 - Dd * N * u ^ 3)        = Q ^ N * m - Q ^ N * m * (A * u ^ 2 + Dd * N * u ^ 3) := by ring    linarith  have hcT : c * T = Q ^ N * m := hc  refine ⟨by have e7 : (c - ε) * T = c * T - ε * T := by ring             linarith, ?_⟩  intro D CB hD hCB  rw [le_div_iff₀ hT0]  have hcm : c * T = Q ^ N * m := hc  have hQx : 2 * c * N * θ * s * T - 2 * c / m * T ≤ 2 * Q ^ N * x := by    have : 2 * c / m * T = 2 * Q ^ N := by      field_simp      linarith [hcm]    rw [this]    have h5 : 2 * c * N * θ * s * T = 2 * Q ^ N * (θ * s * N * m) := by      have : 2 * c * N * θ * s * T = 2 * (c * T) * (θ * s * N) := by ring      rw [this, hcm]; ring    rw [h5]    have : 0 ≤ 2 * Q ^ N := by positivity    nlinarith  have hQm : Q ^ N * ((m:ℝ) - x) = Q ^ N * m - Q ^ N * x := by ring  have e8 : (2 * c * N * θ * s - ε - 2 * c / m) * T      = 2 * c * N * θ * s * T - ε * T - 2 * c / m * T := by ring  linarithlemma in1284_symm {α : Type*} [DecidableEq α] (C B : Finset α) :    (symmDiff C B).card + 2 * (C ∩ B).card = C.card + B.card := by  rw [symmDiff_def, Finset.sup_eq_union, Finset.card_union_of_disjoint disjoint_sdiff_sdiff]  have h1 := Finset.card_sdiff_add_card_inter C B  have h2 := Finset.card_sdiff_add_card_inter B C  rw [Finset.inter_comm] at h2  omegalemma in1284_le_two {N q : ℕ} (hq : 0 < q) (C B : Finset (Fin (N+1) → Fin q)) :    ((symmDiff C B).card : ℝ) / (q : ℝ) ^ (N + 1) ≤ 2 := by  have h := in1284_symm C B  have hC : C.card ≤ q ^ (N + 1) := by    simpa [Fintype.card_fun] using Finset.card_le_univ C  have hB : B.card ≤ q ^ (N + 1) := by    simpa [Fintype.card_fun] using Finset.card_le_univ B  have h3 : (symmDiff C B).card ≤ 2 * q ^ (N + 1) := by omega  have h4 : ((symmDiff C B).card : ℝ) ≤ 2 * (q : ℝ) ^ (N + 1) := by exact_mod_cast h3  rw [div_le_iff₀ (by positivity)]  linariththeorem op2468_blackburn_stability_lower_bound_eventually (n : ℕ) (hn : 2 ≤ n) :    let lam : ℝ := (n - 1 : ℝ) / n    let c_n : ℝ := lam ^ (n - 1) / (n : ℝ)    let K_n : ℝ := 2 * Real.sqrt (2 / (n - 1 : ℝ)) * lam ^ (((n : ℝ) + 1) / 2)    let is_nonoverlapping (q : ℕ) (C : Finset (Fin n → Fin q)) : Prop :=      ∀ u ∈ C, ∀ v ∈ C, ¬ ∃ (k : ℕ) (_ : 0 < k) (_ : k < n),        ∀ i : Fin k, u ⟨i.val, by omega⟩ = v ⟨n - k + i.val, by omega⟩    let optimal_blackburn (q : ℕ) : Set (Finset (Fin n → Fin q)) :=      { B | ∃ (I : Finset (Fin q)), n * I.card = (n - 1) * q ∧        (B = Finset.filter (fun w => (∀ (i : Fin n), i.val < n - 1 → w i ∈ I) ∧          w ⟨n - 1, by omega⟩ ∉ I) Finset.univ ∨         B = Finset.filter (fun w => w ⟨0, by omega⟩ ∉ I ∧          (∀ (i : Fin n), 0 < i.val → w i ∈ I)) Finset.univ) }    let code_dist (q : ℕ) (C : Finset (Fin n → Fin q)) : ℝ :=      sInf { ((symmDiff C B).card : ℝ) / (q : ℝ) ^ n | B ∈ optimal_blackburn q }    let max_dist (q : ℕ) (ε : ℝ) : ℝ :=      sSup { d | ∃ C : Finset (Fin n → Fin q),        is_nonoverlapping q C ∧ (c_n - ε) * (q : ℝ) ^ n ≤ C.card ∧ d = code_dist q C }    let M (ε : ℝ) : ℝ :=      Filter.limsup (fun m : ℕ => max_dist (m * n) ε) Filter.atTop    ∀ η : ℝ, 0 < η → ∀ᶠ ε in nhdsWithin (0 : ℝ) (Set.Ioi 0), (K_n - η) * Real.sqrt ε ≤ M ε := by  obtain ⟨N, rfl⟩ : ∃ N, n = N + 1 := ⟨n - 1, by omega⟩  have hN : 1 ≤ N := by omega  intro lam c_n K_n is_nonoverlapping optimal_blackburn code_dist max_dist M η hη  have hNR : (1:ℝ) ≤ N := by exact_mod_cast hN  have hN1 : (0:ℝ) < (N:ℝ) + 1 := by positivity  have hlam : lam = (N:ℝ) / (N + 1) := by    show (((N + 1 : ℕ) : ℝ) - 1) / ((N + 1 : ℕ) : ℝ) = _    push_cast; ring  have hlam0 : 0 < lam := by rw [hlam]; positivity  have hc : c_n = lam ^ N / (N + 1) := by    show lam ^ (N + 1 - 1) / ((N + 1 : ℕ) : ℝ) = _    rw [Nat.add_sub_cancel]; push_cast; ring  have hc0 : 0 < c_n := by rw [hc]; positivity  have hcT : ∀ m : ℕ, c_n * ((m:ℝ) * (N + 1)) ^ (N + 1) = ((N:ℝ) * m) ^ N * m := by    intro m    rw [hc, hlam, div_pow, mul_pow, mul_pow, pow_succ ((N:ℝ) + 1)]    field_simp    ring  have hK2 : K_n ^ 2 * (N + 1) = 8 * c_n * N := by    have hr : (lam ^ ((((N + 1 : ℕ) : ℝ) + 1) / 2)) ^ 2 = lam ^ (N + 2) := by      rw [← Real.rpow_mul_natCast hlam0.le]      rw [show (((N + 1 : ℕ) : ℝ) + 1) / 2 * ((2 : ℕ) : ℝ) = ((N + 2 : ℕ) : ℝ) by        push_cast; ring]      exact Real.rpow_natCast _ _    have hs2 : (Real.sqrt (2 / (((N + 1 : ℕ) : ℝ) - 1))) ^ 2 = 2 / N := by      rw [Real.sq_sqrt (by push_cast; simp only [add_sub_cancel_right]; positivity)]      push_cast; ring    show (2 * Real.sqrt (2 / (((N + 1 : ℕ) : ℝ) - 1)) *      lam ^ ((((N + 1 : ℕ) : ℝ) + 1) / 2)) ^ 2 * (N + 1) = 8 * c_n * N    rw [mul_pow, mul_pow, hs2, hr, hc, pow_add, hlam]    have : (N:ℝ) ≠ 0 := by positivity    field_simp    ring  have hK0' : 0 ≤ K_n := by    show 0 ≤ 2 * Real.sqrt (2 / (((N + 1 : ℕ) : ℝ) - 1)) * lam ^ ((((N + 1 : ℕ) : ℝ) + 1) / 2)    exact mul_nonneg (mul_nonneg (by norm_num) (Real.sqrt_nonneg _))      (Real.rpow_nonneg hlam0.le _)  have hK0 : 0 < K_n := by    rcases hK0'.lt_or_eq with h | h    · exact h    · exfalso      rw [← h] at hK2      have : 0 < 8 * c_n * N := by positivity      linarith [show (0:ℝ) ^ 2 * (N + 1) = 0 by ring]  have hcN : 0 < 2 * c_n * N := by positivity  set θ : ℝ := max 0 ((K_n - η / 2) / (2 * c_n * N)) with hθdef  have hθ0 : 0 ≤ θ := le_max_left _ _  have hθ1 : K_n - η / 2 ≤ 2 * c_n * N * θ := by    have := le_max_right 0 ((K_n - η / 2) / (2 * c_n * N))    rw [← hθdef] at this    rw [div_le_iff₀ hcN] at this    linarith  have hθ2 : 2 * c_n * N * θ < K_n := by    have : θ < K_n / (2 * c_n * N) := by      rw [hθdef, max_lt_iff]      exact ⟨by positivity, by apply div_lt_div_of_pos_right _ hcN; linarith⟩    rw [lt_div_iff₀ hcN] at this    linarith  have hA : c_n * (N * (N + 1) / 2) * θ ^ 2 < 1 := by    have hsq : (2 * c_n * N * θ) ^ 2 < K_n ^ 2 :=      pow_lt_pow_left₀ hθ2 (by positivity) (by norm_num)    have h := mul_lt_mul_of_pos_right hsq hN1    have h8 : 0 < 8 * c_n * N := by positivity    have e : 8 * c_n * N * (c_n * (N * (N + 1) / 2) * θ ^ 2) = (2 * c_n * N * θ) ^ 2 * (N + 1) := by      ring    by_contra hcon    push_neg at hcon    have := mul_le_mul_of_nonneg_left hcon h8.le    linarith  set γ : ℝ := 1 - c_n * (N * (N + 1) / 2) * θ ^ 2 with hγ  have hγ0 : 0 < γ := by linarith  set β : ℝ := c_n * (N * (N - 1) / 2) * N * θ ^ 3 with hβ  have hβ0 : 0 ≤ β := by    have : 0 ≤ (N:ℝ) - 1 := by linarith    positivity  set r : ℝ := min (η / 2) (min (γ / (β + 1)) (1 / (θ * N + 1))) with hr  have hr0 : 0 < r := by    apply lt_min (by positivity) (lt_min (by positivity) (by positivity))  have hlim : Filter.Tendsto (fun ε : ℝ => Real.sqrt ε) (nhdsWithin 0 (Set.Ioi 0)) (nhds 0) := by    have := (Real.continuous_sqrt.tendsto 0).mono_left      (nhdsWithin_le_nhds (s := Set.Ioi (0:ℝ)))    simpa using this  filter_upwards [self_mem_nhdsWithin, hlim (Iio_mem_nhds hr0)] with ε hε hsr  simp only [Set.mem_Ioi] at hε  simp only [Set.mem_preimage, Set.mem_Iio] at hsr  set s := Real.sqrt ε with hsdef  have hs0 : 0 ≤ s := Real.sqrt_nonneg ε  have hεs : ε = s ^ 2 := (Real.sq_sqrt hε.le).symm  have hs1 : s ≤ η / 2 := le_trans hsr.le (min_le_left _ _)  have hs2 : s ≤ γ / (β + 1) := le_trans hsr.le ((min_le_right _ _).trans (min_le_left _ _))  have hs3 : s ≤ 1 / (θ * N + 1) := le_trans hsr.le ((min_le_right _ _).trans (min_le_right _ _))  have hcond : c_n * (N * (N + 1) / 2) * θ ^ 2 + c_n * (N * (N - 1) / 2) * N * θ ^ 3 * s ≤ 1 := by    rw [le_div_iff₀ (by positivity)] at hs2    have : β * s ≤ γ := by nlinarith    rw [hβ] at this    linarith  have hθs : θ * s * N ≤ 1 := by    rw [le_div_iff₀ (by positivity)] at hs3    nlinarith  -- per m  have hmd : ∀ m : ℕ, 1 ≤ m →      2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ max_dist (m * (N + 1)) ε ∧      max_dist (m * (N + 1)) ε ≤ 2 := by    intro m hm    classical    have hmR : (1:ℝ) ≤ m := by exact_mod_cast hm    have hq : 0 < m * (N + 1) := by positivity    set x := ⌊θ * s * N * m⌋₊ with hxdef    have hxle : (x:ℝ) ≤ θ * s * N * m := Nat.floor_le (by positivity)    have hxge : θ * s * N * m - 1 < x := Nat.sub_one_lt_floor _    have hxm : x ≤ m := by      have : (x:ℝ) ≤ m := by nlinarith      exact_mod_cast this    obtain ⟨C, hCc, hCno, hCB⟩ := in1284_code N m x hN hxm    obtain ⟨h1, h2⟩ := in1284_real N m x hN hm hxm c_n ε s θ (hcT m) hc0 hs0 hεs hθ0      hcond hxle hxge    have hC1 : is_nonoverlapping (m * (N + 1)) C := by      rintro u hu v hv ⟨k, hk0, hk2, hk⟩      exact hCno u hu v hv k hk0 hk2 (by omega) (by omega) (hk ⟨k - 1, by omega⟩)    have hC2 : (c_n - ε) * (((m * (N + 1) : ℕ) : ℝ)) ^ (N + 1) ≤ C.card := by      rw [hCc]      push_cast [Nat.cast_sub hxm]      exact h1    obtain ⟨I0, -, hI0⟩ := Finset.exists_subset_card_eq      (s := (Finset.univ : Finset (Fin (m * (N + 1))))) (n := N * m)      (by rw [Finset.card_univ, Fintype.card_fin, Nat.mul_comm m, Nat.add_mul, Nat.one_mul]          exact Nat.le_add_right _ _)    have hB0 : Finset.filter (fun w : Fin (N + 1) → Fin (m * (N + 1)) =>        (∀ (i : Fin (N + 1)), i.val < N + 1 - 1 → w i ∈ I0) ∧          w ⟨N + 1 - 1, by omega⟩ ∉ I0) Finset.univ ∈ optimal_blackburn (m * (N + 1)) :=      ⟨I0, by rw [hI0, show N + 1 - 1 = N by omega]; ring, Or.inl rfl⟩    have hcd2 : ∀ C' : Finset (Fin (N + 1) → Fin (m * (N + 1))), code_dist (m * (N + 1)) C' ≤ 2 := by      intro C'      refine le_trans (csInf_le ⟨0, ?_⟩ ⟨_, hB0, rfl⟩) (in1284_le_two hq C' _)      rintro _ ⟨B, -, rfl⟩      exact div_nonneg (Nat.cast_nonneg _) (pow_nonneg (Nat.cast_nonneg _) _)    have hcdl : 2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ code_dist (m * (N + 1)) C := by      apply le_csInf      · exact ⟨_, _, hB0, rfl⟩      rintro _ ⟨B, hB, rfl⟩      obtain ⟨hBc, hCBc⟩ := hCB B hB      have hid := in1284_symm C B      have hid' : ((symmDiff C B).card : ℝ) + 2 * ((C ∩ B).card : ℝ)          = ((N:ℝ) * m + x) ^ N * ((m:ℝ) - x) + ((N:ℝ) * m) ^ N * m := by        have : ((symmDiff C B).card : ℝ) + 2 * ((C ∩ B).card : ℝ) = C.card + B.card := by          exact_mod_cast hid        rw [this, hCc, hBc]        push_cast [Nat.cast_sub hxm]        ring      have hCB' : ((C ∩ B).card : ℝ) ≤ ((N:ℝ) * m) ^ N * ((m:ℝ) - x) := by        have : ((C ∩ B).card : ℝ) ≤ (((N * m) ^ N * (m - x) : ℕ) : ℝ) := by exact_mod_cast hCBc        push_cast [Nat.cast_sub hxm] at this        exact this      have := h2 _ _ hid' hCB'      push_cast      exact this    have hmem : code_dist (m * (N + 1)) C ∈ {d | ∃ C : Finset (Fin (N + 1) → Fin (m * (N + 1))),        is_nonoverlapping (m * (N + 1)) C ∧          (c_n - ε) * (((m * (N + 1) : ℕ) : ℝ)) ^ (N + 1) ≤ C.card ∧            d = code_dist (m * (N + 1)) C} := ⟨C, hC1, hC2, rfl⟩    have hub : ∀ d ∈ {d | ∃ C : Finset (Fin (N + 1) → Fin (m * (N + 1))),        is_nonoverlapping (m * (N + 1)) C ∧          (c_n - ε) * (((m * (N + 1) : ℕ) : ℝ)) ^ (N + 1) ≤ C.card ∧            d = code_dist (m * (N + 1)) C}, d ≤ 2 := by      rintro _ ⟨C', -, -, rfl⟩      exact hcd2 C'    exact ⟨hcdl.trans (le_csSup ⟨2, hub⟩ hmem), csSup_le ⟨_, hmem⟩ hub⟩  have hev : ∀ᶠ m : ℕ in Filter.atTop,      2 * c_n * N * θ * s - ε - 2 * c_n / m ≤ max_dist (m * (N + 1)) ε ∧      max_dist (m * (N + 1)) ε ≤ 2 :=    Filter.eventually_atTop.2 ⟨1, fun m hm => hmd m hm⟩  have hbu : Filter.IsBoundedUnder (· ≤ ·) Filter.atTop      (fun m : ℕ => max_dist (m * (N + 1)) ε) :=    Filter.isBoundedUnder_of_eventually_le (hev.mono fun m h => h.2)  have hg : Filter.Tendsto (fun m : ℕ => 2 * c_n * N * θ * s - ε - 2 * c_n / m)      Filter.atTop (nhds (2 * c_n * N * θ * s - ε)) := by    have h0 : Filter.Tendsto (fun m : ℕ => (2 * c_n) / (m : ℝ)) Filter.atTop (nhds 0) :=      tendsto_const_div_atTop_nhds_zero_nat (2 * c_n)    simpa using h0.const_sub (2 * c_n * N * θ * s - ε)  have hl := Filter.limsup_le_limsup (hev.mono fun m h => h.1) hg.isCoboundedUnder_le hbu  rw [hg.limsup_eq] at hl  have hM : 2 * c_n * N * θ * s - ε ≤ M ε := hl  have e1 := mul_le_mul_of_nonneg_right hθ1 hs0  have e2 : ε ≤ η / 2 * s := by    rw [hεs, pow_two]    exact mul_le_mul_of_nonneg_right hs1 hs0  have e3 : (K_n - η) * s = (K_n - η / 2) * s - η / 2 * s := by ring  linarith
See it in the graphDiscuss this resultChallenge it