refactor: compose division ops for ContinuedFraction
#66
Labels
documentation
Improvements or additions to documentation
enhancement
New feature or request
refactor
Refactoring changes
All division operations in
ContinuedFraction
:continuedfraction.ContinuedFraction.__truediv__
continuedfraction.ContinuedFraction.__rtruediv__
continuedfraction.ContinuedFraction.__floordiv__
continuedfraction.ContinuedFraction.__rfloordiv__
can be refactored by composing the division-free algorithms for the negation and inversion of simple continued fractions of positive rational numbers, which are described in the documentation.
A new$\frac{a}{b}$ with simple continued fraction $[a_0; a_1,\ldots, a_n]$ : the positive inversion $+\frac{b}{a}$ is given by:
__invert__
operation is required for the composition, which implements the following algorithm for the inversion of a positive rational numberand the negative inversion$-\frac{b}{a}$ is given by:
In applying this algorithm there is an assumption that the last element$a_n > 1$ , as any simple continued fraction of type $[a_0; a_1,\ldots, a_{n} = 1]$ can be reduced to the simple continued fraction $[a_0; a_1,\ldots, a_{n - 1} + 1]$ .
The text was updated successfully, but these errors were encountered: