Lean / Reader
Lean reader

Exact447.lean

81 lines11 declarationsno sorryimports ThresholdWitnesses Mathlib.Data.Nat.Factorization.Basic Mathlib.Data.Nat.Factorial.BigOperators

Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports ThresholdWitnesses, which it does not have: you can read it there, but it will not check. Build the project itself to check it.

  1. import ThresholdWitnesses
  2. import Mathlib.Data.Nat.Factorization.Basic
  3. import Mathlib.Data.Nat.Factorial.BigOperators
  4. namespace FactorialThresholds
  5. open Finset
  6. private theorem score_prod (w : ℕ → ℤ) (one : w 1 = 0)
  7. (mul : ∀ a b, a ≠ 0 → b ≠ 0 → w (a*b)=w a+w b) (A : Finset ℕ)
  8. (pos : ∀ a ∈ A, 0<a) : w (∏ a ∈ A,a) = ∑ a ∈ A, w a := by
  9. induction A using Finset.induction_on with
  10. | empty => simpa using one
  11. | @insert a A fresh ih =>
  12. have hpos : ∀ b∈A,0<b := fun b hb => pos b (mem_insert_of_mem hb)
  13. rw [prod_insert fresh,sum_insert fresh,mul,ih hpos]
  14. · exact (pos a (mem_insert_self _ _)).ne'
  15. · exact (Finset.prod_pos hpos).ne'
  16. private theorem score_factorial (w : ℕ → ℤ) (one : w 1 = 0)
  17. (mul : ∀ a b, a ≠ 0 → b ≠ 0 → w (a*b)=w a+w b) (n : ℕ) :
  18. w n.factorial = ∑ i ∈ range n, w (i+1) := by
  19. induction n with
  20. | zero => simpa using one
  21. | succ n ih =>
  22. rw [Nat.factorial_succ,mul _ _ (by omega) (Nat.factorial_ne_zero _),ih,sum_range_succ,add_comm]
  23. /-- Every nonnegative additive valuation score on the interval must supply
  24. at least the score required by the factorial. -/
  25. theorem valuation_obstruction (n m : ℕ) (w : ℕ → ℤ) (one : w 1=0)
  26. (mul : ∀ a b, a ≠ 0 → b ≠ 0 → w (a*b)=w a+w b)
  27. (nonneg : ∀ a ∈ Ioc n m, 0≤w a)
  28. (short : (∑ a ∈ Ioc n m, w a) < ∑ i ∈ range n, w (i+1)) : ¬ Fits n m := by
  29. rintro ⟨xs,nodup,inside,target⟩
  30. let S := xs.toFinset
  31. have sub : S ⊆ Ioc n m := by simpa [S,Finset.subset_iff] using inside
  32. have pos : ∀ a∈S,0<a := fun a ha => (mem_Ioc.mp (sub ha)).1.trans_le' (Nat.zero_le n)
  33. have ep : (∏ a ∈ S,a) = n.factorial := by
  34. have e := List.prod_toFinset id nodup
  35. simpa [S] using e.trans (by simpa using target)
  36. have eq := score_prod w one mul S pos
  37. rw [ep,score_factorial w one mul] at eq
  38. have le : (∑ a ∈ S,w a) ≤ ∑ a ∈ Ioc n m,w a :=
  39. Finset.sum_le_sum_of_subset_of_nonneg sub (fun a ha _ => nonneg a ha)
  40. omega
  41. private def ps : List ℕ := [227,229,233,239,241,251,257,263,269,271,277,281,283,293]
  42. private def negScore (ps : List ℕ) (x : ℕ) : ℤ :=
  43. (ps.map (fun p => (x.primeFactorsList.count p : ℤ))).sum
  44. private def score447 (x : ℕ) : ℤ :=
  45. x.primeFactorsList.count 2 + (x.primeFactorsList.count 3 : ℤ) - negScore ps x
  46. private theorem counts_mul {a b : ℕ} (p : ℕ) (ha : a≠0) (hb : b≠0) :
  47. ((a*b).primeFactorsList.count p : ℤ) = a.primeFactorsList.count p + (b.primeFactorsList.count p : ℤ) := by
  48. simp [Nat.factorization_mul ha hb]
  49. private theorem neg_mul {a b : ℕ} (ha : a≠0) (hb : b≠0) (ps : List ℕ) :
  50. negScore ps (a*b) = negScore ps a + negScore ps b := by
  51. induction ps with
  52. | nil => simp [negScore]
  53. | cons p tail ih =>
  54. simp only [negScore,List.map_cons,List.sum_cons] at ih ⊢
  55. rw [counts_mul p ha hb,ih];ring
  56. private theorem score_mul (a b : ℕ) (ha : a≠0) (hb : b≠0) :
  57. score447 (a*b)=score447 a+score447 b := by
  58. unfold score447
  59. rw [counts_mul 2 ha hb,counts_mul 3 ha hb,neg_mul ha hb];ring
  60. set_option maxRecDepth 100000
  61. set_option maxHeartbeats 0
  62. theorem not_fit_447_895 : ¬Fits 447 895 := by
  63. apply valuation_obstruction _ _ score447 (by decide +kernel) score_mul
  64. · decide +kernel
  65. · decide +kernel
  66. theorem exact_447 : IsLeast {m | Fits 447 m} 896 := by
  67. refine ⟨fit_447_2,?_⟩
  68. intro m hm
  69. by_contra! h
  70. exact not_fit_447_895 (fits_mono hm (by omega))
  71. #print axioms exact_447
  72. end FactorialThresholds