Theorem: Pell.eq_of_xn_modEq'
File: Mathlib/NumberTheory/PellMatiyasevic.lean

Proof steps:
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
⊢ i ≤ 2 * n
state_after: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
⊢ n ≤ 2 * n
tactic: apply le_trans hin
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
⊢ n ≤ 2 * n
state_after: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
⊢ n ≤ n + n
tactic: rw [two_mul]
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
⊢ n ≤ n + n
state_after: no goals
tactic: apply Nat.le_add_left
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : j ≤ 2 * n
a2 : a = 2
n1 : n = 1
j0 : j = 0
i2 : i = 2
⊢ False
state_after: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : 2 ≤ 1
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : j ≤ 2 * n
a2 : a = 2
n1 : n = 1
j0 : j = 0
i2 : i = 2
⊢ False
tactic: rw [n1, i2] at hin
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : 2 ≤ 1
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : j ≤ 2 * n
a2 : a = 2
n1 : n = 1
j0 : j = 0
i2 : i = 2
⊢ False
state_after: no goals
tactic: exact absurd hin (by decide)
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
this : i = 4 * n - j
⊢ j + i = 4 * n
state_after: no goals
tactic: rw [this, add_tsub_cancel_of_le j4n]
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
⊢ 4 * n - j + ?m.167070 i2n j2n ≤ 2 * n + ?m.167070 i2n j2n
state_after: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
⊢ 2 * n + 2 * n ≤ 2 * n + j
tactic: rw [tsub_add_cancel_of_le j4n, show 4 * n = 2 * n + 2 * n from right_distrib 2 2 n]
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
⊢ 2 * n + 2 * n ≤ 2 * n + j
state_after: no goals
tactic: exact Nat.add_le_add_left (le_of_lt j2n) _
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
j42n : 4 * n - j ≤ 2 * n
⊢ xn a1 j ≡ xn a1 (4 * n - j) [MOD xn a1 n]
state_after: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
j42n : 4 * n - j ≤ 2 * n
t : xn a1 (4 * n - (4 * n - j)) ≡ xn a1 (4 * n - j) [MOD xn a1 n] := xn_modEq_x4n_sub a1 j42n
⊢ xn a1 j ≡ xn a1 (4 * n - j) [MOD xn a1 n]
tactic: let t := xn_modEq_x4n_sub a1 j42n
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
j42n : 4 * n - j ≤ 2 * n
t : xn a1 (4 * n - (4 * n - j)) ≡ xn a1 (4 * n - j) [MOD xn a1 n] := xn_modEq_x4n_sub a1 j42n
⊢ xn a1 j ≡ xn a1 (4 * n - j) [MOD xn a1 n]
state_after: no goals
tactic: rwa [tsub_tsub_cancel_of_le j4n] at t
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : i ≤ n
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
j42n : 4 * n - j ≤ 2 * n
a2 : a = 2
n1 : n = 1
i2 : i = 2
⊢ 4 * n - j ≠ 0
state_after: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : 2 ≤ 1
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
j42n : 4 * n - j ≤ 2 * n
a2 : a = 2
n1 : n = 1
i2 : i = 2
⊢ 4 * n - j ≠ 0
tactic: rw [n1, i2] at hin
state_before: a : ℕ
a1 : 1 < a
i j n : ℕ
ipos : 0 < i
hin : 2 ≤ 1
j4n : j ≤ 4 * n
h : xn a1 j ≡ xn a1 i [MOD xn a1 n]
i2n : i ≤ 2 * n
j2n : 2 * n < j
j42n : 4 * n - j ≤ 2 * n
a2 : a = 2
n1 : n = 1
i2 : i = 2
⊢ 4 * n - j ≠ 0
state_after: no goals
tactic: exact absurd hin (by decide)