| ||||||

| ||||||

| ||||||

Description | ||||||

Exact Real Arithmetic - Computable reals. Inspired by ''The most unreliable technique for computing pi.'' See also http://www.haskell.org/haskellwiki/Exact_real_arithmetic . | ||||||

Synopsis | ||||||

types | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

basic helpers | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Converts all digits to non-negative digits, that is the usual positional representation. However the conversion will fail when the remaining digits are all zero. (This cannot be improved!) | ||||||

| ||||||

Requires, that no digit is (basis-1) or (1-basis).
The leading digit might be negative and might be -basis or basis.
| ||||||

| ||||||

May prepend a digit. | ||||||

| ||||||

Compress first digit. May prepend a digit. | ||||||

| ||||||

Does not prepend a digit. | ||||||

| ||||||

Compress second digit. Sometimes this is enough to keep the digits in the admissible range. Does not prepend a digit. | ||||||

| ||||||

| ||||||

Eliminate leading zero digits. This will fail for zero. | ||||||

| ||||||

Trim until a minimum exponent is reached. Safe for zeros. | ||||||

| ||||||

| ||||||

Accept a high leading digit for the sake of a reduced exponent.
This eliminates one leading digit.
Like pumpFirst but with exponent management.
| ||||||

| ||||||

Merge leading and second digit.
This is somehow an inverse of compressMant.
| ||||||

| ||||||

| ||||||

| ||||||

Make sure that a number with absolute value less than 1 has a (small) negative exponent. Also works with zero because it chooses an heuristic exponent for stopping. | ||||||

conversions | ||||||

integer | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

rational | ||||||

| ||||||

fixed point | ||||||

| ||||||

Split into integer and fractional part. | ||||||

| ||||||

floating point | ||||||

| ||||||

| ||||||

cf. Numeric.floatToDigits | ||||||

| ||||||

Only return as much digits as are contained in Double. This will speedup further computations. | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

text | ||||||

| ||||||

Show a number with respect to basis 10^e.
| ||||||

| ||||||

| ||||||

| ||||||

basis | ||||||

| ||||||

Convert from a Works well with every exponent. | ||||||

| ||||||

Convert from a Works well with every exponent. | ||||||

| ||||||

Convert between arbitrary bases. This conversion is expensive (quadratic time). | ||||||

| ||||||

comparison | ||||||

| ||||||

The basis must be at least ***. Note: Equality cannot be asserted in finite time on infinite precise numbers. If you want to assert, that a number is below a certain threshold, you should not call this routine directly, because it will fail on equality. Better round the numbers before comparison. | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Get the mantissa in such a form that it fits an expected exponent.
| ||||||

| ||||||

| ||||||

arithmetic | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Add two numbers but do not eliminate leading zeros. | ||||||

| ||||||

| ||||||

| ||||||

Add at most basis summands.
More summands will violate the allowed digit range.
| ||||||

| ||||||

Add many numbers efficiently by computing sums of sub lists with only little carry propagation. | ||||||

| ||||||

| ||||||

Add an infinite number of numbers. You must provide a list of estimate of the current remainders. The estimates must be given as exponents of the remainder. If such an exponent is too small, the summation will be aborted. If exponents are too big, computation will become inefficient. | ||||||

| ||||||

| ||||||

Like splitAt,
but it pads with zeros if the list is too short.
This way it preserves
length (fst (splitAtPadZero n xs)) == n
| ||||||

| ||||||

| ||||||

help showing series summands | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

For obtaining n result digits it is mathematically sufficient
to know the first (n+1) digits of the operands.
However this implementation needs (n+2) digits,
because of calls to compress in both scale and series.
We should fix that.
| ||||||

| ||||||

Undefined if the divisor is zero - of course. Because it is impossible to assert that a real is zero, the routine will not throw an error in general. ToDo: Rigorously derive the minimal required magnitude of the leading divisor digit. | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Fast division for small integral divisors, which occur for instance in summands of power series. | ||||||

| ||||||

| ||||||

algebraic functions | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Square root. We need a leading digit of type Integer,
because we have to collect up to 4 digits.
This presentation can also be considered as ToDo: Rigorously derive the minimal required magnitude of the leading digit of the root. Mathematically the 2*n input digits
for emitting n digits.
This is due to the repeated use of compressMant.
It would suffice to fully compress only every basisth iteration (digit)
and compress only the second leading digit in each iteration.
Can the involved operations be made lazy enough to solve
| ||||||

| ||||||

| ||||||

Newton iteration doubles the number of correct digits in every step. Thus we process the data in chunks of sizes of powers of two. This way we get fastest computation possible with Newton but also more dependencies on input than necessary. The question arises whether this implementation still fits the needs of computational reals. The input is requested as larger and larger chunks, and the input itself might be computed this way, e.g. a repeated square root. Requesting one digit too much, requires the double amount of work for the input computation, which in turn multiplies time consumption by a factor of four, and so on. Optimal fast implementation of one routine does not preserve fast computation of composed computations. The routine assumes, that the integer parts is at least | ||||||

| ||||||

List.inits is defined by
This is too strict for our application.
The following routine is more lazy but restricted to infinite lists. | ||||||

transcendent functions | ||||||

exponential functions | ||||||

| ||||||

| ||||||

Absolute value of argument should be below 1. | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Residue estimates will only hold for exponents with absolute value below one. The computation is based on It is not optimal to split the power into pure root and pure power (that means, with integer exponents). The root series can nicely handle all exponents, but for exponents above 1 the series summands rises at the beginning and thus make the residue estimate complicated. For powers with integer exponents the root series turns into the binomial formula, which is just a complicated way to compute a power which can also be determined by simple multiplication. | ||||||

| ||||||

| ||||||

| ||||||

| ||||||

Absolute value of argument should be below 1. | ||||||

| ||||||

Absolute value of argument should be below 1. | ||||||

| ||||||

Like Note that the faster convergence is hidden by the overhead. The same could be achieved with a fourth power of a complex number. | ||||||

| ||||||

| ||||||

| ||||||

logarithmic functions | ||||||

| ||||||

| ||||||

| ||||||

x' = x - (exp x - y) / exp x = x + (y * exp (-x) - 1) First, the dependencies on low-significant places are currently
much more than mathematically necessary.
Check
Possibly the dependencies of expSmall
could be resolved by not computing Second, even if the dependencies of all atomic operations
are reduced to a minimum,
the mathematical dependencies of the whole iteration function
are less than the sums of the parts.
Lets demonstrate this with the square root iteration.
It is
213 do not depend mathematically on x of 1.414x,
but their computation depends.
Maybe there is a glorious trick to reduce the computational dependencies
to the mathematical ones.
| ||||||

| ||||||

| ||||||

| ||||||

This is an inverse of It could be certainly accelerated by not using cosSin and its fiddling with pi. Instead we could analyse quadrants before calling atan2, then calling cosSinSmall immediately. | ||||||

| ||||||

Arcus tangens of arguments with absolute value less than 1 / sqrt 3.
| ||||||

| ||||||

| ||||||

Efficient computation of Arcus tangens of an argument of the form 1/n.
| ||||||

| ||||||

This implementation gets the first decimal place for free
by calling the arcus tangens implementation for Doubles.
| ||||||

| ||||||

A classic implementation without ''cheating'' with floating point implementations. For For For other
If | ||||||

constants | ||||||

elementary | ||||||

| ||||||

| ||||||

| ||||||

transcendental | ||||||

| ||||||

| ||||||

| ||||||

auxilary functions | ||||||

| ||||||

Candidate for a Utility module. | ||||||

| ||||||

| ||||||

Produced by Haddock version 2.6.0 |