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

Copyright(c) Brett Wines 2014
LicenseBSD-style
Maintainerbgwines@cs.stanford.edu
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell98

Zora.Math

Contents

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

nonprimes :: [Integer] Source

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

is_prime :: Integer -> Bool Source

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

coprime :: Integer -> Integer -> Bool Source

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

euler_phi :: Integer -> Integer Source

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

factorize :: 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

irr_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 -> Bool Source

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 -> Bool Source

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

get_num_digits :: Integer -> Integer Source

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

tri_area :: Integer -> Integer -> Integer -> Double Source

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

tri_area_double :: Double -> Double -> Double -> Double Source

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