| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Euler.Util.ContinuedFractions
Synopsis
- type ContinuedFraction a = (a, [a])
- continuedFractionConvergent :: Integral a => ContinuedFraction a -> Ratio a
- sqrtContinuedFraction :: Integral a => a -> Maybe (ContinuedFraction a)
- sqrtConvergents :: Integral a => a -> Maybe [Ratio a]
Documentation
type ContinuedFraction a = (a, [a]) Source #
continuedFractionConvergent Source #
Arguments
| :: Integral a | |
| => ContinuedFraction a | Must be finite |
| -> Ratio a | The approximation represented by the continued fraction |
>>>fmap (take 6) <$> sqrtContinuedFraction 2Just (1,[2,2,2,2,2,2])
>>>fmap (take 14) <$> sqrtContinuedFraction 114Just (10,[1,2,10,2,1,20,1,2,10,2,1,20,1,2])
>>>sqrtContinuedFraction 16Nothing
sqrtContinuedFraction Source #
Arguments
| :: Integral a | |
| => a | n |
| -> Maybe (ContinuedFraction a) | Continued fraction expansion of sqrt(n) in canonical form. |
Arguments
| :: Integral a | |
| => a | n |
| -> Maybe [Ratio a] | The convergents of the continued fractions representation of sqrt(n). |
>>>:{showRatio :: (Integral a, Show a) => Ratio a -> String showRatio x = intercalate "/" $ show . ($ x) <$> [ numerator, denominator ] :}
>>>(intercalate ", ") . (fmap showRatio) . (take 5) <$> sqrtConvergents 2Just "1/1, 3/2, 7/5, 17/12, 41/29"
>>>(intercalate ", ") . (fmap showRatio) . (take 5) <$> sqrtConvergents 3Just "1/1, 2/1, 5/3, 7/4, 19/11"
>>>sqrtConvergents 16Nothing