np-extras-0.3.0.1: NumericPrelude extras

Safe HaskellNone
LanguageHaskell2010

MathObj.FactoredRational

Contents

Description

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 Möbius (mu) function.

Synopsis

Type

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.

Instances

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

Utilities

factorial :: Integer -> T Source

Efficiently compute n! directly as a factored rational.

eulerPhi :: T -> Integer Source

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

Möbius (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.