Zora-1.1.10.2: Graphing library wrapper + assorted useful functions

Portabilityportable
Stabilityexperimental
Maintainerbgwines@cs.stanford.edu
Safe HaskellSafe-Inferred

Zora.Math

Contents

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

composites :: [Integer]Source

A complete, monotonically increa?ing, infinite list of composite numbers.

prime :: Integer -> BoolSource

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

coprime :: Integer -> Integer -> BoolSource

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

euler_phi :: Integer -> IntegerSource

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

Square roots

irrational_squares :: [Integer]Source

An infinite list of integers with irrational square roots.

sqrt_convergents :: Integer -> [(Integer, Integer)]Source

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

continued_fraction_sqrt :: Integer -> [Integer]Source

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

continued_fraction_sqrt_infinite :: Integer -> [Integer]Source

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

Assorted functions

is_int :: Double -> BoolSource

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

is_power_of_int :: Integer -> Integer -> BoolSource

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

int_to_double :: Double -> IntegerSource

Converts a Double to an Integer.

num_digits :: Integer -> IntegerSource

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

tri_area :: Integer -> Integer -> Integer -> DoubleSource

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

tri_area_double :: Double -> Double -> Double -> DoubleSource

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