Lean / Reader
Lean reader

HindmanBands.lean

51 lines6 declarationsno sorryimports Mathlib.Tactic
  1. import Mathlib.Tactic
  2. namespace HindmanBands
  3. /-- Index-subset sums, including the empty sum. -/
  4. def sums : List ℕ → Finset ℕ
  5. | [] => {0}
  6. | a :: xs => sums xs ∪ (sums xs).image (a + ·)
  7. theorem total_mem (xs : List ℕ) : xs.sum ∈ sums xs := by
  8. induction xs with
  9. | nil => simp [sums]
  10. | cons a xs ih =>
  11. exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨xs.sum, ih, rfl⟩)
  12. theorem no_cross (xs : List ℕ) (B : ℕ) (hB : 0 < B)
  13. (small : ∀ a ∈ xs, a < B)
  14. (gap : ∀ n ∈ sums xs, B ≤ n → 2 * B ≤ n) : xs.sum < B := by
  15. induction xs with
  16. | nil => simpa using hB
  17. | cons a xs ih =>
  18. have ht := ih (fun b hb => small b (List.mem_cons_of_mem _ hb))
  19. (fun n hn => gap n (Finset.mem_union_left _ hn))
  20. have ha := small a (List.mem_cons_self ..)
  21. have hg := gap (a :: xs).sum (total_mem _)
  22. simp only [List.sum_cons] at hg ⊢
  23. omega
  24. theorem next_band (x y e : ℕ) (hx : 2 ^ e ≤ x) (hy : 2 ^ e ≤ y)
  25. (hx' : x < 2 ^ (e + 1)) (hy' : y < 2 ^ (e + 1)) :
  26. 2 ^ (e+1) ≤ x+y ∧ x+y < 2 ^ (e+2) := by
  27. have h1 : 2^(e+1) = 2^e * 2 := pow_succ _ _
  28. have h2 : 2^(e+2) = 2^(e+1) * 2 := pow_succ _ _
  29. omega
  30. theorem squares_le_total_sq (xs : List ℕ) :
  31. (xs.map fun x => x^2).sum ≤ xs.sum^2 := by
  32. induction xs with
  33. | nil => simp
  34. | cons a xs ih =>
  35. simp only [List.map_cons, List.sum_cons]
  36. nlinarith [Nat.zero_le (a * xs.sum)]
  37. theorem sharp_variance_bound (xs : List ℕ) (m d : ℕ) (h : d * xs.sum < m) :
  38. (d^2 + 1)*m^2 > d^2*(m^2 + (xs.map fun x => x^2).sum) := by
  39. have hs := Nat.mul_le_mul_left (d^2) (squares_le_total_sq xs)
  40. have ht : (d * xs.sum)^2 < m^2 := Nat.pow_lt_pow_left h (by decide)
  41. nlinarith
  42. end HindmanBands