Lean / Reader
Lean reader

AdditiveThreshold.lean

178 lines16 declarationsno sorryimports Mathlib.Tactic
  1. import Mathlib.Tactic
  2. namespace AdditiveThreshold
  3. /-- Subset sums including the empty sum. Each list entry is a separate index. -/
  4. def allSums : List ℕ → Finset ℕ
  5. | [] => {0}
  6. | a::xs => allSums xs ∪ (allSums xs).image (a + ·)
  7. theorem zero_mem (xs : List ℕ) : 0 ∈ allSums xs := by
  8. induction xs with
  9. | nil => simp [allSums]
  10. | cons a xs ih => exact Finset.mem_union_left _ ih
  11. private theorem add_increases (S : Finset ℕ) (hne : S.Nonempty) (a : ℕ) (ha : 0<a) :
  12. S.card+1 ≤ (S ∪ S.image (a + ·)).card := by
  13. let m := S.max' hne
  14. have hm : m ∈ S := Finset.max'_mem _ _
  15. have hnew : a+m ∉ S := by
  16. intro hx
  17. have hh := Finset.le_max' S (a+m) hx
  18. change a+m ≤ m at hh
  19. omega
  20. have hs : insert (a+m) S ⊆ S ∪ S.image (a + ·) := by
  21. intro v hv
  22. rcases Finset.mem_insert.mp hv with h|h
  23. · subst v; exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨m,hm,rfl⟩)
  24. · exact Finset.mem_union_left _ h
  25. simpa [hnew] using Finset.card_le_card hs
  26. theorem at_least_one_more (xs : List ℕ) (hp : ∀ i ∈ xs, 0 < i) :
  27. xs.length+1 ≤ (allSums xs).card := by
  28. induction xs with
  29. | nil => simp [allSums]
  30. | cons a xs ih =>
  31. have h := add_increases (allSums xs) ⟨0,zero_mem xs⟩ a (hp a (by simp))
  32. have hi := ih (by intro i hz; exact hp i (by simp [hz]))
  33. simp only [List.length_cons,allSums]; omega
  34. theorem unequal_pair_growth (xs : List ℕ) (a b : ℕ) (ha : 0<a) (hb : 0<b) (hab : a≠b)
  35. (hp : ∀ i ∈ xs, 0 < i) : xs.length+4 ≤ (allSums (xs++[a,b])).card := by
  36. induction xs with
  37. | nil =>
  38. have hset : allSums [a,b] = {0,b,a,a+b} := by ext n; simp [allSums]; tauto
  39. simp only [List.nil_append,List.length_nil,Nat.zero_add,hset,Finset.card_insert_eq_ite,
  40. Finset.mem_insert,Finset.mem_singleton,Finset.card_singleton]
  41. repeat' first | omega | split
  42. | cons c xs ih =>
  43. have hi := ih (by intro i hz; exact hp i (by simp [hz]))
  44. have h := add_increases (allSums (xs++[a,b])) ⟨0,zero_mem _⟩ c (hp c (by simp))
  45. simp only [List.length_cons,List.cons_append,allSums]; omega
  46. /-- A group of size e+1 supplies e+2 different projected subset sums. -/
  47. def gridSize : List ℕ → ℕ
  48. | [] => 1
  49. | e::es => (e+2)*gridSize es
  50. theorem flag_product_bound (es : List ℕ) :
  51. 2^es.length*(es.sum+2) ≤ 2*gridSize es := by
  52. induction es with
  53. | nil => decide
  54. | cons e es ih =>
  55. simp only [List.length_cons,pow_succ,List.sum_cons,gridSize]
  56. have hh := Nat.mul_le_mul_left (e+2) ih
  57. nlinarith only [hh, Nat.zero_le (2^es.length*es.sum*e)]
  58. theorem two_block_equality (s t : ℕ) (hs : 0<s) (ht : 0<t) :
  59. (s+1)*(t+1)=2*(s+t) ↔ s=1 ∨ t=1 := by
  60. obtain ⟨a,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt hs)
  61. obtain ⟨b,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (Nat.ne_of_gt ht)
  62. constructor
  63. · intro h
  64. have hz : a*b=0 := by nlinarith
  65. rcases Nat.mul_eq_zero.mp hz with h|h <;> omega
  66. · rintro (h|h) <;> simp at h <;> simp [h] <;> ring
  67. private theorem two_power_lower (d : ℕ) (hd : 3≤d) : 2*(d:ℤ)+2 ≤ (2:ℤ)^d := by
  68. induction d,hd using Nat.le_induction with
  69. | base => norm_num
  70. | succ d hd ih =>
  71. rw [pow_succ, Nat.cast_succ]; linarith
  72. theorem high_rank_gap (d k : ℕ) (hd : 3≤d) (hk : 4≤k) (hdk : d≤k) :
  73. (d:ℤ)*(2*k-1)+2 < (2:ℤ)^d*((k:ℤ)-d+2) := by
  74. induction d,hd using Nat.le_induction with
  75. | base =>
  76. norm_num at *
  77. omega
  78. | succ d hd ih =>
  79. have hdk' : d≤k := by omega
  80. have hgap := ih hdk'
  81. have hh := two_power_lower d hd
  82. have hdiff : 1 ≤ (k:ℤ)-d := by omega
  83. have hm := mul_le_mul_of_nonneg_right hh (show 0≤(k:ℤ)-d by omega)
  84. have hz : 0 ≤ (d:ℤ)*((k:ℤ)-d-1) := mul_nonneg (by positivity) (by omega)
  85. rw [Nat.cast_succ, pow_succ]
  86. nlinarith only [hgap,hm,hz]
  87. /-- Exact unpruned count for the rank-two shape with r copies of a. -/
  88. theorem count_pairs (r q s : ℕ) :
  89. 2 * (∑ i ∈ Finset.range q, (r*(q-1-i)+s)) =
  90. r*q*(q-1)+2*q*s := by
  91. induction q with
  92. | zero => simp
  93. | succ q ih =>
  94. rw [Finset.sum_range_succ']
  95. simp only [Nat.succ_sub_one,Nat.sub_zero]
  96. have he (i : ℕ) : q-(i+1)=q-1-i := by omega
  97. have hh : (∑ i ∈ Finset.range q, (r*(q-(i+1))+s)) =
  98. ∑ i ∈ Finset.range q, (r*(q-1-i)+s) :=
  99. Finset.sum_congr rfl (fun i _ => congrArg (fun x => r*x+s) (he i))
  100. rw [hh]
  101. cases q with
  102. | zero => simp
  103. | succ q =>
  104. simp only [Nat.succ_sub_one] at *
  105. nlinarith only [ih]
  106. theorem repeated_sums (a r : ℕ) :
  107. allSums (List.replicate r a) = (Finset.range (r+1)).image (fun j => j*a) := by
  108. induction r with
  109. | zero => simp [allSums,Finset.range_one]
  110. | succ r ih =>
  111. rw [List.replicate_succ, allSums, ih]
  112. ext v
  113. simp only [Finset.mem_union,Finset.mem_image,Finset.mem_range]
  114. constructor
  115. · rintro (⟨j,hj,rfl⟩|⟨_,⟨j,hj,rfl⟩,rfl⟩)
  116. · exact ⟨j,by omega,rfl⟩
  117. · exact ⟨j+1,by omega,by ring⟩
  118. · rintro ⟨j,hj,rfl⟩
  119. cases j with
  120. | zero => exact Or.inl ⟨0,by omega,rfl⟩
  121. | succ j => exact Or.inr ⟨j*a,⟨j,by omega,rfl⟩,by ring⟩
  122. theorem repeated_and_one (a b r v : ℕ) :
  123. v ∈ allSums (b::List.replicate r a) ↔
  124. (∃ j ≤ r, j*a=v) ∨ (∃ j ≤ r, b+j*a=v) := by
  125. rw [allSums, repeated_sums]
  126. simp only [Finset.mem_union,Finset.mem_image,Finset.mem_range]
  127. constructor
  128. · rintro (⟨j,hj,rfl⟩|⟨_,⟨j,hj,rfl⟩,rfl⟩)
  129. · exact Or.inl ⟨j,by omega,rfl⟩
  130. · exact Or.inr ⟨j,by omega,rfl⟩
  131. · rintro (⟨j,hj,rfl⟩|⟨j,hj,rfl⟩)
  132. · exact Or.inl ⟨j,by omega,rfl⟩
  133. · exact Or.inr ⟨j*a,⟨j,by omega,rfl⟩,rfl⟩
  134. open Filter
  135. open scoped Topology
  136. def occurs (k : ℕ) (A : Finset ℕ) : Prop :=
  137. ∃ xs : List ℕ, xs.length=k ∧ (∀ i ∈ xs, 0 < i) ∧ (allSums xs).erase 0 ⊆ A
  138. noncomputable def probability (k N : ℕ) (p : ℝ) : ℝ := by
  139. classical
  140. exact ∑ A ∈ (Finset.Icc 1 N).powerset,
  141. if occurs k A then p^A.card*(1-p)^(N-A.card) else 0
  142. /-- Existence version of the limiting law stated and proved in the accompanying paper. -/
  143. def FiniteSumsLaw : Prop :=
  144. ∀ k : ℕ, 0 < k → ∀ (p : ℕ → ℝ) (lam : ℝ), 0 < lam →
  145. (∀ N, p N ∈ Set.Icc 0 1) →
  146. Tendsto (fun N : ℕ => (N:ℝ)^(if k≤3 then k else 2) *
  147. (p N)^(if k≤3 then 2^k-1 else 2*k-1)) atTop (𝓝 lam) →
  148. Tendsto (fun N => probability k N (p N)) atTop
  149. (𝓝 (1-Real.exp (-lam/(if k≤3 then (k.factorial:ℝ)^2 else 2*((k:ℝ)-1)))))
  150. #print axioms at_least_one_more
  151. #print axioms unequal_pair_growth
  152. #print axioms flag_product_bound
  153. #print axioms two_block_equality
  154. #print axioms high_rank_gap
  155. #print axioms count_pairs
  156. #print axioms repeated_sums
  157. #print axioms repeated_and_one
  158. end AdditiveThreshold