File: Mathlib/NumberTheory/PellMatiyasevic.lean

full_name: Pell.IsPell
code: /-- The property of being a solution to the Pell equation, expressed
  as a property of elements of `ℤ√d`. -/
def IsPell : ℤ√d → Prop
  
goal: ℤ√d → Prop

full_name: Pell.isPell_norm
code: theorem isPell_norm : ∀ {b : ℤ√d}, IsPell b ↔ b * star b = 1
  
goal: Pell.IsPell b ↔ b * star b = 1

full_name: Pell.isPell_iff_mem_unitary
code: theorem isPell_iff_mem_unitary : ∀ {b : ℤ√d}, IsPell b ↔ b ∈ unitary (ℤ√d)
  
goal: Pell.IsPell b ↔ b ∈ unitary (ℤ√d)

full_name: Pell.isPell_mul
code: theorem isPell_mul {b c : ℤ√d} (hb : IsPell b) (hc : IsPell c) : IsPell (b * c) 
goal: Pell.IsPell (b * c)

full_name: Pell.isPell_star
code: theorem isPell_star : ∀ {b : ℤ√d}, IsPell b ↔ IsPell (star b)
  
goal: Pell.IsPell b ↔ Pell.IsPell (star b)

full_name: _private.Mathlib.NumberTheory.PellMatiyasevic.0.Pell.d
code: private def d (_a1 : 1 < a) 
goal: ℕ

full_name: Pell.d_pos
code: @[simp]
theorem d_pos : 0 < d a1 
goal: 0 < Pell.d a1

full_name: Pell.pell
code: /-- The Pell sequences, i.e. the sequence of integer solutions to `x ^ 2 - d * y ^ 2 = 1`, where
`d = a ^ 2 - 1`, defined together in mutual recursion. -/
--@[nolint dup_namespace]
def pell : ℕ → ℕ × ℕ
  -- Porting note: used pattern matching because `Nat.recOn` is noncomputable
  
goal: ℕ → ℕ × ℕ

full_name: Pell.xn
code: /-- The Pell `x` sequence. -/
def xn (n : ℕ) : ℕ 
goal: ℕ

full_name: Pell.yn
code: /-- The Pell `y` sequence. -/
def yn (n : ℕ) : ℕ 
goal: ℕ

full_name: Pell.pell_val
code: @[simp]
theorem pell_val (n : ℕ) : pell a1 n = (xn a1 n, yn a1 n) 
goal: Pell.pell a1 n = (Pell.xn a1 n, Pell.yn a1 n)

full_name: Pell.xn_zero
code: @[simp]
theorem xn_zero : xn a1 0 = 1 
goal: Pell.xn a1 0 = 1

full_name: Pell.yn_zero
code: @[simp]
theorem yn_zero : yn a1 0 = 0 
goal: Pell.yn a1 0 = 0

full_name: Pell.xn_succ
code: @[simp]
theorem xn_succ (n : ℕ) : xn a1 (n + 1) = xn a1 n * a + d a1 * yn a1 n 
goal: Pell.xn a1 (n + 1) = Pell.xn a1 n * a + Pell.d a1 * Pell.yn a1 n

full_name: Pell.yn_succ
code: @[simp]
theorem yn_succ (n : ℕ) : yn a1 (n + 1) = xn a1 n + yn a1 n * a 
goal: Pell.yn a1 (n + 1) = Pell.xn a1 n + Pell.yn a1 n * a

full_name: Pell.xn_one
code: theorem xn_one : xn a1 1 = a 
goal: Pell.xn a1 1 = a

full_name: Pell.yn_one
code: theorem yn_one : yn a1 1 = 1 
goal: Pell.yn a1 1 = 1

full_name: Pell.xz
code: /-- The Pell `x` sequence, considered as an integer sequence. -/
def xz (n : ℕ) : ℤ 
goal: ℤ

full_name: Pell.yz
code: /-- The Pell `y` sequence, considered as an integer sequence. -/
def yz (n : ℕ) : ℤ 
goal: ℤ

full_name: Pell.az
code: /-- The element `a` such that `d = a ^ 2 - 1`, considered as an integer. -/
def az (a : ℕ) : ℤ 
goal: ℤ

full_name: Pell.asq_pos
code: theorem asq_pos : 0 < a * a 
goal: 0 < a * a

full_name: Pell.dz_val
code: theorem dz_val : ↑(d a1) = az a * az a - 1 
goal: ↑(Pell.d a1) = Pell.az a * Pell.az a - 1

full_name: Pell.xz_succ
code: @[simp]
theorem xz_succ (n : ℕ) : (xz a1 (n + 1)) = xz a1 n * az a + d a1 * yz a1 n 
goal: Pell.xz a1 (n + 1) = Pell.xz a1 n * Pell.az a + ↑(Pell.d a1) * Pell.yz a1 n

full_name: Pell.yz_succ
code: @[simp]
theorem yz_succ (n : ℕ) : yz a1 (n + 1) = xz a1 n + yz a1 n * az a 
goal: Pell.yz a1 (n + 1) = Pell.xz a1 n + Pell.yz a1 n * Pell.az a

full_name: Pell.pellZd
code: /-- The Pell sequence can also be viewed as an element of `ℤ√d` -/
def pellZd (n : ℕ) : ℤ√(d a1) 
goal: ℤ√↑(Pell.d a1)

full_name: Pell.pellZd_re
code: @[simp]
theorem pellZd_re (n : ℕ) : (pellZd a1 n).re = xn a1 n 
goal: (Pell.pellZd a1 n).re = ↑(Pell.xn a1 n)

full_name: Pell.pellZd_im
code: @[simp]
theorem pellZd_im (n : ℕ) : (pellZd a1 n).im = yn a1 n 
goal: (Pell.pellZd a1 n).im = ↑(Pell.yn a1 n)

full_name: Pell.isPell_nat
code: theorem isPell_nat {x y : ℕ} : IsPell (⟨x, y⟩ : ℤ√(d a1)) ↔ x * x - d a1 * y * y = 1 
goal: Pell.IsPell { re := ↑x, im := ↑y } ↔ x * x - Pell.d a1 * y * y = 1

full_name: Pell.pellZd_succ
code: @[simp]
theorem pellZd_succ (n : ℕ) : pellZd a1 (n + 1) = pellZd a1 n * ⟨a, 1⟩ 
goal: Pell.pellZd a1 (n + 1) = Pell.pellZd a1 n * { re := ↑a, im := 1 }

full_name: Pell.isPell_one
code: theorem isPell_one : IsPell (⟨a, 1⟩ : ℤ√(d a1)) 
goal: Pell.IsPell { re := ↑a, im := 1 }

full_name: Pell.isPell_pellZd
code: theorem isPell_pellZd : ∀ n : ℕ, IsPell (pellZd a1 n)
  
goal: Pell.IsPell (Pell.pellZd a1 n)

full_name: Pell.pell_eqz
code: @[simp]
theorem pell_eqz (n : ℕ) : xz a1 n * xz a1 n - d a1 * yz a1 n * yz a1 n = 1 
goal: Pell.xz a1 n * Pell.xz a1 n - ↑(Pell.d a1) * Pell.yz a1 n * Pell.yz a1 n = 1

full_name: Pell.pell_eq
code: @[simp]
theorem pell_eq (n : ℕ) : xn a1 n * xn a1 n - d a1 * yn a1 n * yn a1 n = 1 
goal: Pell.xn a1 n * Pell.xn a1 n - Pell.d a1 * Pell.yn a1 n * Pell.yn a1 n = 1

full_name: Pell.dnsq
code: instance dnsq : Zsqrtd.Nonsquare (d a1) 
goal: Zsqrtd.Nonsquare (Pell.d a1)

full_name: Pell.xn_ge_a_pow
code: theorem xn_ge_a_pow : ∀ n : ℕ, a ^ n ≤ xn a1 n
  
goal: a ^ n ≤ Pell.xn a1 n

full_name: Pell.n_lt_a_pow
code: theorem n_lt_a_pow : ∀ n : ℕ, n < a ^ n
  
goal: n < a ^ n

full_name: Pell.n_lt_xn
code: theorem n_lt_xn (n) : n < xn a1 n 
goal: n < Pell.xn a1 n

full_name: Pell.x_pos
code: theorem x_pos (n) : 0 < xn a1 n 
goal: 0 < Pell.xn a1 n

full_name: Pell.eq_pell_lem
code: theorem eq_pell_lem : ∀ (n) (b : ℤ√(d a1)), 1 ≤ b → IsPell b →
    b ≤ pellZd a1 n → ∃ n, b = pellZd a1 n
  
