Lean / Reader
Lean reader

ProductFour.lean

138 lines14 declarationsno sorryimports Mathlib.Probability.Independence.Basic Mathlib.Tactic
  1. import Mathlib.Probability.Independence.Basic
  2. import Mathlib.Tactic
  3. set_option maxHeartbeats 1500000
  4. namespace ProductFour
  5. /-- All nonempty subset products of three indexed generators. -/
  6. def triple (a b c : ℕ) : Finset ℕ := {a,b,c,a*b,a*c,b*c,a*b*c}
  7. /-- All nonempty subset products of four indexed generators. -/
  8. def quadruple (a b c d : ℕ) : Finset ℕ :=
  9. triple a b c ∪ {d,a*d,b*d,c*d,a*b*d,a*c*d,b*c*d,a*b*c*d}
  10. macro "count_labels" : tactic => `(tactic|
  11. (simp only [triple, quadruple, Finset.card_insert_eq_ite, Finset.mem_insert, Finset.mem_singleton, Finset.card_singleton, true_or, or_true, if_true, Nat.mul_assoc]; (repeat' (first | omega | split))))
  12. theorem triple_distinct (a b c : ℕ) (ha : 1<a) (hab : a<b) (hbc : b<c) :
  13. (triple a b c).card = if c=a*b then 6 else 7 := by
  14. have bp : 0<b := by omega
  15. have cp : 0<c := by omega
  16. have ap : 0<a := by omega
  17. have h1 : b<a*b := by nlinarith
  18. have h2 : c<a*c := by nlinarith
  19. have h3 : a*b<a*c := by nlinarith
  20. have h4 : a*c<b*c := by nlinarith
  21. have h5 : b*c<a*(b*c) := by nlinarith only [Nat.mul_lt_mul_of_pos_right ha (by positivity : 0<b*c)]
  22. by_cases h : c=a*b
  23. · count_labels
  24. · count_labels
  25. theorem triple_repeat (a b : ℕ) (ha : 1<a) (hb : 1<b) (hne : a≠b) :
  26. (triple a a b).card = if b=a*a then 4 else 5 := by
  27. have h0 : a<a*a := by nlinarith
  28. have h1 : a<a*b := by nlinarith
  29. have h2 : b<a*b := by nlinarith
  30. have h3 : a*a<a*(a*b) := by nlinarith only [Nat.mul_lt_mul_of_pos_left hb (by positivity : 0<a*a)]
  31. have h4 : a*b<a*(a*b) := by nlinarith only [Nat.mul_lt_mul_of_pos_right ha (by positivity : 0<a*b)]
  32. have h5 : a*a≠a*b := by exact fun h => hne (Nat.eq_of_mul_eq_mul_left (by omega) h)
  33. by_cases h : b=a*a
  34. · count_labels
  35. · count_labels
  36. theorem three_distinct_in_four (a b c d : ℕ) (ha : 1<a) (hab : a<b) (hbc : b<c) (hd : 1<d) :
  37. 7 ≤ (quadruple a b c d).card := by
  38. let S : Finset ℕ := {a,b,a*b,a*c,b*c,a*b*c,a*b*c*d}
  39. have hs : S ⊆ quadruple a b c d := by
  40. intro x hx
  41. simp [S] at hx
  42. simp [quadruple,triple]
  43. tauto
  44. have bp : 0<b := by omega
  45. have cp : 0<c := by omega
  46. have ap : 0<a := by omega
  47. have h1 : b<a*b := by nlinarith
  48. have h2 : a*b<a*c := by nlinarith
  49. have h3 : a*c<b*c := by nlinarith
  50. have h4 : b*c<a*b*c := by nlinarith only [Nat.mul_lt_mul_of_pos_right ha (by positivity : 0<b*c)]
  51. have h5 : a*b*c<a*b*c*d := by nlinarith only [Nat.mul_lt_mul_of_pos_left hd (by positivity : 0<a*b*c)]
  52. have hc : S.card=7 := by simp only [S, Finset.card_insert_eq_ite, Finset.mem_insert, Finset.mem_singleton, Finset.card_singleton]; (repeat' (first | omega | split))
  53. exact hc ▸ Finset.card_le_card hs
  54. /-- If every index belongs to a disjoint product equality, every prime of the total
  55. product divides it at least twice. This applies to the core after removal of free indices. -/
  56. theorem squarefull_core {ι : Type*} [Fintype ι] [DecidableEq ι] (x : ι → ℕ)
  57. (cover : ∀ i, ∃ s t : Finset ι, Disjoint s t ∧ i∈s ∧ s.prod x = t.prod x)
  58. {q : ℕ} (hq : q.Prime) (hd : q ∣ ∏ i, x i) : q^2 ∣ ∏ i, x i := by
  59. obtain ⟨i,_,hi⟩ := (hq.prime.dvd_finset_prod_iff x).mp hd
  60. obtain ⟨s,t,hst,his,he⟩ := cover i
  61. have h1 : q ∣ s.prod x := hi.trans (Finset.dvd_prod_of_mem x his)
  62. have h2 : q ∣ t.prod x := he ▸ h1
  63. have hp : q*q ∣ (s∪t).prod x := by
  64. rw [Finset.prod_union hst]
  65. exact mul_dvd_mul h1 h2
  66. rw [pow_two]
  67. exact hp.trans (Finset.prod_dvd_prod_of_subset _ _ x (Finset.subset_univ _))
  68. theorem three_cut_region (x y z : ℝ) (h : x+y+z=1) :
  69. (1/7 ≤ x ∧ 1/7 ≤ y ∧ 1/7 ≤ z ∧ 3/7 ≤ x+y ∧ 3/7 ≤ x+z ∧ 3/7 ≤ y+z) ↔
  70. (x ∈ Set.Icc (1/7) (4/7) ∧ y ∈ Set.Icc (1/7) (4/7) ∧ z ∈ Set.Icc (1/7) (4/7)) := by
  71. simp only [Set.mem_Icc]
  72. constructor
  73. · rintro ⟨_,_,_,_,_,_⟩; (repeat' constructor) <;> linarith
  74. · rintro ⟨⟨_,_⟩,⟨_,_⟩,_,_⟩; (repeat' constructor) <;> linarith
  75. theorem four_angular_slice (x y : ℝ) (h : x+y=9/13) :
  76. (3/13 ≤ x ∧ x≤y) ↔ x ∈ Set.Icc (3/13) (9/26) := by
  77. constructor <;> rintro ⟨h1,h2⟩ <;> constructor <;> linarith
  78. theorem rational_constants :
  79. ((2/3-1/3)/2 : ℚ) = 1/6 ∧
  80. (((4/7)^2-3*(1/7)^2)/(2*6) : ℚ) = 13/588 ∧
  81. (9/26-3/13 : ℚ) = 3/26 := by norm_num
  82. open MeasureTheory ProbabilityTheory Filter
  83. open scoped ENNReal Topology
  84. theorem prescribed_labels {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω}
  85. {E : ℕ → Set Ω} (hi : iIndepSet E μ) (S : Finset ℕ) (p : ℝ≥0∞)
  86. (hp : ∀ i ∈ S, μ (E i) = p) :
  87. μ (⋂ i ∈ S, E i) = p^S.card := by
  88. rw [hi.meas_biInter]
  89. calc
  90. _ = ∏ _i ∈ S, p := Finset.prod_congr rfl hp
  91. _ = _ := Finset.prod_const _
  92. def hasFour (A : Finset ℕ) : Prop :=
  93. ∃ a b c d : ℕ, 0<a ∧ 0<b ∧ 0<c ∧ 0<d ∧ quadruple a b c d ⊆ A
  94. noncomputable def appearanceProbability (N : ℕ) (p : ℝ) : ℝ := by
  95. classical
  96. exact ∑ A ∈ (Finset.Icc 1 N).powerset,
  97. if hasFour A then p^A.card*(1-p)^(N-A.card) else 0
  98. theorem total_mass (N : ℕ) (p : ℝ) :
  99. ∑ A ∈ (Finset.Icc 1 N).powerset, p^A.card*(1-p)^(N-A.card) = 1 := by
  100. have hcard : (Finset.Icc 1 N).card=N := by simp
  101. simpa [hcard] using Finset.sum_pow_mul_eq_add_pow p (1-p) (Finset.Icc 1 N)
  102. /-- Formal statement of the written probabilistic theorem. -/
  103. def CriticalLaw : Prop :=
  104. ∀ (p : ℕ → ℝ) (lam : ℝ), (∀ N, p N ∈ Set.Icc 0 1) → 0 < lam →
  105. Tendsto (fun N : ℕ => (N : ℝ)*Real.log N*(p N)^13) atTop (𝓝 lam) →
  106. Tendsto (fun N => appearanceProbability N (p N)) atTop
  107. (𝓝 (1-Real.exp (-Real.sqrt (3*Real.pi*lam/26))))
  108. #print axioms prescribed_labels
  109. #print axioms total_mass
  110. #print axioms triple_distinct
  111. #print axioms triple_repeat
  112. #print axioms three_distinct_in_four
  113. #print axioms squarefull_core
  114. #print axioms three_cut_region
  115. #print axioms four_angular_slice
  116. #print axioms rational_constants
  117. end ProductFour