@@ -9,32 +9,38 @@ import algebra.continued_fractions.continuants_recurrence
9
9
import order.filter.at_top_bot
10
10
11
11
/-!
12
- # Correctness of Terminating Continued Fraction Computations (`gcf .of`)
12
+ # Correctness of Terminating Continued Fraction Computations (`generalized_continued_fraction .of`)
13
13
14
14
## Summary
15
15
16
- Let us write `gcf` for `generalized_continued_fraction`. We show the correctness of the
17
- algorithm computing continued fractions (`gcf.of`) in case of termination in the following sense:
16
+ We show the correctness of the
17
+ algorithm computing continued fractions (`generalized_continued_fraction.of`) in case of termination
18
+ in the following sense:
18
19
19
20
At every step `n : ℕ`, we can obtain the value `v` by adding a specific residual term to the last
20
- denominator of the fraction described by `(gcf.of v).convergents' n`. The residual term will be zero
21
- exactly when the continued fraction terminated; otherwise, the residual term will be given by the
22
- fractional part stored in `gcf.int_fract_pair.stream v n`.
21
+ denominator of the fraction described by `(generalized_continued_fraction.of v).convergents' n`.
22
+ The residual term will be zero exactly when the continued fraction terminated; otherwise, the
23
+ residual term will be given by the fractional part stored in
24
+ `generalized_continued_fraction.int_fract_pair.stream v n`.
23
25
24
- For an example, refer to `gcf.comp_exact_value_correctness_of_stream_eq_some` and for more
26
+ For an example, refer to
27
+ `generalized_continued_fraction.comp_exact_value_correctness_of_stream_eq_some` and for more
25
28
information about the computation process, refer to `algebra.continued_fraction.computation.basic`.
26
29
27
30
## Main definitions
28
31
29
- - `gcf.comp_exact_value` can be used to compute the exact value approximated by the continued
30
- fraction `gcf.of v` by adding a residual term as described in the summary.
32
+ - `generalized_continued_fraction.comp_exact_value` can be used to compute the exact value
33
+ approximated by the continued fraction `generalized_continued_fraction.of v` by adding a residual
34
+ term as described in the summary.
31
35
32
36
## Main Theorems
33
37
34
- - `gcf.comp_exact_value_correctness_of_stream_eq_some` shows that `gcf.comp_exact_value` indeed
35
- returns the value `v` when given the convergent and fractional part as described in the summary.
36
- - `gcf.of_correctness_of_terminated_at` shows the equality `v = (gcf.of v).convergents n`
37
- if `gcf.of v` terminated at position `n`.
38
+ - `generalized_continued_fraction.comp_exact_value_correctness_of_stream_eq_some` shows that
39
+ `generalized_continued_fraction.comp_exact_value` indeed returns the value `v` when given the
40
+ convergent and fractional part as described in the summary.
41
+ - `generalized_continued_fraction.of_correctness_of_terminated_at` shows the equality
42
+ `v = (generalized_continued_fraction.of v).convergents n` if `generalized_continued_fraction.of v`
43
+ terminated at position `n`.
38
44
-/
39
45
40
46
namespace generalized_continued_fraction
@@ -48,8 +54,9 @@ Given two continuants `pconts` and `conts` and a value `fr`, this function retur
48
54
- `exact_conts.a / exact_conts.b` where `exact_conts = next_continuants 1 fr⁻¹ pconts conts`
49
55
otherwise.
50
56
51
- This function can be used to compute the exact value approxmated by a continued fraction `gcf.of v`
52
- as described in lemma `comp_exact_value_correctness_of_stream_eq_some`.
57
+ This function can be used to compute the exact value approxmated by a continued fraction
58
+ `generalized_continued_fraction.of v` as described in lemma
59
+ `comp_exact_value_correctness_of_stream_eq_some`.
53
60
-/
54
61
protected def comp_exact_value (pconts conts : gcf.pair K) (fr : K) : K :=
55
62
-- if the fractional part is zero, we exactly approximated the value by the last continuants
@@ -69,20 +76,20 @@ by { field_simp [fract_a_ne_zero], rw [fract], ring }
69
76
open generalized_continued_fraction as gcf
70
77
71
78
/--
72
- Shows the correctness of `comp_exact_value` in case the continued fraction `gcf.of v` did not
73
- terminate at position `n`. That is, we obtain the value `v` if we pass the two successive
74
- (auxiliary) continuants at positions `n` and `n + 1` as well as the fractional part at
75
- `int_fract_pair.stream n` to `comp_exact_value`.
79
+ Shows the correctness of `comp_exact_value` in case the continued fraction
80
+ `generalized_continued_fraction.of v` did not terminate at position `n`. That is, we obtain the
81
+ value `v` if we pass the two successive (auxiliary) continuants at positions `n` and `n + 1` as well
82
+ as the fractional part at `int_fract_pair.stream n` to `comp_exact_value`.
76
83
77
84
The correctness might be seen more readily if one uses `convergents'` to evaluate the continued
78
85
fraction. Here is an example to illustrate the idea:
79
86
80
87
Let `(v : ℚ) := 3.4`. We have
81
- - `gcf .int_fract_pair.stream v 0 = some ⟨3, 0.4⟩`, and
82
- - `gcf .int_fract_pair.stream v 1 = some ⟨2, 0.5⟩`.
83
- Now `(gcf .of v).convergents' 1 = 3 + 1/2`, and our fractional term at position `2` is `0.5`. We
84
- hence have `v = 3 + 1/(2 + 0.5) = 3 + 1/2.5 = 3.4`. This computation corresponds exactly to the one
85
- using the recurrence equation in `comp_exact_value`.
88
+ - `generalized_continued_fraction .int_fract_pair.stream v 0 = some ⟨3, 0.4⟩`, and
89
+ - `generalized_continued_fraction .int_fract_pair.stream v 1 = some ⟨2, 0.5⟩`.
90
+ Now `(generalized_continued_fraction .of v).convergents' 1 = 3 + 1/2`, and our fractional term at
91
+ position `2` is `0.5`. We hence have `v = 3 + 1/(2 + 0.5) = 3 + 1/2.5 = 3.4`. This computation
92
+ corresponds exactly to the one using the recurrence equation in `comp_exact_value`.
86
93
-/
87
94
lemma comp_exact_value_correctness_of_stream_eq_some :
88
95
∀ {ifp_n : int_fract_pair K}, int_fract_pair.stream v n = some ifp_n →
@@ -173,8 +180,8 @@ begin
173
180
ac_refl } }
174
181
end
175
182
176
- /-- The convergent of `gcf .of v` at step `n - 1` is exactly `v` if the `int_fract_pair.stream` of
177
- the corresponding continued fraction terminated at step `n`. -/
183
+ /-- The convergent of `generalized_continued_fraction .of v` at step `n - 1` is exactly `v` if the
184
+ `int_fract_pair.stream` of the corresponding continued fraction terminated at step `n`. -/
178
185
lemma of_correctness_of_nth_stream_eq_none
179
186
(nth_stream_eq_none : int_fract_pair.stream v n = none) :
180
187
v = (gcf.of v).convergents (n - 1 ) :=
@@ -202,15 +209,20 @@ begin
202
209
(comp_exact_value_correctness_of_stream_eq_some nth_stream_eq) } }
203
210
end
204
211
205
- /-- If `gcf.of v` terminated at step `n`, then the `n`th convergent is exactly `v`. -/
212
+ /--
213
+ If `generalized_continued_fraction.of v` terminated at step `n`, then the `n`th convergent is
214
+ exactly `v`.
215
+ -/
206
216
theorem of_correctness_of_terminated_at (terminated_at_n : (gcf.of v).terminated_at n) :
207
217
v = (gcf.of v).convergents n :=
208
218
have int_fract_pair.stream v (n + 1 ) = none, from
209
219
gcf.of_terminated_at_n_iff_succ_nth_int_fract_pair_stream_eq_none.elim_left terminated_at_n,
210
220
of_correctness_of_nth_stream_eq_none this
211
221
212
- /-- If `gcf.of v` terminates, then there is `n : ℕ` such that the `n`th convergent is exactly
213
- `v`. -/
222
+ /--
223
+ If `generalized_continued_fraction.of v` terminates, then there is `n : ℕ` such that the `n`th
224
+ convergent is exactly `v`.
225
+ -/
214
226
lemma of_correctness_of_terminates (terminates : (gcf.of v).terminates) :
215
227
∃ (n : ℕ), v = (gcf.of v).convergents n :=
216
228
exists.elim terminates
@@ -219,7 +231,10 @@ exists.elim terminates
219
231
220
232
open filter
221
233
222
- /-- If `gcf.of v` terminates, then its convergents will eventually always be `v`. -/
234
+ /--
235
+ If `generalized_continued_fraction.of v` terminates, then its convergents will eventually always
236
+ be `v`.
237
+ -/
223
238
lemma of_correctness_at_top_of_terminates (terminates : (gcf.of v).terminates) :
224
239
∀ᶠ n in at_top, v = (gcf.of v).convergents n :=
225
240
begin
0 commit comments