-- Mathlib/NumberTheory/Pell.lean
theorem mul_inv_x_lt_x {a₁ : Solution₁ d} (h : IsFundamental a₁) {a : Solution₁ d} (hax : 1 < a.x)
    (hay : 0 < a.y) : (a * a₁⁻¹).x < a.x

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.x * a₁.x < d * (a.y * a₁.y) + a.x

Tactic:
refine (mul_lt_mul_left h.2.1).mp ?_

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a₁.y * (a.x * a₁.x) < a₁.y * (d * (a.y * a₁.y) + a.x)

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y * (1 + d * a₁.y ^ 2) - a₁.y * (d * (a.y * a₁.y) + a.x) < 0

Tactic:
suffices a.y - a.x * a₁.y < 0 by convert this using 1; ring

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y - a.x * a₁.y < 0

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y ^ 2 < (1 + d * a.y ^ 2) * a₁.y ^ 2

Tactic:
calc
  a.y ^ 2 = 1 * a.y ^ 2 := (one_mul _).symm
  _ ≤ d * a.y ^ 2 := (mul_le_mul_right <| sq_pos_of_pos hay).mpr h.d_pos
  _ < d * a.y ^ 2 + 1 := lt_add_one _
  _ = (1 + d * a.y ^ 2) * 1 := by rw [add_comm, mul_one]
  _ ≤ (1 + d * a.y ^ 2) * a₁.y ^ 2 :=
    (mul_le_mul_left (by have := h.d_pos; positivity)).mpr (sq_pos_of_pos h.2.1)

Result:
no goals

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y * a₁.x * a₁.x < a₁.y * (d * (a.y * a₁.y) + a.x)

Tactic:
rw [mul_assoc, ← sq, a₁.prop_x, ← sub_neg]

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y * (1 + d * a₁.y ^ 2) - a₁.y * (d * (a.y * a₁.y) + a.x) < 0

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y - a.x * a₁.y < 0

Tactic:
rw [sub_neg, ← abs_of_pos hay, ← abs_of_pos h.2.1, ← abs_of_pos <| zero_lt_one.trans hax, ←
  abs_mul, ← sq_lt_sq, mul_pow, a.prop_x]

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y ^ 2 < (1 + d * a.y ^ 2) * a₁.y ^ 2

Proof state:
case h.e'_3
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
this : a.y - a.x * a₁.y < 0
⊢ a.y * (1 + d * a₁.y ^ 2) - a₁.y * (d * (a.y * a₁.y) + a.x) = a.y - a.x * a₁.y

Tactic:
ring

Result:
no goals

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
this : 0 < d
⊢ 0 < 1 + d * a.y ^ 2

Tactic:
positivity

Result:
no goals

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a₁.y * (a.x * a₁.x) < a₁.y * (d * (a.y * a₁.y) + a.x)

Tactic:
rw [(by ring : a₁.y * (a.x * a₁.x) = a.x * a₁.y * a₁.x)]

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.x * a₁.y * a₁.x < a₁.y * (d * (a.y * a₁.y) + a.x)

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ d * a.y ^ 2 + 1 = (1 + d * a.y ^ 2) * 1

Tactic:
rw [add_comm, mul_one]

Result:
no goals

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ 0 < 1 + d * a.y ^ 2

Tactic:
have := h.d_pos

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
this : 0 < d
⊢ 0 < 1 + d * a.y ^ 2

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ (a * a₁⁻¹).x < a.x

Tactic:
simp only [x_mul, x_inv, y_inv, mul_neg, add_neg_lt_iff_le_add']

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.x * a₁.x < d * (a.y * a₁.y) + a.x

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a₁.y * (a.x * a₁.x) = a.x * a₁.y * a₁.x

Tactic:
ring

Result:
no goals

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
this : a.y - a.x * a₁.y < 0
⊢ a.y * (1 + d * a₁.y ^ 2) - a₁.y * (d * (a.y * a₁.y) + a.x) < 0

Tactic:
convert this using 1

Result:
case h.e'_3
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
this : a.y - a.x * a₁.y < 0
⊢ a.y * (1 + d * a₁.y ^ 2) - a₁.y * (d * (a.y * a₁.y) + a.x) = a.y - a.x * a₁.y

Proof state:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.x * a₁.y * a₁.x < a₁.y * (d * (a.y * a₁.y) + a.x)

Tactic:
refine
  ((mul_le_mul_right <| zero_lt_one.trans h.1).mpr <| x_mul_y_le_y_mul_x h hax hay).trans_lt ?_

Result:
d : ℤ
a₁ : Solution₁ d
h : IsFundamental a₁
a : Solution₁ d
hax : 1 < a.x
hay : 0 < a.y
⊢ a.y * a₁.x * a₁.x < a₁.y * (d * (a.y * a₁.y) + a.x)