You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sources/creating-continued-fractions.rst
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,7 +152,7 @@ Then we can iteratively construct more accurate ``ContinuedFraction`` approximat
152
152
153
153
With the first :math:`10` elements of the complete sequence of elements of the continued fraction representation of :math:`\sqrt{2}` we have obtained an approximation that is accurate to :math:`6` decimal places. We'd ideally like to have as few elements as possible in our ``ContinuedFraction`` approximation of :math:`\sqrt{2}` for a desired level of accuracy, but this partly depends on how fast the partial, finite continued fractions represented by the chosen sequences of elements in our approximations are converging to the true value of :math:`\sqrt{2}` - these partial, finite continued fractions in a continued fraction representation are called convergents, and will be discussed in more detail later on.
154
154
155
-
This example also highlights the higher density of irrational numbers as compared to rational numbers
155
+
This example also highlights the fact that "almost all" square roots of positive integers are irrational, even though the set of positive integers which are perfect squares and the set of positive integers which are not perfect squares are both countably infinite - the former is an infinitely sparser subset of the integers.
Each convergent :math:`C_k` represents a **rational approximation**:math:`\frac{p_k}{q_k}` of:math:`x`, and we can define an error term:math:`\epsilon_k = x - C_k = x - \frac{p_k}{q_k}`. If we assume :math:`x > 0` then the convergents form a strictly increasing sequence of rational numbers converging to :math:`x` as:math:`n \longrightarrow\infty`. So, formally:
54
+
We note that if a continued fraction :math:`[a_0; a_1,\ldots]` has a finite order:math:`n` then:math:`C_n` is just the rational number represented by:math:`[a_0; a_1,\ldots,a_n]`, and :math:`C_k = a_k + C_{k - 1}` for:math:`k > 0`.
Each convergent :math:`C_k` represents a **rational approximation** :math:`\frac{p_k}{q_k}` of the given real number :math:`x`, and we can define an error term :math:`\epsilon_k = x - C_k = x - \frac{p_k}{q_k}`. If we assume :math:`x > 0` then the convergents form a sequence of rational numbers converging to :math:`x` as :math:`k \longrightarrow\infty`. So, formally:
61
57
62
58
.. math::
63
59
64
-
\lim_{n\to\infty} \frac{p_n}{q_n} = x
60
+
\lim_{k\to\infty} C_k = \lim_{k \to\infty} \frac{p_k}{q_k} = x
65
61
66
-
This is equivalent to the limit :math:`\lim_{n\to\infty} \epsilon_n = 0`. If:math:`x` is irrational then the convergents may alternate about :math:`x`, but still converge to it. If and only if :math:`x` is rational do we have the case that the convergent sequence is finite and terminates in :math:`x`.
62
+
This is equivalent to the limit :math:`\lim_{k\to\infty} \epsilon_k = 0`: if:math:`x` is rational the error term will vanish for some :math:`k >= 0` at which point the convergent :math:`C_k = x`. But if :math:`x` is irrational there will be infinitely many convergents, and their sequence may alternate about :math:`x`, but still converge to it.
67
63
68
64
The ``ContinuedFraction`` class provides a ``.convergents`` property for objects, which returns an immutable map
69
65
(`types.MappingProxyType <https://docs.python.org/3/library/types.html#types.MappingProxyType>`_) of all :math:`k`-order convergents, indexed (keyed) by integers :math:`k=0,1,\ldots,n`, where :math:`n` is the order of the continued fraction.
@@ -91,16 +87,14 @@ Using the continued fraction representation :math:`[3; 4, 12, 4]` of :math:`\fra
Obviously, we can only handle finite continued fractions in Python, so the convergents produced by ``ContinuedFraction`` will always be finite in number, regardless of whether the real numbers they approximate are rational or irrational. We can verify some of these properties for convergents, e.g. that :math:`C_0 < C_1 < \cdots < C_n`, for ``ContinuedFraction(649, 200)`` and also ``ContinuedFraction(math.pi)``:
90
+
Obviously, we can only handle finite continued fractions in Python, so the convergents produced by ``ContinuedFraction`` will always be finite in number, regardless of whether the real numbers they approximate are rational or irrational. We can verify the convergentsfor ``ContinuedFraction(math.pi)`` approach ``math.pi``:
**Note**: As the convergents are constructed during ``ContinuedFraction`` object initialisation, the objects that represent them cannot be of type ``ContinuedFraction``, due to recursion errors. Thus, it was decided to keep them as ``fractions.Fraction`` objects.
@@ -146,6 +140,12 @@ Using the continued fraction representation of :math:`\frac{649}{200}` we can ve
146
140
& R_3 &&= [4;] = 4 = \frac{4}{1}
147
141
\end{alignat*}
148
142
143
+
Given a (possibly infinite) continued fraction :math:`[a_0; a_1, a_2,\ldots]` the remainders :math:`R_1,R_2,\ldots` satisfy the following relation:
0 commit comments