Skip to content

Commit 30f4950

Browse files
emlis42ocfnashurkud
committed
feat(Algebra/ContinuedFractions): generalize determinant formula to GenContFract (#37997)
Let $g$ be a `GenContFract K`. In this PR I generalize the determinant formula for continued fractions from the simple continued fraction case $$A_n B_{n+1} - B_n A_{n+1} = (-1)^n$$ to the generalized continued fraction product formula $$A_n B_{n+1} - B_n A_{n+1} = (-a_0) (-a_1) \dots (-a_n)$$ - The `SimpContFract` version is still available unchanged, so this should avoid breaking existing users of the old API. - The use of `0` as the default partial numerator in `(g.partNums.get? i).getD 0` allows product formulation that remains valid when the fraction is terminated. Co-authored-by: Oliver Nash <7734364+ocfnash@users.noreply.github.com> Co-authored-by: Yury G. Kudryashov <urkud@urkud.name>
1 parent 9dd2956 commit 30f4950

2 files changed

Lines changed: 51 additions & 28 deletions

File tree

Mathlib/Algebra/ContinuedFractions/Computation/Approximations.lean

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,14 @@ theorem sub_convs_eq {ifp : IntFractPair K}
366366
have : ¬g.TerminatedAt n' :=
367367
(not_congr of_terminatedAt_n_iff_succ_nth_intFractPair_stream_eq_none).2 this
368368
exact Or.inr this
369-
have determinant_eq : pA * B - pB * A = (-1) ^ n :=
370-
(SimpContFract.of v).determinant_aux n_eq_zero_or_not_terminatedAt_pred_n
369+
have determinant_eq : pA * B - pB * A = (-1) ^ n := by
370+
match hn : n with
371+
| 0 => subst n; simp [pA, pB, A, B, pred_conts, conts]
372+
| n' + 1 =>
373+
subst n
374+
simp only [succ_ne_zero, false_or] at n_eq_zero_or_not_terminatedAt_pred_n
375+
rw [add_tsub_cancel_right] at n_eq_zero_or_not_terminatedAt_pred_n
376+
exact (SimpContFract.of v).determinant n_eq_zero_or_not_terminatedAt_pred_n
371377
-- now all we got to do is to rewrite this equality in our goal and re-arrange terms;
372378
-- however, for this, we first have to derive quite a few tedious inequalities.
373379
have pB_ineq : (fib n : K) ≤ pB :=

Mathlib/Algebra/ContinuedFractions/Determinant.lean

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,16 @@ Authors: Kevin Kappelmann
55
-/
66
module
77

8+
public import Mathlib.Algebra.BigOperators.Group.Finset.Basic
89
public import Mathlib.Algebra.ContinuedFractions.ContinuantsRecurrence
910
public import Mathlib.Algebra.ContinuedFractions.TerminatedStable
1011
public 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

3327
open 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`. -/
7080
theorem 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

7592
end SimpContFract

0 commit comments

Comments
 (0)