import Mathlib.Probability.Independence.Basicimport Mathlib.Tacticset_option maxHeartbeats 1500000namespace ProductFour/-- All nonempty subset products of three indexed generators. -/def triple (a b c : ℕ) : Finset ℕ := {a,b,c,a*b,a*c,b*c,a*b*c}/-- All nonempty subset products of four indexed generators. -/def quadruple (a b c d : ℕ) : Finset ℕ :=triple a b c ∪ {d,a*d,b*d,c*d,a*b*d,a*c*d,b*c*d,a*b*c*d}macro "count_labels" : tactic => `(tactic|(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))))theorem triple_distinct (a b c : ℕ) (ha : 1<a) (hab : a<b) (hbc : b<c) :(triple a b c).card = if c=a*b then 6 else 7 := byhave bp : 0<b := by omegahave cp : 0<c := by omegahave ap : 0<a := by omegahave h1 : b<a*b := by nlinarithhave h2 : c<a*c := by nlinarithhave h3 : a*b<a*c := by nlinarithhave h4 : a*c<b*c := by nlinarithhave h5 : b*c<a*(b*c) := by nlinarith only [Nat.mul_lt_mul_of_pos_right ha (by positivity : 0<b*c)]by_cases h : c=a*b· count_labels· count_labelstheorem triple_repeat (a b : ℕ) (ha : 1<a) (hb : 1<b) (hne : a≠b) :(triple a a b).card = if b=a*a then 4 else 5 := byhave h0 : a<a*a := by nlinarithhave h1 : a<a*b := by nlinarithhave h2 : b<a*b := by nlinarithhave h3 : a*a<a*(a*b) := by nlinarith only [Nat.mul_lt_mul_of_pos_left hb (by positivity : 0<a*a)]have h4 : a*b<a*(a*b) := by nlinarith only [Nat.mul_lt_mul_of_pos_right ha (by positivity : 0<a*b)]have h5 : a*a≠a*b := by exact fun h => hne (Nat.eq_of_mul_eq_mul_left (by omega) h)by_cases h : b=a*a· count_labels· count_labelstheorem three_distinct_in_four (a b c d : ℕ) (ha : 1<a) (hab : a<b) (hbc : b<c) (hd : 1<d) :7 ≤ (quadruple a b c d).card := bylet S : Finset ℕ := {a,b,a*b,a*c,b*c,a*b*c,a*b*c*d}have hs : S ⊆ quadruple a b c d := byintro x hxsimp [S] at hxsimp [quadruple,triple]tautohave bp : 0<b := by omegahave cp : 0<c := by omegahave ap : 0<a := by omegahave h1 : b<a*b := by nlinarithhave h2 : a*b<a*c := by nlinarithhave h3 : a*c<b*c := by nlinarithhave h4 : b*c<a*b*c := by nlinarith only [Nat.mul_lt_mul_of_pos_right ha (by positivity : 0<b*c)]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)]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))exact hc ▸ Finset.card_le_card hs/-- If every index belongs to a disjoint product equality, every prime of the totalproduct divides it at least twice. This applies to the core after removal of free indices. -/theorem squarefull_core {ι : Type*} [Fintype ι] [DecidableEq ι] (x : ι → ℕ)(cover : ∀ i, ∃ s t : Finset ι, Disjoint s t ∧ i∈s ∧ s.prod x = t.prod x){q : ℕ} (hq : q.Prime) (hd : q ∣ ∏ i, x i) : q^2 ∣ ∏ i, x i := byobtain ⟨i,_,hi⟩ := (hq.prime.dvd_finset_prod_iff x).mp hdobtain ⟨s,t,hst,his,he⟩ := cover ihave h1 : q ∣ s.prod x := hi.trans (Finset.dvd_prod_of_mem x his)have h2 : q ∣ t.prod x := he ▸ h1have hp : q*q ∣ (s∪t).prod x := byrw [Finset.prod_union hst]exact mul_dvd_mul h1 h2rw [pow_two]exact hp.trans (Finset.prod_dvd_prod_of_subset _ _ x (Finset.subset_univ _))theorem three_cut_region (x y z : ℝ) (h : x+y+z=1) :(1/7 ≤ x ∧ 1/7 ≤ y ∧ 1/7 ≤ z ∧ 3/7 ≤ x+y ∧ 3/7 ≤ x+z ∧ 3/7 ≤ y+z) ↔(x ∈ Set.Icc (1/7) (4/7) ∧ y ∈ Set.Icc (1/7) (4/7) ∧ z ∈ Set.Icc (1/7) (4/7)) := bysimp only [Set.mem_Icc]constructor· rintro ⟨_,_,_,_,_,_⟩; (repeat' constructor) <;> linarith· rintro ⟨⟨_,_⟩,⟨_,_⟩,_,_⟩; (repeat' constructor) <;> linariththeorem four_angular_slice (x y : ℝ) (h : x+y=9/13) :(3/13 ≤ x ∧ x≤y) ↔ x ∈ Set.Icc (3/13) (9/26) := byconstructor <;> rintro ⟨h1,h2⟩ <;> constructor <;> linariththeorem rational_constants :((2/3-1/3)/2 : ℚ) = 1/6 ∧(((4/7)^2-3*(1/7)^2)/(2*6) : ℚ) = 13/588 ∧(9/26-3/13 : ℚ) = 3/26 := by norm_numopen MeasureTheory ProbabilityTheory Filteropen scoped ENNReal Topologytheorem prescribed_labels {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω}{E : ℕ → Set Ω} (hi : iIndepSet E μ) (S : Finset ℕ) (p : ℝ≥0∞)(hp : ∀ i ∈ S, μ (E i) = p) :μ (⋂ i ∈ S, E i) = p^S.card := byrw [hi.meas_biInter]calc_ = ∏ _i ∈ S, p := Finset.prod_congr rfl hp_ = _ := Finset.prod_const _def hasFour (A : Finset ℕ) : Prop :=∃ a b c d : ℕ, 0<a ∧ 0<b ∧ 0<c ∧ 0<d ∧ quadruple a b c d ⊆ Anoncomputable def appearanceProbability (N : ℕ) (p : ℝ) : ℝ := byclassicalexact ∑ A ∈ (Finset.Icc 1 N).powerset,if hasFour A then p^A.card*(1-p)^(N-A.card) else 0theorem total_mass (N : ℕ) (p : ℝ) :∑ A ∈ (Finset.Icc 1 N).powerset, p^A.card*(1-p)^(N-A.card) = 1 := byhave hcard : (Finset.Icc 1 N).card=N := by simpsimpa [hcard] using Finset.sum_pow_mul_eq_add_pow p (1-p) (Finset.Icc 1 N)/-- Formal statement of the written probabilistic theorem. -/def CriticalLaw : Prop :=∀ (p : ℕ → ℝ) (lam : ℝ), (∀ N, p N ∈ Set.Icc 0 1) → 0 < lam →Tendsto (fun N : ℕ => (N : ℝ)*Real.log N*(p N)^13) atTop (𝓝 lam) →Tendsto (fun N => appearanceProbability N (p N)) atTop(𝓝 (1-Real.exp (-Real.sqrt (3*Real.pi*lam/26))))#print axioms prescribed_labels#print axioms total_mass#print axioms triple_distinct#print axioms triple_repeat#print axioms three_distinct_in_four#print axioms squarefull_core#print axioms three_cut_region#print axioms four_angular_slice#print axioms rational_constantsend ProductFour