Copyright | (c) Eric Bailey 2024-2025 |
---|---|
License | MIT |
Maintainer | eric@ericb.me |
Stability | stable |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Data.Rhythm.ContinuedFractions
Description
Simple continued fractions represented by nonempty lists of terms.
\[ \begin{align*} [b_0; b_1, b_2, b_3, \dotsc] &= b_0 + \cfrac{1}{b_1 + \cfrac{1}{b_2 + \cfrac{1}{b_3 + \dotsm}}} \\ &= b_0 + \mathop{\vcenter{\Huge\mathcal{K}}}_{n=1}^{\infty} \frac{1}{b_n} \end{align*} \]
Synopsis
- newtype ContinuedFraction = ContinuedFraction {}
- collapseFraction :: ContinuedFraction -> Rational
- continuedFractionSqrt :: Integral a => a -> ContinuedFraction
Documentation
newtype ContinuedFraction Source #
A ContinuedFraction
is a NonEmpty
, potentially infinite, list of
integer terms
.
>>>
ContinuedFraction (1 :| [2,3,4])
[1;2,3,4]
Constructors
ContinuedFraction | |
Instances
collapseFraction :: ContinuedFraction -> Rational Source #
Evaluate a finite ContinuedFraction
.
>>>
collapseFraction (ContinuedFraction (1 :| [2,3,4]))
43 % 30
continuedFractionSqrt :: Integral a => a -> ContinuedFraction Source #
Calculate the ContinuedFraction
representation of the square root of a
given number.
>>>
continuedFractionSqrt 7
[2;1,1,1,4]