quadratic-irrational-0.0.1: An implementation of quadratic irrationals

PortabilityViewPatterns
Stabilityprovisional
MaintainerJohan Kiviniemi <devel@johan.kiviniemi.name>
Safe HaskellNone

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

qiSource

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

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

Given n and f such that n = (a + b √c)/d, run f a b c d.

runQI' :: QI -> (Rational -> Rational -> Integer -> a) -> aSource

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 :: QISource

The constant zero. qi 0 0 0 1

qiOne :: QISource

The constant one. qi 1 0 0 1

qiIsZero :: QI -> BoolSource

Check if the value is zero.

qiToFloat :: Floating a => QI -> aSource

Convert a QI number into a Floating one.

qiAddI :: QI -> Integer -> QISource

Add an Integer to a QI.

qiSubI :: QI -> Integer -> QISource

Subtract an Integer from a QI.

qiMulI :: QI -> Integer -> QISource

Multiply a QI by an Integer.

qiDivI :: QI -> Integer -> QISource

Divice a QI by an Integer.

qiAddR :: QI -> Rational -> QISource

Add a Rational to a QI.

qiSubR :: QI -> Rational -> QISource

Subtract a Rational from a QI.

qiMulR :: QI -> Rational -> QISource

Multiply a QI by a Rational.

qiDivR :: QI -> Rational -> QISource

Divice a QI by a Rational.

qiNegate :: QI -> QISource

Negate a QI.

qiRecip :: QI -> Maybe QISource

Compute the reciprocal of a QI.

qiAdd :: QI -> QI -> Maybe QISource

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

qiSub :: QI -> QI -> Maybe QISource

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

qiMul :: QI -> QI -> Maybe QISource

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

qiDiv :: QI -> QI -> Maybe QISource

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

qiPow :: QI -> Integer -> QISource

Exponentiate a QI to an Integer power.

qiFloor :: QI -> IntegerSource

Compute the floor of a QI.

continuedFractionToQI :: (Integer, CycList Integer) -> QISource

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

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

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