Zora-1.1.6: A library of assorted useful functions and data types and classes.

Zora.Math

Description

Assorted mathematical functions.

Synopsis

# Prime numbers and division

primes :: [Integer] Source

A complete, monotonically increasing, infinite list of primes. Implementation based on http://en.literateprograms.org/Sieve_of_Eratosthenes_(Haskell).

A complete, monotonically increasing, infinite list of non-prime numbers.

O(n) Returns whether the parameter is a prime number.

O(min(n, m)) Returns whether the the two parameters are coprime, that is, whether they share any divisors.

O(k n log(n)^-1), where k is the number of primes dividing n (double-counting for powers).

O(k n log(n)^-1), where k is the number of primes dividing n (double-counting for powers). n log(n)^-1 is an approximation for the number of primes below a number.

divisors :: Integer -> [Integer] Source

O(4^(k n log(n)^-1)), where k is the number of primes dividing n (double-counting for powers).

# Square roots

An infinite list of integers with irrational square roots.

A list of fractions monotonically increasingly accurately approximating the square root of the parameter, where each fraction is represented as a pair of `(numerator, denominator)` See http://en.wikipedia.org/wiki/Convergent_(continued_fraction).

O(k) The continued fraction representation of the square root of the parameter. k is the length of the continued fraction.

An infinite list of the terms of the continued fraction representation of the square root of the given parameter.

# Assorted functions

Returns whether a `Double` value is an integer. For example, `16.0 :: Double` is an integer, but not `16.1`.

O(1) Calculates whether n is the e^th power of any integer, where n is the first parameter and e is the second.

Converts a `Double` to an `Integer`.

O(log_10(n)) Calculates the number of digits in an integer.

O(1) Area of a triangle, where the parameters are the edge lengths (Heron's formula).

O(1) Area of a triangle, where the parameters are the edge lengths (Heron's formula).