goal: 1 ≤ b → Pell.IsPell b → b ≤ Pell.pellZd a1 n → ∃ n, b = Pell.pellZd a1 n

full_name: Pell.eq_pellZd
code: theorem eq_pellZd (b : ℤ√(d a1)) (b1 : 1 ≤ b) (hp : IsPell b) : ∃ n, b = pellZd a1 n 
goal: ∃ n, b = Pell.pellZd a1 n

full_name: Pell.eq_pell
code: /-- Every solution to **Pell's equation** is recursively obtained from the initial solution
`(1,0)` using the recursion `pell`. -/
theorem eq_pell {x y : ℕ} (hp : x * x - d a1 * y * y = 1) : ∃ n, x = xn a1 n ∧ y = yn a1 n 
goal: ∃ n, x = Pell.xn a1 n ∧ y = Pell.yn a1 n

full_name: Pell.pellZd_add
code: theorem pellZd_add (m) : ∀ n, pellZd a1 (m + n) = pellZd a1 m * pellZd a1 n
  
goal: Pell.pellZd a1 (m + n) = Pell.pellZd a1 m * Pell.pellZd a1 n

full_name: Pell.xn_add
code: theorem xn_add (m n) : xn a1 (m + n) = xn a1 m * xn a1 n + d a1 * yn a1 m * yn a1 n 
goal: Pell.xn a1 (m + n) = Pell.xn a1 m * Pell.xn a1 n + Pell.d a1 * Pell.yn a1 m * Pell.yn a1 n

full_name: Pell.yn_add
code: theorem yn_add (m n) : yn a1 (m + n) = xn a1 m * yn a1 n + yn a1 m * xn a1 n 
goal: Pell.yn a1 (m + n) = Pell.xn a1 m * Pell.yn a1 n + Pell.yn a1 m * Pell.xn a1 n

full_name: Pell.pellZd_sub
code: theorem pellZd_sub {m n} (h : n ≤ m) : pellZd a1 (m - n) = pellZd a1 m * star (pellZd a1 n) 
goal: Pell.pellZd a1 (m - n) = Pell.pellZd a1 m * star (Pell.pellZd a1 n)

full_name: Pell.xz_sub
code: theorem xz_sub {m n} (h : n ≤ m) :
    xz a1 (m - n) = xz a1 m * xz a1 n - d a1 * yz a1 m * yz a1 n 
goal: Pell.xz a1 (m - n) = Pell.xz a1 m * Pell.xz a1 n - ↑(Pell.d a1) * Pell.yz a1 m * Pell.yz a1 n

full_name: Pell.yz_sub
code: theorem yz_sub {m n} (h : n ≤ m) : yz a1 (m - n) = xz a1 n * yz a1 m - xz a1 m * yz a1 n 
goal: Pell.yz a1 (m - n) = Pell.xz a1 n * Pell.yz a1 m - Pell.xz a1 m * Pell.yz a1 n

full_name: Pell.xy_coprime
code: theorem xy_coprime (n) : (xn a1 n).Coprime (yn a1 n) 
goal: (Pell.xn a1 n).Coprime (Pell.yn a1 n)

full_name: Pell.strictMono_y
code: theorem strictMono_y : StrictMono (yn a1)
  
goal: StrictMono (Pell.yn a1)

full_name: Pell.strictMono_x
code: theorem strictMono_x : StrictMono (xn a1)
  
goal: StrictMono (Pell.xn a1)

full_name: Pell.yn_ge_n
code: theorem yn_ge_n : ∀ n, n ≤ yn a1 n
  
goal: n ≤ Pell.yn a1 n

full_name: Pell.y_mul_dvd
code: theorem y_mul_dvd (n) : ∀ k, yn a1 n ∣ yn a1 (n * k)
  
goal: Pell.yn a1 n ∣ Pell.yn a1 (n * k)

full_name: Pell.y_dvd_iff
code: theorem y_dvd_iff (m n) : yn a1 m ∣ yn a1 n ↔ m ∣ n 
goal: Pell.yn a1 m ∣ Pell.yn a1 n ↔ m ∣ n

full_name: Pell.xy_modEq_yn
code: theorem xy_modEq_yn (n) :
    ∀ k, xn a1 (n * k) ≡ xn a1 n ^ k [MOD yn a1 n ^ 2] ∧ yn a1 (n * k) ≡
        k * xn a1 n ^ (k - 1) * yn a1 n [MOD yn a1 n ^ 3]
  
