-- 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:
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)
⊢ pA * (gp.b * (g.contsAux (n + 1)).b + gp.a * (g.contsAux n).b) -
      pB * (gp.b * (g.contsAux (n + 1)).a + gp.a * (g.contsAux n).a) =
    (-1) ^ (n + 1)

Tactic:
have gp_a_eq_one : gp.a = 1 := s.property _ _ (partNum_eq_s_a s_nth_eq)

Result:
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 + gp.a * (g.contsAux n).b) -
      pB * (gp.b * (g.contsAux (n + 1)).a + gp.a * (g.contsAux n).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 - pB * ppA = (-1) ^ (n + 1)
⊢ pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA

Tactic:
ring

Result:
no goals

Proof state:
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 * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)

Tactic:
suffices pA * ppB - pB * ppA = (-1) ^ (n + 1) by calc
  pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) =
      pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA := by ring
  _ = pA * ppB - pB * ppA := by ring
  _ = (-1) ^ (n + 1) := by assumption

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 * ppB - pB * ppA = (-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 - pB * ppA = (-1) ^ (n + 1)
⊢ pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (-1) ^ (n + 1)

Tactic:
calc
pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) =
pA * ppB + pA * gp.b * pB - pB * ppA - pB * gp.b * pA := by ring
_ = pA * ppB - pB * ppA := by ring
_ = (-1) ^ (n + 1) := by assumption

Result:
no goals

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 + gp.a * (g.contsAux n).b) -
      pB * (gp.b * (g.contsAux (n + 1)).a + gp.a * (g.contsAux n).a) =
    (-1) ^ (n + 1)

Tactic:
rw [gp_a_eq_one, this.symm]

Result:
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)