np-extras- NumericPrelude extras




A representation of rational numbers as lists of prime powers, allowing efficient representation, multiplication and division of large numbers, especially of the sort occurring in combinatorial computations.

The module also includes a method for generating factorials in factored form directly, and for generating all divisors of factored integers, or computing Euler's totient (phi) function and the Mbius (mu) function.



data T Source

The type of factored rationals.

Instances are provided for Eq, Ord, Additive, Ring, ZeroTestable, Real, ToRational, Integral, RealIntegral, ToInteger, and Field.

Note that currently, addition is performed on factored rationals by converting them to normal rationals, performing the addition, and factoring. This could probably be made more efficient by finding a common denominator, pulling out common factors from the numerators, and performing the addition and factoring only on the relatively prime parts.


Eq T 
Ord T 
Show T 
C T 
C T 
C T 
C T 
C T 
C T 
C T 
C T 
C T 


factorial :: Integer -> TSource

Efficiently compute n! directly as a factored rational.

eulerPhi :: T -> IntegerSource

Compute Euler's totient function (eulerPhi n is the number of integers less than and relatively prime to n). Only makes sense for (nonnegative) integers.

divisors :: T -> [T]Source

List of the divisors of n. Only makes sense for integers.

mu :: T -> IntegerSource

Mbius (mu) function of a positive integer: mu(n) = 0 if one or more repeated prime factors, 1 if n = 1, and (-1)^k if n is a product of k distinct primes.