goal: Pell.xn a1 (n * k) ≡ Pell.xn a1 n ^ k [MOD Pell.yn a1 n ^ 2] ∧
  Pell.yn a1 (n * k) ≡ k * Pell.xn a1 n ^ (k - 1) * Pell.yn a1 n [MOD Pell.yn a1 n ^ 3]

full_name: Pell.ysq_dvd_yy
code: theorem ysq_dvd_yy (n) : yn a1 n * yn a1 n ∣ yn a1 (n * yn a1 n) 
goal: Pell.yn a1 n * Pell.yn a1 n ∣ Pell.yn a1 (n * Pell.yn a1 n)

full_name: Pell.dvd_of_ysq_dvd
code: theorem dvd_of_ysq_dvd {n t} (h : yn a1 n * yn a1 n ∣ yn a1 t) : yn a1 n ∣ t 
goal: Pell.yn a1 n ∣ t

full_name: Pell.pellZd_succ_succ
code: theorem pellZd_succ_succ (n) :
    pellZd a1 (n + 2) + pellZd a1 n = (2 * a : ℕ) * pellZd a1 (n + 1) 
goal: Pell.pellZd a1 (n + 2) + Pell.pellZd a1 n = ↑(2 * a) * Pell.pellZd a1 (n + 1)

full_name: Pell.xy_succ_succ
code: theorem xy_succ_succ (n) :
    xn a1 (n + 2) + xn a1 n =
      2 * a * xn a1 (n + 1) ∧ yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) 
goal: Pell.xn a1 (n + 2) + Pell.xn a1 n = 2 * a * Pell.xn a1 (n + 1) ∧
  Pell.yn a1 (n + 2) + Pell.yn a1 n = 2 * a * Pell.yn a1 (n + 1)

full_name: Pell.xn_succ_succ
code: theorem xn_succ_succ (n) : xn a1 (n + 2) + xn a1 n = 2 * a * xn a1 (n + 1) 
goal: Pell.xn a1 (n + 2) + Pell.xn a1 n = 2 * a * Pell.xn a1 (n + 1)

full_name: Pell.yn_succ_succ
code: theorem yn_succ_succ (n) : yn a1 (n + 2) + yn a1 n = 2 * a * yn a1 (n + 1) 
goal: Pell.yn a1 (n + 2) + Pell.yn a1 n = 2 * a * Pell.yn a1 (n + 1)

full_name: Pell.xz_succ_succ
code: theorem xz_succ_succ (n) : xz a1 (n + 2) = (2 * a : ℕ) * xz a1 (n + 1) - xz a1 n 
goal: Pell.xz a1 (n + 2) = ↑(2 * a) * Pell.xz a1 (n + 1) - Pell.xz a1 n

full_name: Pell.yz_succ_succ
code: theorem yz_succ_succ (n) : yz a1 (n + 2) = (2 * a : ℕ) * yz a1 (n + 1) - yz a1 n 
goal: Pell.yz a1 (n + 2) = ↑(2 * a) * Pell.yz a1 (n + 1) - Pell.yz a1 n

full_name: Pell.yn_modEq_a_sub_one
code: theorem yn_modEq_a_sub_one : ∀ n, yn a1 n ≡ n [MOD a - 1]
  
goal: Pell.yn a1 n ≡ n [MOD a - 1]

full_name: Pell.yn_modEq_two
code: theorem yn_modEq_two : ∀ n, yn a1 n ≡ n [MOD 2]
  
goal: Pell.yn a1 n ≡ n [MOD 2]

full_name: Pell.x_sub_y_dvd_pow_lem
code: theorem x_sub_y_dvd_pow_lem (y2 y1 y0 yn1 yn0 xn1 xn0 ay a2 : ℤ) :
    (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) =
      y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0) 
goal: (a2 * yn1 - yn0) * ay + y2 - (a2 * xn1 - xn0) = y2 - a2 * y1 + y0 + a2 * (yn1 * ay + y1 - xn1) - (yn0 * ay + y0 - xn0)

full_name: Pell.x_sub_y_dvd_pow
code: theorem x_sub_y_dvd_pow (y : ℕ) :
    ∀ n, (2 * a * y - y * y - 1 : ℤ) ∣ yz a1 n * (a - y) + ↑(y ^ n) - xz a1 n
  
