Zora-1.1.11: Graphing library wrapper + assorted useful functions

Portability portable experimental bgwines@cs.stanford.edu Safe-Inferred

Zora.Math

Description

Assorted mathematical functions.

Synopsis

# Prime numbers and division

primes :: [Integer]Source

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

A complete, monotonically increasing, infinite list of composite 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).

factor :: Integer -> [Integer]Source

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

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. Essentially, linear in the time it takes to factor the number.

# 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.

Determines whether the given integer is a square number.

# Assorted functions

fibs :: [Integer]Source

An infinite list of the Fibonacci numbers.

Takes the square root of a perfect square.

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. Relies on `logBase`, so gives wrong answer for very large `n`.

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