Theorem: Rat.finite_rat_abs_sub_lt_one_div_den_sq
File: Mathlib/NumberTheory/DiophantineApproximation.lean

tactic: let f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
state_before: ξ : ℚ
⊢ {q | |ξ - q| < 1 / ↑q.den ^ 2}.Finite
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
⊢ {q | |ξ - q| < 1 / ↑q.den ^ 2}.Finite

tactic: set s := {q : ℚ | |ξ - q| < 1 / (q.den : ℚ) ^ 2}
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
⊢ {q | |ξ - q| < 1 / ↑q.den ^ 2}.Finite
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
⊢ s.Finite

tactic: have hinj : Function.Injective f := by
  intro a b hab
  simp only [f, Prod.mk.inj_iff] at hab
  rw [← Rat.num_div_den a, ← Rat.num_div_den b, hab.1, hab.2]
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
⊢ s.Finite
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
⊢ s.Finite

tactic: have H : f '' s ⊆ ⋃ (y : ℕ) (_ : y ∈ Ioc 0 ξ.den), Icc (⌈ξ * y⌉ - 1) (⌊ξ * y⌋ + 1) ×ˢ {y} := by
  intro xy hxy
  simp only [mem_image, mem_setOf] at hxy
  obtain ⟨q, hq₁, hq₂⟩ := hxy
  obtain ⟨hd, hn⟩ := den_le_and_le_num_le_of_sub_lt_one_div_den_sq hq₁
  simp_rw [mem_iUnion]
  refine ⟨q.den, Set.mem_Ioc.mpr ⟨q.pos, hd⟩, ?_⟩
  simp only [prod_singleton, mem_image, mem_Icc, (congr_arg Prod.snd (Eq.symm hq₂)).trans rfl]
  exact ⟨q.num, hn, hq₂⟩
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
⊢ s.Finite
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
H : f '' s ⊆ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
⊢ s.Finite

tactic: refine (Finite.subset ?_ H).of_finite_image hinj.injOn
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
H : f '' s ⊆ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
⊢ s.Finite
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
H : f '' s ⊆ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
⊢ (⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}).Finite

tactic: exact Finite.biUnion (finite_Ioc _ _) fun x _ => Finite.prod (finite_Icc _ _) (finite_singleton _)
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
H : f '' s ⊆ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
⊢ (⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}).Finite
state_after: no goals

tactic: intro a b hab
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
⊢ Function.Injective f
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
a b : ℚ
hab : f a = f b
⊢ a = b

tactic: simp only [f, Prod.mk.inj_iff] at hab
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
a b : ℚ
hab : f a = f b
⊢ a = b
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
a b : ℚ
hab : a.num = b.num ∧ a.den = b.den
⊢ a = b

tactic: rw [← Rat.num_div_den a, ← Rat.num_div_den b, hab.1, hab.2]
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
a b : ℚ
hab : a.num = b.num ∧ a.den = b.den
⊢ a = b
state_after: no goals

tactic: intro xy hxy
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
⊢ f '' s ⊆ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
hxy : xy ∈ f '' s
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}

tactic: simp only [mem_image, mem_setOf] at hxy
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
hxy : xy ∈ f '' s
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
state_after: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
hxy : ∃ x ∈ s, f x = xy
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}

tactic: obtain ⟨q, hq₁, hq₂⟩ := hxy
state_before: ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
hxy : ∃ x ∈ s, f x = xy
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
state_after: case intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}

tactic: obtain ⟨hd, hn⟩ := den_le_and_le_num_le_of_sub_lt_one_div_den_sq hq₁
state_before: case intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
state_after: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}

tactic: simp_rw [mem_iUnion]
state_before: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ xy ∈ ⋃ y ∈ Ioc 0 ξ.den, Icc (⌈ξ * ↑y⌉ - 1) (⌊ξ * ↑y⌋ + 1) ×ˢ {y}
state_after: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ ∃ i, ∃ (_ : i ∈ Ioc 0 ξ.den), xy ∈ Icc (⌈ξ * ↑i⌉ - 1) (⌊ξ * ↑i⌋ + 1) ×ˢ {i}

tactic: refine ⟨q.den, Set.mem_Ioc.mpr ⟨q.pos, hd⟩, ?_⟩
state_before: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ ∃ i, ∃ (_ : i ∈ Ioc 0 ξ.den), xy ∈ Icc (⌈ξ * ↑i⌉ - 1) (⌊ξ * ↑i⌋ + 1) ×ˢ {i}
state_after: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ xy ∈ Icc (⌈ξ * ↑q.den⌉ - 1) (⌊ξ * ↑q.den⌋ + 1) ×ˢ {q.den}

tactic: simp only [prod_singleton, mem_image, mem_Icc, (congr_arg Prod.snd (Eq.symm hq₂)).trans rfl]
state_before: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ xy ∈ Icc (⌈ξ * ↑q.den⌉ - 1) (⌊ξ * ↑q.den⌋ + 1) ×ˢ {q.den}
state_after: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ ∃ x, (⌈ξ * ↑q.den⌉ - 1 ≤ x ∧ x ≤ ⌊ξ * ↑q.den⌋ + 1) ∧ (x, q.den) = xy

tactic: exact ⟨q.num, hn, hq₂⟩
state_before: case intro.intro.intro
ξ : ℚ
f : ℚ → ℤ × ℕ := fun q => (q.num, q.den)
s : Set ℚ := {q | |ξ - q| < 1 / ↑q.den ^ 2}
hinj : Function.Injective f
xy : ℤ × ℕ
q : ℚ
hq₁ : q ∈ s
hq₂ : f q = xy
hd : q.den ≤ ξ.den
hn : ⌈ξ * ↑q.den⌉ - 1 ≤ q.num ∧ q.num ≤ ⌊ξ * ↑q.den⌋ + 1
⊢ ∃ x, (⌈ξ * ↑q.den⌉ - 1 ≤ x ∧ x ≤ ⌊ξ * ↑q.den⌋ + 1) ∧ (x, q.den) = xy
state_after: no goals