goal: 2 * ↑a * ↑y - ↑y * ↑y - 1 ∣ Pell.yz a1 n * (↑a - ↑y) + ↑(y ^ n) - Pell.xz a1 n

full_name: Pell.xn_modEq_x2n_add_lem
code: theorem xn_modEq_x2n_add_lem (n j) : xn a1 n ∣ d a1 * yn a1 n * (yn a1 n * xn a1 j) + xn a1 j 
goal: Pell.xn a1 n ∣ Pell.d a1 * Pell.yn a1 n * (Pell.yn a1 n * Pell.xn a1 j) + Pell.xn a1 j

full_name: Pell.xn_modEq_x2n_add
code: theorem xn_modEq_x2n_add (n j) : xn a1 (2 * n + j) + xn a1 j ≡ 0 [MOD xn a1 n] 
goal: Pell.xn a1 (2 * n + j) + Pell.xn a1 j ≡ 0 [MOD Pell.xn a1 n]

full_name: Pell.xn_modEq_x2n_sub_lem
code: theorem xn_modEq_x2n_sub_lem {n j} (h : j ≤ n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] 
goal: Pell.xn a1 (2 * n - j) + Pell.xn a1 j ≡ 0 [MOD Pell.xn a1 n]

full_name: Pell.xn_modEq_x2n_sub
code: theorem xn_modEq_x2n_sub {n j} (h : j ≤ 2 * n) : xn a1 (2 * n - j) + xn a1 j ≡ 0 [MOD xn a1 n] 
goal: Pell.xn a1 (2 * n - j) + Pell.xn a1 j ≡ 0 [MOD Pell.xn a1 n]

full_name: Pell.xn_modEq_x4n_add
code: theorem xn_modEq_x4n_add (n j) : xn a1 (4 * n + j) ≡ xn a1 j [MOD xn a1 n] 
goal: Pell.xn a1 (4 * n + j) ≡ Pell.xn a1 j [MOD Pell.xn a1 n]

full_name: Pell.xn_modEq_x4n_sub
code: theorem xn_modEq_x4n_sub {n j} (h : j ≤ 2 * n) : xn a1 (4 * n - j) ≡ xn a1 j [MOD xn a1 n] 
goal: Pell.xn a1 (4 * n - j) ≡ Pell.xn a1 j [MOD Pell.xn a1 n]

full_name: Pell.eq_of_xn_modEq_lem1
code: theorem eq_of_xn_modEq_lem1 {i n} : ∀ {j}, i < j → j < n → xn a1 i % xn a1 n < xn a1 j % xn a1 n
  
goal: i < j → j < n → Pell.xn a1 i % Pell.xn a1 n < Pell.xn a1 j % Pell.xn a1 n

full_name: Pell.eq_of_xn_modEq_lem2
code: theorem eq_of_xn_modEq_lem2 {n} (h : 2 * xn a1 n = xn a1 (n + 1)) : a = 2 ∧ n = 0 
goal: a = 2 ∧ n = 0

full_name: Pell.eq_of_xn_modEq_lem3
code: theorem eq_of_xn_modEq_lem3 {i n} (npos : 0 < n) :
    ∀ {j}, i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) →
        xn a1 i % xn a1 n < xn a1 j % xn a1 n
  
goal: i < j → j ≤ 2 * n → j ≠ n → ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2) → Pell.xn a1 i % Pell.xn a1 n < Pell.xn a1 j % Pell.xn a1 n

full_name: Pell.eq_of_xn_modEq_le
code: theorem eq_of_xn_modEq_le {i j n} (ij : i ≤ j) (j2n : j ≤ 2 * n)
    (h : xn a1 i ≡ xn a1 j [MOD xn a1 n])
    (ntriv : ¬(a = 2 ∧ n = 1 ∧ i = 0 ∧ j = 2)) : i = j 
goal: i = j

full_name: Pell.eq_of_xn_modEq
code: theorem eq_of_xn_modEq {i j n} (i2n : i ≤ 2 * n) (j2n : j ≤ 2 * n)
    (h : xn a1 i ≡ xn a1 j [MOD xn a1 n])
    (ntriv : a = 2 → n = 1 → (i = 0 → j ≠ 2) ∧ (i = 2 → j ≠ 0)) : i = j 
