Skip to main content
AlexKontorovich/PrimeNumberTheoremAnd
Source indexedtheorem · leanprover/lean4:v4.32.0

Erdos392.Solution_1

PrimeNumberTheoremAnd.IEANTN.Erdos392 · PrimeNumberTheoremAnd/IEANTN/Erdos392.lean:3008 to 3083

Mathematical statement

Exact Lean statement

@[blueprint
  "erdos-sol-1"
  (statement := /-- One can find a balanced factorization of $n!$ with cardinality at most
  $n - n / \log n + o(n / \log n)$.--/)
  (proof := /-- Combine Proposition \ref{initial-score} with Proposition \ref{card-bound} and
  the Stirling approximation.-/)
  (latexEnv := "theorem")
  (discussion := 648)]
theorem Solution_1 (ε : ℝ) (hε : ε > 0) : ∀ᶠ n in .atTop, ∃ f : Factorization n,
    f.total_imbalance = 0 ∧ f.a.card ≤ n - n / Real.log n + ε * n / Real.log n

Complete declaration

Lean source

Canonical source
Full Lean sourceLean 4
@[blueprint  "erdos-sol-1"  (statement := /-- One can find a balanced factorization of $n!$ with cardinality at most  $n - n / \log n + o(n / \log n)$.--/)  (proof := /-- Combine Proposition \ref{initial-score} with Proposition \ref{card-bound} and  the Stirling approximation.-/)  (latexEnv := "theorem")  (discussion := 648)]theorem Solution_1 (ε : ) (hε : ε > 0) : ᶠ n in .atTop,  f : Factorization n,    f.total_imbalance = 0  f.a.card  n - n / Real.log n + ε * n / Real.log n := by  have h_stirling : ᶠ n :  in .atTop,      log (n ! : )  n * Real.log n - n +/ 4) * n := by    have h_ratio : Filter.Tendsto        (fun n :   (n ! : ) / (sqrt (2 * n * π) * (n / exp 1) ^ n))        .atTop (nhds 1) := by      have h := Stirling.factorial_isEquivalent_stirling      rw [isEquivalent_iff_tendsto_one] at h      · exact h      · filter_upwards [Filter.eventually_gt_atTop 0] with n hn; positivity    have h_ratio_le : ᶠ n :  in .atTop,        (n ! : ) / (sqrt (2 * n * π) * (n / exp 1) ^ n)  2 :=      h_ratio.eventually (Metric.ball_mem_nhds 1 one_pos) |>.mono fun n hn  by        simp only [Real.dist_eq] at hn; linarith [abs_sub_lt_iff.mp hn]    have h_log_o := isLittleO_log_id_atTop.def (by linarith : (0 : ) < ε / 16)    have h_const : ᶠ n :  in .atTop, Real.log 2 + log (2 * π) / 2 / 16) * n := by      let c := Real.log 2 + log (2 * π) / 2      filter_upwards [Filter.eventually_ge_atTop (ceil (c // 16)) + 1)] with n hn      calc c =/ 16) * (c // 16)) := by field_simp        _ / 16) * (ceil (c // 16)) + 1) := by            gcongr; exact (le_ceil _).trans (le_add_of_nonneg_right (by norm_num))        _ / 16) * n := by gcongr; exact_mod_cast hn    filter_upwards [h_ratio_le, h_log_o.natCast_atTop, h_const, Filter.eventually_gt_atTop 0]      with n h_rat h_logn h_c hn_pos    have hn : (0 : ) < n := cast_pos.mpr hn_pos    have h_fact : (n ! : )  2 * sqrt (2 * n * π) * (n / exp 1) ^ n := by      calc (n ! : ) = (n ! : ) / (sqrt (2 * n * π) * (n / exp 1) ^ n) *      have h_denom_pos : sqrt (2 * n * π) * (n / exp 1) ^ n > 0 := by positivity              (sqrt (2 * n * π) * (n / exp 1) ^ n) := by field_simp        _  2 * (sqrt (2 * n * π) * (n / exp 1) ^ n) := by gcongr        _ = 2 * sqrt (2 * n * π) * (n / exp 1) ^ n := by ring    simp only [id, norm_eq_abs] at h_logn    have hn1 : (1 : )  n := by      exact_mod_cast one_le_iff_ne_zero.mpr (pos_iff_ne_zero.mp hn_pos)    rw [abs_of_nonneg (Real.log_nonneg hn1), abs_of_nonneg hn.le] at h_logn    have h2npi : (0 : ) < 2 * n * π := by positivity    have h2pi : (0 : ) < 2 * π := by positivity    have hsqrt : sqrt (2 * n * π) > 0 := by positivity    have hpow : (n / exp 1 : ) ^ n > 0 := by positivity    calc Real.log (n ! : )         log (2 * sqrt (2 * n * π) * (n / exp 1) ^ n) := log_le_log (by positivity) h_fact      _ = Real.log 2 + log (2 * n * π) / 2 + n * Real.log n - n := by        rw [show (2 : ) * sqrt (2 * n * π) * (n / exp 1) ^ n =              2 * (sqrt (2 * n * π) * (n / exp 1) ^ n) by ring, log_mul (by norm_num)                (mul_pos hsqrt hpow).ne', log_mul hsqrt.ne' hpow.ne', sqrt_eq_rpow, log_rpow h2npi,                  Real.log_pow, log_div hn.ne' (exp_pos 1).ne', log_exp]        ring      _ = Real.log 2 + Real.log (2 * π) / 2 + Real.log n / 2 + n * Real.log n - n := by          have : Real.log (2 * n * π) = Real.log (2 * π) + Real.log n := by            rw [show (2 : ) * n * π = 2 * π * n by ring, log_mul h2pi.ne' hn.ne']          linarith [this]      _ / 16) * n +/ 16) * n / 2 + n * Real.log n - n := by gcongr      _ = n * Real.log n - n + (3 * ε / 32) * n := by ring      _  n * Real.log n - n +/ 4) * n := by nlinarith  filter_upwards [Params.initial.score/ 2) (by linarith),    h_stirling, Filter.eventually_gt_atTop 1]    with n P, hPn, hP_score h_stir hn  obtain f, hf_bal, hf_card := Factorization.card_bound P.initial P.L  subst hPn  refine f, hf_bal, ?_  have hlogn_pos : Real.log P.n > 0 := Real.log_pos (by exact_mod_cast hn)  calc (f.a.card : )       (Real.log P.n.factorial + P.initial.score P.L) / Real.log P.n := by          rw [le_div_iff₀ hlogn_pos]; exact hf_card    _  (P.n * Real.log P.n - P.n +/ 4) * P.n +/ 2) * P.n) / Real.log P.n := by gcongr    _ = P.n - P.n / Real.log P.n + (3 * ε / 4) * P.n / Real.log P.n := by field_simp; ring    _  P.n - P.n / Real.log P.n + ε * P.n / Real.log P.n := by gcongr; linarith