quadratic-irrational-0.0.1: An implementation of quadratic irrationals

Copyright© 2014 Johan Kiviniemi
LicenseMIT
MaintainerJohan Kiviniemi <devel@johan.kiviniemi.name>
Stabilityprovisional
PortabilityViewPatterns
Safe HaskellNone
LanguageHaskell2010

Numeric.QuadraticIrrational

Description

An implementation of quadratic irrationals with support for conversion from and to periodic continued fractions.

Synopsis

Documentation

data QI Source

(a + b √c) / d

Instances

qi Source

Arguments

:: Integer

a

-> Integer

b

-> Integer

c

-> Integer

d

-> QI 

Given a, b, c and d such that n = (a + b √c)/d, constuct a QI corresponding to n.

qi' Source

Arguments

:: Rational

a

-> Rational

b

-> Integer

c

-> QI 

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).

qiZero :: QI Source

The constant zero. qi 0 0 0 1

qiOne :: QI Source

The constant one. qi 1 0 0 1

qiIsZero :: QI -> Bool Source

Check if the value is zero.

qiToFloat :: Floating a => QI -> a Source

Convert a QI number into a Floating one.

qiAddI :: QI -> Integer -> QI Source

Add an Integer to a QI.

qiSubI :: QI -> Integer -> QI Source

Subtract an Integer from a QI.

qiMulI :: QI -> Integer -> QI Source

Multiply a QI by an Integer.

qiDivI :: QI -> Integer -> QI Source

Divice a QI by an Integer.

qiAddR :: QI -> Rational -> QI Source

Add a Rational to a QI.

qiSubR :: QI -> Rational -> QI Source

Subtract a Rational from a QI.

qiMulR :: QI -> Rational -> QI Source

Multiply a QI by a Rational.

qiDivR :: QI -> Rational -> QI Source

Divice a QI by a Rational.

qiNegate :: QI -> QI Source

Negate a QI.

qiRecip :: QI -> Maybe QI Source

Compute the reciprocal of a QI.

qiAdd :: QI -> QI -> Maybe QI Source

Add two QIs if the square root terms are the same or zeros.

qiSub :: QI -> QI -> Maybe QI Source

Subtract two QIs if the square root terms are the same or zeros.

qiMul :: QI -> QI -> Maybe QI Source

Multiply two QIs if the square root terms are the same or zeros.

qiDiv :: QI -> QI -> Maybe QI Source

Divide two QIs if the square root terms are the same or zeros.

qiPow :: QI -> Integer -> QI Source

Exponentiate a QI to an Integer power.

qiFloor :: QI -> Integer Source

Compute the floor of a QI.

continuedFractionToQI :: (Integer, CycList Integer) -> QI Source

Convert a (possibly periodic) continued fraction to a QI.

qiToContinuedFraction :: QI -> (Integer, CycList Integer) Source

Convert a QI into a (possibly periodic) continued fraction.