Copyright | © 2014 Johan Kiviniemi |
---|---|
License | MIT |
Maintainer | Johan Kiviniemi <devel@johan.kiviniemi.name> |
Stability | provisional |
Portability | ViewPatterns |
Safe Haskell | None |
Language | Haskell2010 |
An implementation of quadratic irrationals with support for conversion from and to periodic continued fractions.
- data QI
- qi :: Integer -> Integer -> Integer -> Integer -> QI
- qi' :: Rational -> Rational -> Integer -> QI
- qiModify :: QI -> (Integer -> Integer -> Integer -> (Integer, Integer, Integer)) -> QI
- runQI :: QI -> (Integer -> Integer -> Integer -> Integer -> a) -> a
- runQI' :: QI -> (Rational -> Rational -> Integer -> a) -> a
- unQI :: QI -> (Integer, Integer, Integer, Integer)
- unQI' :: QI -> (Rational, Rational, Integer)
- qiZero :: QI
- qiOne :: QI
- qiIsZero :: QI -> Bool
- qiToFloat :: Floating a => QI -> a
- qiAddI :: QI -> Integer -> QI
- qiSubI :: QI -> Integer -> QI
- qiMulI :: QI -> Integer -> QI
- qiDivI :: QI -> Integer -> QI
- qiAddR :: QI -> Rational -> QI
- qiSubR :: QI -> Rational -> QI
- qiMulR :: QI -> Rational -> QI
- qiDivR :: QI -> Rational -> QI
- qiNegate :: QI -> QI
- qiRecip :: QI -> Maybe QI
- qiAdd :: QI -> QI -> Maybe QI
- qiSub :: QI -> QI -> Maybe QI
- qiMul :: QI -> QI -> Maybe QI
- qiDiv :: QI -> QI -> Maybe QI
- qiPow :: QI -> Integer -> QI
- qiFloor :: QI -> Integer
- continuedFractionToQI :: (Integer, CycList Integer) -> QI
- qiToContinuedFraction :: QI -> (Integer, CycList Integer)
- module Numeric.QuadraticIrrational.CyclicList
Documentation
Given a
, b
, c
and d
such that n = (a + b √c)/d
, constuct a QI
corresponding to n
.
Given a
, b
and c
such that n = a + b √c
, constuct a QI
corresponding to n
.
qiModify :: QI -> (Integer -> Integer -> Integer -> (Integer, Integer, Integer)) -> QI Source
Given a QI
corresponding to n = (a + b √c)/d
, modify (a, b, d)
.
Avoids having to simplify b √c
.
runQI :: QI -> (Integer -> Integer -> Integer -> Integer -> a) -> a Source
Given n
and f
such that n = (a + b √c)/d
, run f a b c d
.
runQI' :: QI -> (Rational -> Rational -> Integer -> a) -> a Source
Given n
and f
such that n = a + b √c
, run f a b c
.
unQI :: QI -> (Integer, Integer, Integer, Integer) Source
Given n
such that n = (a + b √c)/d
, return (a, b, c, d)
.
unQI' :: QI -> (Rational, Rational, Integer) Source
Given n
such that n = a + b √c
, return (a, b, c)
.
qiSub :: QI -> QI -> Maybe QI Source
Subtract two QI
s if the square root terms are the same or zeros.
qiMul :: QI -> QI -> Maybe QI Source
Multiply two QI
s if the square root terms are the same or zeros.
continuedFractionToQI :: (Integer, CycList Integer) -> QI Source
Convert a (possibly periodic) continued fraction to a QI
.