@@ -5,22 +5,16 @@ Authors: Kevin Kappelmann
55-/
66module
77
8+ public import Mathlib.Algebra.BigOperators.Group.Finset.Basic
89public import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence
910public import Mathlib.Algebra.ContinuedFractions.TerminatedStable
1011public import Mathlib.Tactic.Ring
1112
1213/-!
13- # Determinant Formula for Simple Continued Fraction
14+ # Determinant Formula for Generalized Continued Fraction
1415
15- ## Summary
16-
17- We derive the so-called *determinant formula* for `SimpContFract`:
18- `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`.
19-
20- ## TODO
21-
22- Generalize this for `GenContFract` version:
23- `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-a₀) * (-a₁) * .. * (-aₙ₊₁)`.
16+ We derive the so-called *determinant formula* for `GenContFract`:
17+ `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-a₀) * (-a₁) * .. * (-aₙ)`.
2418
2519## References
2620
@@ -32,19 +26,20 @@ public section
3226
3327open GenContFract
3428
35- namespace SimpContFract
29+ variable {K : Type *} [Field K]
30+
31+ namespace GenContFract
3632
37- variable {K : Type *} [Field K] {s : SimpContFract K} {n : ℕ}
33+ variable {g : GenContFract K} {n : ℕ}
3834
39- theorem determinant_aux (hyp : n = 0 ∨ ¬(↑s : GenContFract K) .TerminatedAt (n - 1 )) :
40- ((↑s : GenContFract K) .contsAux n).a * ((↑s : GenContFract K) .contsAux (n + 1 )).b -
41- ((↑s : GenContFract K) .contsAux n).b * ((↑s : GenContFract K) .contsAux (n + 1 )).a =
42- (- 1 ) ^ n := by
35+ private theorem determinant_aux (hyp : n = 0 ∨ ¬g .TerminatedAt (n - 1 )) :
36+ (g .contsAux n).a * (g .contsAux (n + 1 )).b -
37+ (g .contsAux n).b * (g .contsAux (n + 1 )).a =
38+ ∏ i ∈ Finset.range n, - (g.partNums.get? i).getD 0 := by
4339 induction n with
4440 | zero => simp [contsAux]
4541 | succ n IH =>
4642 -- set up some shorthand notation
47- let g := (↑s : GenContFract K)
4843 let conts := contsAux g (n + 2 )
4944 set pred_conts := contsAux g (n + 1 ) with pred_conts_eq
5045 set ppred_conts := contsAux g n with ppred_conts_eq
@@ -53,23 +48,45 @@ theorem determinant_aux (hyp : n = 0 ∨ ¬(↑s : GenContFract K).TerminatedAt
5348 let ppA := ppred_conts.a
5449 let ppB := ppred_conts.b
5550 -- let's change the goal to something more readable
56- change pA * conts.b - pB * conts.a = (- 1 ) ^ (n + 1 )
51+ change pA * conts.b - pB * conts.a = ∏ i ∈ Finset.range (n + 1 ), -(g.partNums.get? i).getD 0
5752 have not_terminated_at_n : ¬TerminatedAt g n := Or.resolve_left hyp n.succ_ne_zero
5853 obtain ⟨gp, s_nth_eq⟩ : ∃ gp, g.s.get? n = some gp :=
5954 Option.ne_none_iff_exists'.1 not_terminated_at_n
6055 -- unfold the recurrence relation for `conts` once and simplify to derive the following
61- suffices pA * (ppB + gp.b * pB) - pB * (ppA + gp.b * pA) = (- 1 ) ^ (n + 1 ) by
62- simp only [conts, contsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq ]
63- have gp_a_eq_one : gp.a = 1 := s.property _ _ (partNum_eq_s_a s_nth_eq)
64- rw [gp_a_eq_one, this.symm ]
56+ suffices ppA * pB - ppB * pA = ∏ i ∈ Finset.range n, - (g.partNums.get? i).getD 0 by
57+ rw [Finset.prod_range_succ, ← this, partNum_eq_s_a s_nth_eq, Option.getD_some ]
58+ subst conts
59+ rw [contsAux_recurrence s_nth_eq ppred_conts_eq pred_conts_eq ]
6560 ring
66- suffices ppA * pB - ppB * pA = (-1 ) ^ n by grind
6761 exact IH <| Or.inr <| mt (terminated_stable <| n.sub_le 1 ) not_terminated_at_n
6862
69- /-- The determinant formula `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1)^(n + 1)`. -/
63+ /-- The determinant formula `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-a₀) * (-a₁) * .. * (-aₙ)`. -/
64+ theorem determinant :
65+ g.nums n * g.dens (n + 1 ) - g.dens n * g.nums (n + 1 ) =
66+ ∏ i ∈ Finset.range (n + 1 ), - (g.partNums.get? i).getD 0 := by
67+ rcases em <| TerminatedAt g n with terminatedAt_n | not_terminatedAt_n
68+ · rw [dens_stable_of_terminated n.le_succ terminatedAt_n,
69+ nums_stable_of_terminated n.le_succ terminatedAt_n, Finset.prod_range_succ,
70+ partNum_none_iff_s_none.mpr terminatedAt_n]
71+ grind
72+ · exact determinant_aux <| Or.inr <| not_terminatedAt_n
73+ end GenContFract
74+
75+ namespace SimpContFract
76+
77+ variable {s : SimpContFract K} {n : ℕ}
78+
79+ /-- The determinant formula `Aₙ * Bₙ₊₁ - Bₙ * Aₙ₊₁ = (-1) ^ (n + 1)` for `SimpContFract`. -/
7080theorem determinant (not_terminatedAt_n : ¬(↑s : GenContFract K).TerminatedAt n) :
7181 (↑s : GenContFract K).nums n * (↑s : GenContFract K).dens (n + 1 ) -
72- (↑s : GenContFract K).dens n * (↑s : GenContFract K).nums (n + 1 ) = (-1 ) ^ (n + 1 ) :=
73- determinant_aux <| Or.inr <| not_terminatedAt_n
82+ (↑s : GenContFract K).dens n * (↑s : GenContFract K).nums (n + 1 ) = (-1 ) ^ (n + 1 ) := calc
83+ _ = ∏ i ∈ Finset.range (n + 1 ), - ((↑s : GenContFract K).partNums.get? i).getD 0 :=
84+ (↑s : GenContFract K).determinant
85+ _ = ∏ i ∈ Finset.range (n + 1 ), -1 := Finset.prod_congr rfl fun i hi ↦ by
86+ rw [Finset.mem_range] at hi
87+ obtain ⟨gp, s_ith_eq⟩ : ∃ gp, (↑s : GenContFract K).s.get? i = some gp :=
88+ Option.ne_none_iff_exists'.1 <| mt (terminated_stable <| Nat.le_of_succ_le_succ hi) ‹_›
89+ rw [partNum_eq_s_a s_ith_eq, s.property i gp.a <| partNum_eq_s_a s_ith_eq, Option.getD_some]
90+ _ = (-1 ) ^ (n + 1 ) := by rw [Finset.prod_const, Finset.card_range]
7491
7592end SimpContFract
0 commit comments