-- Mathlib/Algebra/ContinuedFractions/Determinant.lean
theorem determinant_aux (hyp : n = 0 ∨ ¬(↑s : GenContFract K).TerminatedAt (n - 1)) :
    ((↑s : GenContFract K).contsAux n).a * ((↑s : GenContFract K).contsAux (n + 1)).b -
      ((↑s : GenContFract K).contsAux n).b * ((↑s : GenContFract K).contsAux (n + 1)).a =
        (-1) ^ n

Proof state:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
pred_conts_eq : pred_conts = g.contsAux (n + 1)
ppred_conts : Pair K := g.contsAux n
IH : n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = g.contsAux n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬g.TerminatedAt n
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)

Tactic:
obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
  Option.ne_none_iff_exists'.1 not_terminated_at_n

Result:
case succ.intro
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
pred_conts_eq : pred_conts = g.contsAux (n + 1)
ppred_conts : Pair K := g.contsAux n
IH : n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = g.contsAux n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬g.TerminatedAt n
gp : Pair K
s_nth_eq : g.s.get? n = some gp
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)

Proof state:
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
pred_conts_eq : pred_conts = g.contsAux (n + 1)
ppred_conts : Pair K := g.contsAux n
IH : n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = g.contsAux n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
not_terminated_at_n : ¬g.TerminatedAt n
gp : Pair K
s_nth_eq : g.s.get? n = some gp
this : pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)
gp_a_eq_one : gp.a = 1
⊢ pA * (gp.b * (g.contsAux (n + 1)).b + 1 * (g.contsAux n).b) -
      pB * (gp.b * (g.contsAux (n + 1)).a + 1 * (g.contsAux n).a) =
    pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA)

Tactic:
ring

Result:
no goals

Proof state:
case zero
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n : ℕ
hyp : 0 = 0 ∨ ¬(↑s).TerminatedAt (0 - 1)
⊢ ((↑s).contsAux 0).a * ((↑s).contsAux (0 + 1)).b - ((↑s).contsAux 0).b * ((↑s).contsAux (0 + 1)).a = (-1) ^ 0

Tactic:
simp [contsAux]

Result:
no goals

Proof state:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
pred_conts_eq : pred_conts = g.contsAux (n + 1)
ppred_conts : Pair K := g.contsAux n
IH : n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = g.contsAux n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
⊢ pred_conts.a * ((↑s).contsAux (n + 1 + 1)).b - pred_conts.b * ((↑s).contsAux (n + 1 + 1)).a = (-1) ^ (n + 1)

Tactic:
change pA * conts.b - pB * conts.a = (-1) ^ (n + 1)

Result:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
pred_conts_eq : pred_conts = g.contsAux (n + 1)
ppred_conts : Pair K := g.contsAux n
IH : n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = g.contsAux n
pA : K := pred_conts.a
pB : K := pred_conts.b
ppA : K := ppred_conts.a
ppB : K := ppred_conts.b
⊢ pA * conts.b - pB * conts.a = (-1) ^ (n + 1)

Proof state:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
IH :
  n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) →
    ((↑s).contsAux n).a * ((↑s).contsAux (n + 1)).b - ((↑s).contsAux n).b * ((↑s).contsAux (n + 1)).a = (-1) ^ n
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
⊢ ((↑s).contsAux (n + 1)).a * ((↑s).contsAux (n + 1 + 1)).b -
      ((↑s).contsAux (n + 1)).b * ((↑s).contsAux (n + 1 + 1)).a =
    (-1) ^ (n + 1)

Tactic:
let g := (↑s : GenContFract K)

Result:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
IH :
  n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) →
    ((↑s).contsAux n).a * ((↑s).contsAux (n + 1)).b - ((↑s).contsAux n).b * ((↑s).contsAux (n + 1)).a = (-1) ^ n
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
⊢ ((↑s).contsAux (n + 1)).a * ((↑s).contsAux (n + 1 + 1)).b -
      ((↑s).contsAux (n + 1)).b * ((↑s).contsAux (n + 1 + 1)).a =
    (-1) ^ (n + 1)

Proof state:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
IH :
  n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) →
    ((↑s).contsAux n).a * pred_conts.b - ((↑s).contsAux n).b * pred_conts.a = (-1) ^ n
pred_conts_eq : pred_conts = g.contsAux (n + 1)
⊢ pred_conts.a * ((↑s).contsAux (n + 1 + 1)).b - pred_conts.b * ((↑s).contsAux (n + 1 + 1)).a = (-1) ^ (n + 1)

Tactic:
set ppred_conts := contsAux g n with ppred_conts_eq

Result:
case succ
K : Type u_1
inst✝ : Field K
s : SimpContFract K
n✝ n : ℕ
hyp : n + 1 = 0 ∨ ¬(↑s).TerminatedAt (n + 1 - 1)
g : GenContFract K := ↑s
conts : Pair K := g.contsAux (n + 2)
pred_conts : Pair K := g.contsAux (n + 1)
pred_conts_eq : pred_conts = g.contsAux (n + 1)
ppred_conts : Pair K := g.contsAux n
IH : n = 0 ∨ ¬(↑s).TerminatedAt (n - 1) → ppred_conts.a * pred_conts.b - ppred_conts.b * pred_conts.a = (-1) ^ n
ppred_conts_eq : ppred_conts = g.contsAux n
⊢ pred_conts.a * ((↑s).contsAux (n + 1 + 1)).b - pred_conts.b * ((↑s).contsAux (n + 1 + 1)).a = (-1) ^ (n + 1)