goal: i = j

full_name: Pell.eq_of_xn_modEq'
code: theorem eq_of_xn_modEq' {i j n} (ipos : 0 < i) (hin : i ≤ n) (j4n : j ≤ 4 * n)
    (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) : j = i ∨ j + i = 4 * n 
goal: j = i ∨ j + i = 4 * n

full_name: Pell.modEq_of_xn_modEq
code: theorem modEq_of_xn_modEq {i j n} (ipos : 0 < i) (hin : i ≤ n)
    (h : xn a1 j ≡ xn a1 i [MOD xn a1 n]) :
    j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n] 
goal: j ≡ i [MOD 4 * n] ∨ j + i ≡ 0 [MOD 4 * n]

full_name: Pell.xy_modEq_of_modEq
code: theorem xy_modEq_of_modEq {a b c} (a1 : 1 < a) (b1 : 1 < b) (h : a ≡ b [MOD c]) :
    ∀ n, xn a1 n ≡ xn b1 n [MOD c] ∧ yn a1 n ≡ yn b1 n [MOD c]
  
goal: Pell.xn a1 n ≡ Pell.xn b1 n [MOD c] ∧ Pell.yn a1 n ≡ Pell.yn b1 n [MOD c]

full_name: Pell.matiyasevic
code: theorem matiyasevic {a k x y} :
    (∃ a1 : 1 < a, xn a1 k = x ∧ yn a1 k = y) ↔
      1 < a ∧ k ≤ y ∧ (x = 1 ∧ y = 0 ∨
        ∃ u v s t b : ℕ,
          x * x - (a * a - 1) * y * y = 1 ∧ u * u - (a * a - 1) * v * v = 1 ∧
          s * s - (b * b - 1) * t * t = 1 ∧ 1 < b ∧ b ≡ 1 [MOD 4 * y] ∧
          b ≡ a [MOD u] ∧ 0 < v ∧ y * y ∣ v ∧ s ≡ x [MOD u] ∧ t ≡ k [MOD 4 * y]) 
goal: (∃ (a1 : 1 < a), Pell.xn a1 k = x ∧ Pell.yn a1 k = y) ↔
  1 < a ∧
    k ≤ y ∧
      (x = 1 ∧ y = 0 ∨
        ∃ u v s t b,
          x * x - (a * a - 1) * y * y = 1 ∧
            u * u - (a * a - 1) * v * v = 1 ∧
              s * s - (b * b - 1) * t * t = 1 ∧
                1 < b ∧ b ≡ 1 [MOD 4 * y] ∧ b ≡ a [MOD u] ∧ 0 < v ∧ y * y ∣ v ∧ s ≡ x [MOD u] ∧ t ≡ k [MOD 4 * y])

full_name: Pell.eq_pow_of_pell_lem
code: theorem eq_pow_of_pell_lem {a y k : ℕ} (hy0 : y ≠ 0) (hk0 : k ≠ 0) (hyk : y ^ k < a) :
    (↑(y ^ k) : ℤ) < 2 * a * y - y * y - 1 
goal: ↑(y ^ k) < 2 * ↑a * ↑y - ↑y * ↑y - 1

full_name: Pell.eq_pow_of_pell
code: theorem eq_pow_of_pell {m n k} :
    n ^ k = m ↔ k = 0 ∧ m = 1 ∨0 < k ∧ (n = 0 ∧ m = 0 ∨
      0 < n ∧ ∃ (w a t z : ℕ) (a1 : 1 < a), xn a1 k ≡ yn a1 k * (a - n) + m [MOD t] ∧
      2 * a * n = t + (n * n + 1) ∧ m < t ∧
      n ≤ w ∧ k ≤ w ∧ a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1) 
goal: n ^ k = m ↔
  k = 0 ∧ m = 1 ∨
    0 < k ∧
      (n = 0 ∧ m = 0 ∨
        0 < n ∧
          ∃ w a t z,
            ∃ (a1 : 1 < a),
              Pell.xn a1 k ≡ Pell.yn a1 k * (a - n) + m [MOD t] ∧
                2 * a * n = t + (n * n + 1) ∧
                  m < t ∧ n ≤ w ∧ k ≤ w ∧ a * a - ((w + 1) * (w + 1) - 1) * (w * z) * (w * z) = 1)