-- Mathlib/Combinatorics/Additive/Corner/Roth.lean
theorem roth_3ap_theorem_nat (ε : ℝ) (hε : 0 < ε) (hG : cornersTheoremBound (ε / 3) ≤ n)
    (A : Finset ℕ) (hAn : A ⊆ range n) (hAε : ε * n ≤ #A) : ¬ ThreeAPFree (A : Set ℕ)

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ ↑(#A) = ↑(#(image (fun x => ↑x) A))

Tactic:
rw [card_image_of_injOn]

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ Set.InjOn (fun x => ↑x) ↑A

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this : ↑A = Fin.val '' (Nat.cast '' ↑A)
⊢ False

Tactic:
have := Fin.isAddFreimanIso_Iio two_ne_zero (le_refl (2 * n))

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
⊢ False

Proof state:
case h.bc
n : ℕ
ε : ℝ
hε : 0 < ε
hG : ⌊(triangleRemovalBound (ε / 3 / 9) * 27)⁻¹⌋₊ + 1 ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ 1 ≤ n

Tactic:
omega

Result:
no goals

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ 0 < ε / 3

Tactic:
positivity

Result:
no goals

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
x : ℕ
hx : x ∈ Set.Iio n
⊢ n ≤ 2 * n

Tactic:
omega

Result:
no goals

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ cornersTheoremBound (ε / 3) ≤ Fintype.card (Fin (2 * n + 1))

Tactic:
simp

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ cornersTheoremBound (ε / 3) ≤ 2 * n + 1

Proof state:
case h.bc
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ 1 ≤ ↑n

Tactic:
simp

Result:
case h.bc
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ 1 ≤ n

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree ↑A
a : ℕ
ha : a ∈ A
this : a < n
⊢ a < 2 * n + 1

Tactic:
omega

Result:
no goals

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ Set.Iio n ⊆ Set.Iio (2 * n).succ

Tactic:
simp

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ n ≤ 2 * n + 1

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree ↑A
this : ↑A = Fin.val '' (Nat.cast '' ↑A)
⊢ False

Tactic:
rw [this] at hA

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this : ↑A = Fin.val '' (Nat.cast '' ↑A)
⊢ False

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ↑(image (fun x => ↑x) A)
⊢ ε / 3 * (2 * ↑n + ↑n) = ε * ↑n

Tactic:
ring

Result:
no goals

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
⊢ False

Tactic:
have := hA.of_image this.isAddFreimanHom Fin.val_injective.injOn <| Set.image_subset_iff.2 <|
    hAn.trans fun x hx ↦ Fin.natCast_strictMono (by omega) <| by
      simpa only [coe_range, Set.mem_Iio] using hx

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree (Fin.val '' (Nat.cast '' ↑A))
this✝¹ : ↑A = Fin.val '' (Nat.cast '' ↑A)
this✝ : IsAddFreimanIso 2 (Set.Iio ↑n) (Set.Iio n) Fin.val
this : ThreeAPFree ((fun x => ↑x) '' ↑A)
⊢ False

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree ↑A
⊢ False

Tactic:
have : A = Fin.val '' (Nat.cast '' A : Set (Fin (2 * n).succ)) := by
  rw [Set.image_image, Set.image_congr, Set.image_id]
  simp only [mem_coe, Nat.succ_eq_add_one, Fin.val_natCast, id_eq, Nat.mod_succ_eq_iff_lt]
  rintro a ha
  have := hAn ha
  simp at this
  omega

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree ↑A
this : ↑A = Fin.val '' (Nat.cast '' ↑A)
⊢ False

Proof state:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree ↑A
a : ℕ
ha : a ∈ A
this : a ∈ Set.Iio n
⊢ a < 2 * n + 1

Tactic:
simp at this

Result:
n : ℕ
ε : ℝ
hε : 0 < ε
hG : cornersTheoremBound (ε / 3) ≤ n
A : Finset ℕ
hAn : ↑A ⊆ Set.Iio n
hAε : ε * ↑n ≤ ↑(#A)
hA : ThreeAPFree ↑A
a : ℕ
ha : a ∈ A
this : a < n
⊢ a < 2 * n + 1