number-0.1.1.0: A library for real numbers

Safe HaskellSafe
LanguageHaskell2010

Data.Number

Contents

Description

A library for real number arithmetics

Synopsis

Classes

data Continued a Source

Continued fraction type

Represents a simple continued fraction of the form:

Supports Haskell arithmetic operators though the use of the operator function is to be preferred since provide shortcuts to calculations.

It can be an infinite sequence. Be careful with functions like show and precision: they may not terminate.

Cons operator

n :| x equivalent to n + 1/x

Negate operator

M x equivalent to -x

Constructors

M (Continued a)

Negative number

a :| (Continued a) infixr 5

Positive number

E

Zero

Instances

type Number = Continued Nat Source

Real numbers datatype (a continued fraction of naturals)

data Nat Source

Lazy Peano numbers. Allow calculation with infinite values.

Constructors

Z

Zero

S Nat

Successor

Instances

Bounded Nat Source

The lower bound is zero, the upper bound is infinity.

Enum Nat Source

The pred function is bounded at Zero.

Eq Nat Source

== and /= work as long as at least one operand is finite.

Integral Nat Source

Since negative numbers are not allowed, quot = div and rem = mod. The methods quot, rem, div, mod, quotRem and divMod will terminate as long as their first argument is finite. Infinities in their second arguments are permitted and are handled as follows:

  n quot infinity   =   n div infinity   =   0
  n rem  infinity   =   n mod infinity   =   n
Num Nat Source

Addition, multiplication, and subtraction are lazy in both arguments, meaning that, in the case of infinite values, they can produce an infinite stream of S-constructors. As long as the callers of these functions only consume a finite amount of these, the program will not hang.

fromInteger is not injective in case of Nat, since negative integers are all converted to zero (Z).

Ord Nat Source

All methods work as long as at least one operand is finite.

Real Nat Source

Since toRational returns a Ratio Integer, it WILL NOT terminate on infinities.

Show Nat Source 
Peano Nat Source

Peano class instance

data Whole Source

Whole numbers (Z).

Constructors

Whole Nat Sign

Construct a whole number out of a magnitue and a sign.

Instances

Bounded Whole Source

The bounds are negative and positive infinity.

Enum Whole Source

succ and pred work according to the total order on the whole numbers, i.e. succ n = n+1 and pred n = n-1.

Eq Whole Source

Positive and negative zero are considered equal.

Integral Whole Source

Integer conversions and division

Num Whole Source

Implements arithmetics for Whole numbers

Ord Whole Source

The ordering is the standard total order on Z. Positive and negative zero are equal.

Real Whole Source

Since toRational returns a Ratio Integer, it WILL NOT terminate on infinities.

Peano Whole Source

Peano class instance defines infinity (positive) and other functions handling the sign

Functions

fromList :: [Nat] -> Number Source

Create a Number from a list of naturals

toList :: Number -> [Nat] Source

Convert a Number to a list of naturals (losing the sign)

fromNumber :: RealFrac a => Number -> a Source

Convert a Number into a RealFrac number

toNumber :: RealFrac a => a -> Number Source

Convert a RealFrac number into a Number

Constants

σ :: Number Source

The infinite continued fraction whose terms are naturals numbers

φ :: Number Source

The golden ratio

π :: Number Source

Pi: the ratio of a circle's circumference to its diameter

e :: Number Source

Euler's number: the base of the natural logarithm

Internals

hom :: Hom -> Number -> Number Source

Homographic function

Given the Hom matrix

and a Number x calculates

See http://perl.plover.com/yak/cftalk/INFO/gosper.txt for a complete explanation.

biHom :: BiHom -> Number -> Number -> Number Source

Bihomographic function

Given a BiHom matrix

and two Number x and y calculates

cut :: Nat -> Number -> Number Source

Truncate a Number to a given length n