Copyright | (c) Brett Wines 2014 |
---|---|
License | BSD-style |
Maintainer | bgwines@cs.stanford.edu |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
Assorted mathematical functions.
- primes :: [Integer]
- nonprimes :: [Integer]
- is_prime :: Integer -> Bool
- coprime :: Integer -> Integer -> Bool
- euler_phi :: Integer -> Integer
- factorize :: Integer -> [Integer]
- divisors :: Integer -> [Integer]
- irr_squares :: [Integer]
- sqrt_convergents :: Integer -> [(Integer, Integer)]
- continued_fraction_sqrt :: Integer -> [Integer]
- continued_fraction_sqrt_infinite :: Integer -> [Integer]
- is_int :: Double -> Bool
- is_power_of_int :: Integer -> Integer -> Bool
- int_to_double :: Double -> Integer
- get_num_digits :: Integer -> Integer
- tri_area :: Integer -> Integer -> Integer -> Double
- tri_area_double :: Double -> Double -> Double -> Double
Prime numbers and division
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.
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.