exact-pi-0.5.0.1: Exact rational multiples of pi (and integer powers of pi)

Data.ExactPi

Contents

Description

This type is sufficient to exactly express the closure of Q ∪ {π} under multiplication and division. As a result it is useful for representing conversion factors between physical units. Approximate values are included both to close the remainder of the arithmetic operations in the Num typeclass and to encode conversion factors defined experimentally.

Synopsis

Documentation

data ExactPi Source #

Represents an exact or approximate real value. The exactly representable values are rational multiples of an integer power of pi.

Constructors

 Exact Integer Rational Exact z q = q * pi^z. Note that this means there are many representations of zero. Approximate (forall a. Floating a => a) An approximate value. This representation was chosen because it allows conversion to floating types using their native definition of pi.
Instances
 Source # Instance detailsDefined in Data.ExactPi Methods Source # Instance detailsDefined in Data.ExactPi Methods Source # Instance detailsDefined in Data.ExactPi Methods Source # Instance detailsDefined in Data.ExactPi MethodsshowList :: [ExactPi] -> ShowS # Source # The multiplicative semigroup over Rationals augmented with multiples of pi. Instance detailsDefined in Data.ExactPi Methodsstimes :: Integral b => b -> ExactPi -> ExactPi # Source # The multiplicative monoid over Rationals augmented with multiples of pi. Instance detailsDefined in Data.ExactPi Methodsmconcat :: [ExactPi] -> ExactPi #

approximateValue :: Floating a => ExactPi -> a Source #

Approximates an exact or approximate value, converting it to a Floating type. This uses the value of pi supplied by the destination type, to provide the appropriate precision.

Identifies whether an ExactPi is an exact or approximate representation of zero.

Identifies whether an ExactPi is an exact value.

Identifies whether an ExactPi is an exact representation of zero.

Identifies whether an ExactPi is an exact representation of one.

Identifies whether two ExactPi values are exactly equal.

Identifies whether an ExactPi is an exact representation of an integer.

Converts an ExactPi to an exact Integer or Nothing.

Identifies whether an ExactPi is an exact representation of a rational.

Converts an ExactPi to an exact Rational or Nothing.

Converts an ExactPi to a list of increasingly accurate rational approximations. Note that Approximate values are converted using the Real instance for Double into a singleton list. Note that exact rationals are also converted into a singleton list.

Implementation is based on Chudnovsky's algorithm.

Utils

getRationalLimit :: Fractional a => (a -> a -> Bool) -> [Rational] -> a Source #

Given an infinite converging sequence of rationals, find their limit. Takes a comparison function to determine when convergence is close enough.

>>> getRationalLimit (==) (rationalApproximations (Exact 1 1)) :: Double
3.141592653589793