|
| 1 | +/- |
| 2 | +Copyright (c) 2020 Kevin Kappelmann. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Kevin Kappelmann |
| 5 | +-/ |
| 6 | +import algebra.continued_fractions.translations |
| 7 | +/-! |
| 8 | +# Stabilisation of gcf Computations Under Termination |
| 9 | +
|
| 10 | +## Summary |
| 11 | +
|
| 12 | +We show that the continuants and convergents of a gcf stabilise once the gcf terminates. |
| 13 | +-/ |
| 14 | + |
| 15 | +namespace generalized_continued_fraction |
| 16 | +open generalized_continued_fraction as gcf |
| 17 | +variables {α : Type*} {g : gcf α} {n m : ℕ} |
| 18 | + |
| 19 | +/-- If a gcf terminated at position `n`, it also terminated at `m ≥ n`.-/ |
| 20 | +lemma terminated_stable (n_le_m : n ≤ m) (terminated_at_n : g.terminated_at n) : |
| 21 | + g.terminated_at m := |
| 22 | +g.s.terminated_stable n_le_m terminated_at_n |
| 23 | + |
| 24 | +variable [division_ring α] |
| 25 | + |
| 26 | +lemma continuants_aux_stable_step_of_terminated (terminated_at_n : g.terminated_at n) : |
| 27 | + g.continuants_aux (n + 2) = g.continuants_aux (n + 1) := |
| 28 | +by { rw [terminated_at_iff_s_none] at terminated_at_n, simp only [terminated_at_n, continuants_aux] } |
| 29 | + |
| 30 | +lemma continuants_aux_stable_of_terminated (succ_n_le_m : (n + 1) ≤ m) |
| 31 | + (terminated_at_n : g.terminated_at n) : |
| 32 | + g.continuants_aux m = g.continuants_aux (n + 1) := |
| 33 | +begin |
| 34 | + induction succ_n_le_m with m succ_n_le_m IH, |
| 35 | + { refl }, |
| 36 | + { have : g.continuants_aux (m + 1) = g.continuants_aux m, by |
| 37 | + { have : n ≤ m - 1, from nat.le_pred_of_lt succ_n_le_m, |
| 38 | + have : g.terminated_at (m - 1), from terminated_stable this terminated_at_n, |
| 39 | + have stable_step : g.continuants_aux (m - 1 + 2) = g.continuants_aux (m - 1 + 1), from |
| 40 | + continuants_aux_stable_step_of_terminated this, |
| 41 | + have one_le_m : 1 ≤ m, from nat.one_le_of_lt succ_n_le_m, |
| 42 | + have : m - 1 + 2 = m + 2 - 1, from (nat.sub_add_comm one_le_m).symm, |
| 43 | + have : m - 1 + 1 = m + 1 - 1, from (nat.sub_add_comm one_le_m).symm, |
| 44 | + simpa [*] using stable_step }, |
| 45 | + exact (eq.trans this IH) } |
| 46 | +end |
| 47 | + |
| 48 | +lemma convergents'_aux_stable_step_of_terminated {s : seq $ gcf.pair α} |
| 49 | + (terminated_at_n : s.terminated_at n) : |
| 50 | + convergents'_aux s (n + 1) = convergents'_aux s n := |
| 51 | +begin |
| 52 | + change s.nth n = none at terminated_at_n, |
| 53 | + induction n with n IH generalizing s, |
| 54 | + case nat.zero |
| 55 | + { simp only [convergents'_aux, terminated_at_n, seq.head] }, |
| 56 | + case nat.succ |
| 57 | + { cases s_head_eq : s.head with gp_head, |
| 58 | + case option.none { simp only [convergents'_aux, s_head_eq] }, |
| 59 | + case option.some |
| 60 | + { have : s.tail.terminated_at n, by simp only [seq.terminated_at, s.nth_tail, terminated_at_n], |
| 61 | + simp only [convergents'_aux, s_head_eq, (IH this)] }} |
| 62 | +end |
| 63 | + |
| 64 | +lemma convergents'_aux_stable_of_terminated {s : seq $ gcf.pair α} (n_le_m : n ≤ m) |
| 65 | + (terminated_at_n : s.terminated_at n) : |
| 66 | + convergents'_aux s m = convergents'_aux s n := |
| 67 | +begin |
| 68 | + induction n_le_m with m n_le_m IH generalizing s, |
| 69 | + { refl }, |
| 70 | + { cases s_head_eq : s.head with gp_head, |
| 71 | + case option.none { cases n; simp only [convergents'_aux, s_head_eq] }, |
| 72 | + case option.some |
| 73 | + { have : convergents'_aux s (n + 1) = convergents'_aux s n, from |
| 74 | + convergents'_aux_stable_step_of_terminated terminated_at_n, |
| 75 | + rw [←this], |
| 76 | + have : s.tail.terminated_at n, by |
| 77 | + simpa only [seq.terminated_at, seq.nth_tail] using (s.le_stable n.le_succ terminated_at_n), |
| 78 | + have : convergents'_aux s.tail m = convergents'_aux s.tail n, from IH this, |
| 79 | + simp only [convergents'_aux, s_head_eq, this] }} |
| 80 | +end |
| 81 | + |
| 82 | +lemma continuants_stable_of_terminated (n_le_m : n ≤ m) (terminated_at_n : g.terminated_at n) : |
| 83 | + g.continuants m = g.continuants n := |
| 84 | +by simp only [nth_cont_eq_succ_nth_cont_aux, |
| 85 | + (continuants_aux_stable_of_terminated (nat.pred_le_iff.elim_left n_le_m) terminated_at_n)] |
| 86 | + |
| 87 | +lemma numerators_stable_of_terminated (n_le_m : n ≤ m) (terminated_at_n : g.terminated_at n) : |
| 88 | + g.numerators m = g.numerators n := |
| 89 | +by simp only [num_eq_conts_a, (continuants_stable_of_terminated n_le_m terminated_at_n)] |
| 90 | + |
| 91 | +lemma denominators_stable_of_terminated (n_le_m : n ≤ m) (terminated_at_n : g.terminated_at n) : |
| 92 | + g.denominators m = g.denominators n := |
| 93 | +by simp only [denom_eq_conts_b, (continuants_stable_of_terminated n_le_m terminated_at_n)] |
| 94 | + |
| 95 | +lemma convergents_stable_of_terminated (n_le_m : n ≤ m) (terminated_at_n : g.terminated_at n) : |
| 96 | + g.convergents m = g.convergents n := |
| 97 | +by simp only [convergents, (denominators_stable_of_terminated n_le_m terminated_at_n), |
| 98 | + (numerators_stable_of_terminated n_le_m terminated_at_n)] |
| 99 | + |
| 100 | +lemma convergents'_stable_of_terminated (n_le_m : n ≤ m) (terminated_at_n : g.terminated_at n) : |
| 101 | + g.convergents' m = g.convergents' n := |
| 102 | +by simp only [convergents', (convergents'_aux_stable_of_terminated n_le_m terminated_at_n)] |
| 103 | + |
| 104 | +end generalized_continued_fraction |
0 commit comments