-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Efficient basic number-theoretic functions.
--   
--   A library of basic functionality needed for number-theoretic
--   calculations. The aim of this library is to provide efficient
--   implementations of the functions. Primes and related things (totients,
--   factorisation), powers (integer roots and tests, modular
--   exponentiation).
@package arithmoi
@version 0.13.2.0


-- | Container for pairwise coprime numbers.
module Math.NumberTheory.Euclidean.Coprimes

-- | The input list is assumed to be a factorisation of some number into a
--   list of powers of (possibly, composite) non-zero factors. The output
--   list is a factorisation of the same number such that all factors are
--   coprime. Such transformation is crucial to continue factorisation
--   (lazily, in parallel or concurrent fashion) without having to merge
--   multiplicities of primes, which occurs more than in one composite
--   factor.
--   
--   <pre>
--   &gt;&gt;&gt; splitIntoCoprimes [(140, 1), (165, 1)]
--   Coprimes {unCoprimes = [(28,1),(33,1),(5,2)]}
--   
--   &gt;&gt;&gt; splitIntoCoprimes [(360, 1), (210, 1)]
--   Coprimes {unCoprimes = [(7,1),(5,2),(3,3),(2,4)]}
--   </pre>
splitIntoCoprimes :: (Eq a, GcdDomain a, Eq b, Num b) => [(a, b)] -> Coprimes a b

-- | A list of pairwise coprime numbers with their multiplicities.
data Coprimes a b

-- | Unwrap.
unCoprimes :: Coprimes a b -> [(a, b)]

-- | Wrap a non-zero number with its multiplicity into <a>Coprimes</a>.
--   
--   <pre>
--   &gt;&gt;&gt; singleton 210 1
--   Coprimes {unCoprimes = [(210,1)]}
--   </pre>
singleton :: (Eq a, GcdDomain a, Eq b, Num b) => a -> b -> Coprimes a b

-- | Add a non-zero number with its multiplicity to <a>Coprimes</a>.
--   
--   <pre>
--   &gt;&gt;&gt; insert 360 1 (singleton 210 1)
--   Coprimes {unCoprimes = [(7,1),(5,2),(3,3),(2,4)]}
--   
--   &gt;&gt;&gt; insert 2 4 (insert 7 1 (insert 5 2 (singleton 4 3)))
--   Coprimes {unCoprimes = [(7,1),(5,2),(2,10)]}
--   </pre>
insert :: (Eq a, GcdDomain a, Eq b, Num b) => a -> b -> Coprimes a b -> Coprimes a b
instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (Math.NumberTheory.Euclidean.Coprimes.Coprimes a b)
instance (GHC.Classes.Eq a, Data.Euclidean.GcdDomain a, GHC.Classes.Eq b, GHC.Internal.Num.Num b) => GHC.Internal.Base.Monoid (Math.NumberTheory.Euclidean.Coprimes.Coprimes a b)
instance (GHC.Classes.Eq a, Data.Euclidean.GcdDomain a, GHC.Classes.Eq b, GHC.Internal.Num.Num b) => GHC.Internal.Base.Semigroup (Math.NumberTheory.Euclidean.Coprimes.Coprimes a b)
instance (GHC.Internal.Show.Show a, GHC.Internal.Show.Show b) => GHC.Internal.Show.Show (Math.NumberTheory.Euclidean.Coprimes.Coprimes a b)


-- | Chinese remainder theorem
module Math.NumberTheory.Moduli.Chinese

-- | <a>chinese</a> <tt>(n1, m1)</tt> <tt>(n2, m2)</tt> returns <tt>(n, lcm
--   m1 m2)</tt> such that <tt>n `mod` m1 == n1</tt> and <tt>n `mod` m2 ==
--   n2</tt>, if exists. Moduli <tt>m1</tt> and <tt>m2</tt> are allowed to
--   have common factors.
--   
--   <pre>
--   &gt;&gt;&gt; chinese (1, 2) (2, 3)
--   Just (-1, 6)
--   
--   &gt;&gt;&gt; chinese (3, 4) (5, 6)
--   Just (-1, 12)
--   
--   &gt;&gt;&gt; chinese (3, 4) (2, 6)
--   Nothing
--   </pre>
chinese :: (Eq a, Ring a, Euclidean a) => (a, a) -> (a, a) -> Maybe (a, a)

-- | Same as <a>chinese</a>, but operates on residues.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; import Data.Mod
--   
--   &gt;&gt;&gt; (1 `modulo` 2) `chineseSomeMod` (2 `modulo` 3)
--   Just (5 `modulo` 6)
--   
--   &gt;&gt;&gt; (3 `modulo` 4) `chineseSomeMod` (5 `modulo` 6)
--   Just (11 `modulo` 12)
--   
--   &gt;&gt;&gt; (3 `modulo` 4) `chineseSomeMod` (2 `modulo` 6)
--   Nothing
--   </pre>
chineseSomeMod :: SomeMod -> SomeMod -> Maybe SomeMod


-- | A <a>smooth number</a> is an number, which can be represented as a
--   product of powers of elements from a given set (smooth basis). E. g.,
--   48 = 3 * 4 * 4 is smooth over a set {3, 4}, and 24 is not.
module Math.NumberTheory.SmoothNumbers

-- | An abstract representation of a smooth basis.
data SmoothBasis a

-- | Unwrap elements of a smooth basis.
unSmoothBasis :: SmoothBasis a -> [a]

-- | Build a <a>SmoothBasis</a> from a list of numbers, sanitizing it from
--   duplicates, zeros and units.
--   
--   <pre>
--   &gt;&gt;&gt; fromList [2, 3]
--   SmoothBasis {unSmoothBasis = [2,3]}
--   
--   &gt;&gt;&gt; fromList [2, 2]
--   SmoothBasis {unSmoothBasis = [2]}
--   
--   &gt;&gt;&gt; fromList [1, 3]
--   SmoothBasis {unSmoothBasis = [3]}
--   </pre>
fromList :: (Eq a, GcdDomain a) => [a] -> SmoothBasis a

-- | Check that a given number is smooth under a given <a>SmoothBasis</a>.
--   
--   <pre>
--   &gt;&gt;&gt; isSmooth (fromList [2,3]) 12
--   True
--   
--   &gt;&gt;&gt; isSmooth (fromList [2,3]) 15
--   False
--   </pre>
isSmooth :: (Eq a, GcdDomain a) => SmoothBasis a -> a -> Bool

-- | Generate an infinite ascending list of <a>smooth numbers</a> over a
--   given smooth basis.
--   
--   This routine is more efficient than filtering with <a>isSmooth</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 (smoothOver (fromList [2, 5]))
--   [1,2,4,5,8,10,16,20,25,32]
--   </pre>
smoothOver :: Integral a => SmoothBasis a -> [a]

-- | A generalization of <a>smoothOver</a>, suitable for
--   non-<a>Integral</a> domains. The first argument must be an appropriate
--   <a>Ideal norm</a> function, like <a>norm</a> or <a>norm</a>.
--   
--   This routine is more efficient than filtering with <a>isSmooth</a>.
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.Quadratic.GaussianIntegers
--   
--   &gt;&gt;&gt; take 10 (smoothOver' norm (fromList [1+ι,3]))
--   [1,1+ι,2,2+2*ι,3,4,3+3*ι,4+4*ι,6,8]
--   </pre>
smoothOver' :: (Eq a, Num a, Ord b) => (a -> b) -> SmoothBasis a -> [a]
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.SmoothNumbers.SmoothBasis a)


-- | A newtype wrapper around <a>IntSet</a>.
--   
--   This module is intended to be imported qualified, e. g.,
--   
--   <pre>
--   import Math.NumberTheory.Primes.IntSet (PrimeIntSet)
--   import qualified Math.NumberTheory.Primes.IntSet as PrimeIntSet
--   </pre>
module Math.NumberTheory.Primes.IntSet

-- | A set of <a>Prime</a> integers.
data PrimeIntSet

-- | Convert to a set of integers.
unPrimeIntSet :: PrimeIntSet -> IntSet

-- | Build a singleton set.
singleton :: Prime Int -> PrimeIntSet

-- | Build a set from a list of primes.
fromList :: [Prime Int] -> PrimeIntSet

-- | Build a set from an ascending list of primes (the precondition is not
--   checked).
fromAscList :: [Prime Int] -> PrimeIntSet

-- | Build a set from an ascending list of distinct primes (the
--   precondition is not checked).
fromDistinctAscList :: [Prime Int] -> PrimeIntSet

-- | Insert a prime into the set.
insert :: Prime Int -> PrimeIntSet -> PrimeIntSet

-- | Delete an integer from the set.
delete :: Int -> PrimeIntSet -> PrimeIntSet

-- | Check whether the given prime is a member of the set.
member :: Prime Int -> PrimeIntSet -> Bool

-- | Check whether the given prime is not a member of the set.
notMember :: Prime Int -> PrimeIntSet -> Bool

-- | Find a prime in the set, equal to the given integer, if any exists.
lookupEQ :: Int -> PrimeIntSet -> Maybe (Prime Int)

-- | Find the largest prime in the set, smaller than the given integer, if
--   any exists.
lookupLT :: Int -> PrimeIntSet -> Maybe (Prime Int)

-- | Find the smallest prime in the set, greater than the given integer, if
--   any exists.
lookupGT :: Int -> PrimeIntSet -> Maybe (Prime Int)

-- | Find the largest prime in the set, smaller or equal to the given
--   integer, if any exists.
lookupLE :: Int -> PrimeIntSet -> Maybe (Prime Int)

-- | Find the smallest prime in the set, greater or equal to the given
--   integer, if any exists.
lookupGE :: Int -> PrimeIntSet -> Maybe (Prime Int)

-- | Check whether the set is empty.
null :: PrimeIntSet -> Bool

-- | Cardinality of the set.
size :: PrimeIntSet -> Int

-- | Check whether the first argument is a subset of the second one.
isSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool

-- | Check whether the first argument is a proper subset of the second one.
isProperSubsetOf :: PrimeIntSet -> PrimeIntSet -> Bool

-- | Check whether two sets are disjoint.
disjoint :: PrimeIntSet -> PrimeIntSet -> Bool

-- | Difference between a set of primes and a set of integers.
difference :: PrimeIntSet -> IntSet -> PrimeIntSet

-- | An alias to <a>difference</a>.
(\\) :: PrimeIntSet -> IntSet -> PrimeIntSet
infixl 9 \\

-- | Symmetric difference of two sets of primes.
symmetricDifference :: PrimeIntSet -> PrimeIntSet -> PrimeIntSet

-- | Intersection of a set of primes and a set of integers.
intersection :: PrimeIntSet -> IntSet -> PrimeIntSet

-- | Filter primes satisfying a predicate.
filter :: (Prime Int -> Bool) -> PrimeIntSet -> PrimeIntSet

-- | Partition primes according to a predicate.
partition :: (Prime Int -> Bool) -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet)

-- | Split into primes strictly less and strictly greater than the first
--   argument.
split :: Int -> PrimeIntSet -> (PrimeIntSet, PrimeIntSet)

-- | Simultaneous <a>split</a> and <a>member</a>.
splitMember :: Prime Int -> PrimeIntSet -> (PrimeIntSet, Bool, PrimeIntSet)

-- | Simultaneous <a>split</a> and <a>lookupEQ</a>.
splitLookupEQ :: Int -> PrimeIntSet -> (PrimeIntSet, Maybe (Prime Int), PrimeIntSet)

-- | Decompose a set into pieces based on the structure of the underlying
--   tree.
splitRoot :: PrimeIntSet -> [PrimeIntSet]

-- | Fold a set using the given right-associative operator.
foldr :: (Prime Int -> b -> b) -> b -> PrimeIntSet -> b

-- | Fold a set using the given left-associative operator.
foldl :: (a -> Prime Int -> a) -> a -> PrimeIntSet -> a

-- | A strict version of <a>foldr</a>.
foldr' :: (Prime Int -> b -> b) -> b -> PrimeIntSet -> b

-- | A strict version of <a>foldl</a>.
foldl' :: (a -> Prime Int -> a) -> a -> PrimeIntSet -> a

-- | Delete the smallest prime in the set.
deleteMin :: PrimeIntSet -> PrimeIntSet

-- | Delete the largest prime in the set.
deleteMax :: PrimeIntSet -> PrimeIntSet

-- | Split a set into the smallest prime and the rest, if non-empty.
minView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet)

-- | Split a set into the largest prime and the rest, if non-empty.
maxView :: PrimeIntSet -> Maybe (Prime Int, PrimeIntSet)

-- | Convert the set to a list of ascending primes.
toAscList :: PrimeIntSet -> [Prime Int]

-- | Convert the set to a list of descending primes.
toDescList :: PrimeIntSet -> [Prime Int]
instance GHC.Internal.Data.Data.Data Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance GHC.Classes.Eq Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance GHC.Internal.IsList.IsList Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance GHC.Internal.Base.Monoid Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance Control.DeepSeq.NFData Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance GHC.Classes.Ord Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance GHC.Internal.Base.Semigroup Math.NumberTheory.Primes.IntSet.PrimeIntSet
instance GHC.Internal.Show.Show Math.NumberTheory.Primes.IntSet.PrimeIntSet


-- | Number of primes not exceeding <tt>n</tt>, <tt>π(n)</tt>, and
--   <tt>n</tt>-th prime; also fast, but reasonably accurate approximations
--   to these.
module Math.NumberTheory.Primes.Counting

-- | <tt><a>primeCount</a> n == π(n)</tt> is the number of (positive)
--   primes not exceeding <tt>n</tt>.
--   
--   For efficiency, the calculations are done on 64-bit signed integers,
--   therefore <tt>n</tt> must not exceed <a>primeCountMaxArg</a>.
--   
--   Requires <tt><i>O</i>(n^0.5)</tt> space, the time complexity is
--   roughly <tt><i>O</i>(n^0.7)</tt>. For small bounds,
--   <tt><a>primeCount</a> n</tt> simply counts the primes not exceeding
--   <tt>n</tt>, for bounds from <tt>30000</tt> on, Meissel's algorithm is
--   used in the improved form due to D.H. Lehmer, cf.
--   <a>http://en.wikipedia.org/wiki/Prime_counting_function#Algorithms_for_evaluating_.CF.80.28x.29</a>.
primeCount :: Integer -> Integer

-- | Maximal allowed argument of <a>primeCount</a>. Currently 8e18.
primeCountMaxArg :: Integer

-- | <tt><a>nthPrime</a> n</tt> calculates the <tt>n</tt>-th prime.
--   Numbering of primes is <tt>1</tt>-based, so <tt><a>nthPrime</a> 1 ==
--   2</tt>.
--   
--   Requires <tt><i>O</i>((n*log n)^0.5)</tt> space, the time complexity
--   is roughly <tt><i>O</i>((n*log n)^0.7</tt>. The argument must be
--   strictly positive.
nthPrime :: Int -> Prime Integer

-- | <tt><a>approxPrimeCount</a> n</tt> gives an approximation of the
--   number of primes not exceeding <tt>n</tt>. The approximation is fairly
--   good for <tt>n</tt> large enough.
approxPrimeCount :: Integral a => a -> a

-- | Following property holds:
--   
--   <pre>
--   approxPrimeCount n &gt;= primeCount n || n &gt;= approxPrimeCountOverestimateLimit
--   </pre>
approxPrimeCountOverestimateLimit :: Integral a => a

-- | <tt><a>nthPrimeApprox</a> n</tt> gives an approximation to the n-th
--   prime. The approximation is fairly good for <tt>n</tt> large enough.
nthPrimeApprox :: Integer -> Integer

-- | Following property holds:
--   
--   <pre>
--   nthPrimeApprox n &lt;= nthPrime n || n &gt;= nthPrimeApproxUnderestimateLimit
--   </pre>
nthPrimeApproxUnderestimateLimit :: Integer


module Math.NumberTheory.Primes

-- | Wrapper for prime elements of <tt>a</tt>. It is supposed to be
--   constructed by <a>nextPrime</a> / <a>precPrime</a>. and eliminated by
--   <a>unPrime</a>.
--   
--   One can leverage <a>Enum</a> instance to generate lists of primes.
--   Here are some examples.
--   
--   <ul>
--   <li>Generate primes from the given interval:</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XFlexibleContexts
--   
--   &gt;&gt;&gt; [nextPrime 101 .. precPrime 130]
--   [Prime 101,Prime 103,Prime 107,Prime 109,Prime 113,Prime 127]
--   </pre>
--   
--   <ul>
--   <li>Generate an infinite list of primes:</li>
--   </ul>
--   
--   <pre>
--   [nextPrime 101 ..]
--   [Prime 101,Prime 103,Prime 107,Prime 109,Prime 113,Prime 127...
--   </pre>
--   
--   <ul>
--   <li>Generate primes from the given interval of form p = 6k+5:</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; [nextPrime 101, nextPrime 107 .. precPrime 150]
--   [Prime 101,Prime 107,Prime 113,Prime 131,Prime 137,Prime 149]
--   </pre>
--   
--   <ul>
--   <li>Get next prime:</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; succ (nextPrime 101)
--   Prime 103
--   </pre>
--   
--   <ul>
--   <li>Get previous prime:</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; pred (nextPrime 101)
--   Prime 97
--   </pre>
--   
--   <ul>
--   <li>Count primes less than a given number (cf.
--   <a>approxPrimeCount</a>):</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; fromEnum (precPrime 100)
--   25
--   </pre>
--   
--   <ul>
--   <li>Get 25-th prime number (cf. <a>nthPrimeApprox</a>):</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; toEnum 25 :: Prime Int
--   Prime 97
--   </pre>
data Prime a

-- | Unwrap prime element.
unPrime :: Prime a -> a

-- | Convert between primes of different types, similar in spirit to
--   <a>toIntegralSized</a>.
--   
--   A simpler version of this function is:
--   
--   <pre>
--   toPrimeIntegral :: (Integral a, Integral b) =&gt; a -&gt; Maybe b
--   toPrimeIntegral (Prime a)
--     | toInteger a == b = Just (Prime (fromInteger b))
--     | otherwise        = Nothing
--     where
--       b = toInteger a
--   </pre>
--   
--   The point of <a>toPrimeIntegral</a> is to avoid redundant conversions
--   and conditions, when it is safe to do so, determining type sizes
--   statically with <a>bitSizeMaybe</a>. For example,
--   <a>toPrimeIntegral</a> from <a>Prime</a> <a>Int</a> to <a>Prime</a>
--   <a>Word</a> boils down to <a>Just</a> . <a>fromIntegral</a>.
toPrimeIntegral :: (Integral a, Integral b, Bits a, Bits b) => Prime a -> Maybe (Prime b)

-- | Smallest prime, greater or equal to argument.
--   
--   <pre>
--   nextPrime (-100) ==    2
--   nextPrime  1000  == 1009
--   nextPrime  1009  == 1009
--   </pre>
nextPrime :: (Bits a, Integral a, UniqueFactorisation a) => a -> Prime a

-- | Largest prime, less or equal to argument. Undefined, when argument
--   &lt; 2.
--   
--   <pre>
--   precPrime 100 == 97
--   precPrime  97 == 97
--   </pre>
precPrime :: (Bits a, Integral a, UniqueFactorisation a) => a -> Prime a

-- | A class for unique factorisation domains.
class Num a => UniqueFactorisation a

-- | Factorise a number into a product of prime powers. Factorisation of 0
--   is an undefined behaviour. Otherwise following invariants hold:
--   
--   <pre>
--   abs n == abs (product (map (\(p, k) -&gt; unPrime p ^ k) (factorise n)))
--   all ((&gt; 0) . snd) (factorise n)
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; factorise (1 :: Integer)
--   []
--   
--   &gt;&gt;&gt; factorise (-1 :: Integer)
--   []
--   
--   &gt;&gt;&gt; factorise (6 :: Integer)
--   [(Prime 2,1),(Prime 3,1)]
--   
--   &gt;&gt;&gt; factorise (-108 :: Integer)
--   [(Prime 2,2),(Prime 3,3)]
--   </pre>
--   
--   This function is a replacement for <a>factorise</a>. If you were
--   looking for the latter, please import
--   <a>Math.NumberTheory.Primes.Factorisation</a> instead of this module.
--   
--   <b>Warning:</b> there are no guarantees of any particular order of
--   prime factors, do not expect them to be ascending. E. g.,
--   
--   <pre>
--   &gt;&gt;&gt; factorise 10251562501
--   [(Prime 101701,1),(Prime 100801,1)]
--   </pre>
factorise :: UniqueFactorisation a => a -> [(Prime a, Word)]

-- | Check whether an argument is prime. If it is then return an associated
--   prime.
--   
--   <pre>
--   &gt;&gt;&gt; isPrime (3 :: Integer)
--   Just (Prime 3)
--   
--   &gt;&gt;&gt; isPrime (4 :: Integer)
--   Nothing
--   
--   &gt;&gt;&gt; isPrime (-5 :: Integer)
--   Just (Prime 5)
--   </pre>
--   
--   This function is a replacement for <a>isPrime</a>. If you were looking
--   for the latter, please import <a>Math.NumberTheory.Primes.Testing</a>
--   instead of this module.
isPrime :: UniqueFactorisation a => a -> Maybe (Prime a)

-- | Restore a number from its factorisation.
factorBack :: Num a => [(Prime a, Word)] -> a

-- | Ascending list of primes.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 primes
--   [Prime 2,Prime 3,Prime 5,Prime 7,Prime 11,Prime 13,Prime 17,Prime 19,Prime 23,Prime 29]
--   </pre>
--   
--   <a>primes</a> is a polymorphic list, so the results of computations
--   are not retained in memory. Make it monomorphic to take advantages of
--   memoization. Compare
--   
--   <pre>
--   &gt;&gt;&gt; primes !! 1000000 :: Prime Int -- (5.32 secs, 6,945,267,496 bytes)
--   Prime 15485867
--   
--   &gt;&gt;&gt; primes !! 1000000 :: Prime Int -- (5.19 secs, 6,945,267,496 bytes)
--   Prime 15485867
--   </pre>
--   
--   against
--   
--   <pre>
--   &gt;&gt;&gt; let primes' = primes :: [Prime Int]
--   
--   &gt;&gt;&gt; primes' !! 1000000 :: Prime Int -- (5.29 secs, 6,945,269,856 bytes)
--   Prime 15485867
--   
--   &gt;&gt;&gt; primes' !! 1000000 :: Prime Int -- (0.02 secs, 336,232 bytes)
--   Prime 15485867
--   </pre>
primes :: Integral a => [Prime a]
instance GHC.Internal.Enum.Bounded (Math.NumberTheory.Primes.Types.Prime GHC.Types.Int)
instance GHC.Internal.Enum.Bounded (Math.NumberTheory.Primes.Types.Prime GHC.Types.Word)
instance GHC.Internal.Enum.Enum (Math.NumberTheory.Primes.Types.Prime GHC.Num.Integer.Integer)
instance GHC.Internal.Enum.Enum (Math.NumberTheory.Primes.Types.Prime GHC.Num.Natural.Natural)
instance GHC.Internal.Enum.Enum (Math.NumberTheory.Primes.Types.Prime GHC.Types.Int)
instance GHC.Internal.Enum.Enum (Math.NumberTheory.Primes.Types.Prime GHC.Types.Word)
instance Math.NumberTheory.Primes.UniqueFactorisation GHC.Types.Int
instance Math.NumberTheory.Primes.UniqueFactorisation GHC.Num.Integer.Integer
instance Math.NumberTheory.Primes.UniqueFactorisation GHC.Num.Natural.Natural
instance Math.NumberTheory.Primes.UniqueFactorisation GHC.Types.Word


-- | Efficient calculation of linear recurrent sequences, including
--   Fibonacci and Lucas sequences.
module Math.NumberTheory.Recurrences.Linear

-- | Infinite zero-based table of factorials.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 factorial
--   [1,1,2,6,24]
--   </pre>
--   
--   The time-and-space behaviour of <a>factorial</a> is similar to
--   described in <a>Math.NumberTheory.Recurrences.Bilinear#memory</a>.
factorial :: (Num a, Enum a) => Infinite a

-- | Prime factors of a factorial.
--   
--   <pre>
--   factorialFactors n == factorise (factorial !! n)
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; factorialFactors 10
--   [(Prime 2,8),(Prime 3,4),(Prime 5,2),(Prime 7,1)]
--   </pre>
factorialFactors :: Word -> [(Prime Word, Word)]

-- | <tt><a>fibonacci</a> k</tt> calculates the <tt>k</tt>-th Fibonacci
--   number in <i>O</i>(<tt>log (abs k)</tt>) steps. The index may be
--   negative. This is efficient for calculating single Fibonacci numbers
--   (with large index), but for computing many Fibonacci numbers in close
--   proximity, it is better to use the simple addition formula starting
--   from an appropriate pair of successive Fibonacci numbers.
fibonacci :: Num a => Int -> a

-- | <tt><a>fibonacciPair</a> k</tt> returns the pair <tt>(F(k),
--   F(k+1))</tt> of the <tt>k</tt>-th Fibonacci number and its successor,
--   thus it can be used to calculate the Fibonacci numbers from some index
--   on without needing to compute the previous. The pair is efficiently
--   calculated in <i>O</i>(<tt>log (abs k)</tt>) steps. The index may be
--   negative.
fibonacciPair :: Num a => Int -> (a, a)

-- | <tt><a>lucas</a> k</tt> computes the <tt>k</tt>-th Lucas number. Very
--   similar to <tt><a>fibonacci</a></tt>.
lucas :: Num a => Int -> a

-- | <tt><a>lucasPair</a> k</tt> computes the pair <tt>(L(k), L(k+1))</tt>
--   of the <tt>k</tt>-th Lucas number and its successor. Very similar to
--   <tt><a>fibonacciPair</a></tt>.
lucasPair :: Num a => Int -> (a, a)

-- | <tt><a>generalLucas</a> p q k</tt> calculates the quadruple <tt>(U(k),
--   U(k+1), V(k), V(k+1))</tt> where <tt>U(i)</tt> is the Lucas sequence
--   of the first kind and <tt>V(i)</tt> the Lucas sequence of the second
--   kind for the parameters <tt>p</tt> and <tt>q</tt>, where <tt>p^2-4q /=
--   0</tt>. Both sequences satisfy the recurrence relation <tt>A(j+2) =
--   p*A(j+1) - q*A(j)</tt>, the starting values are <tt>U(0) = 0, U(1) =
--   1</tt> and <tt>V(0) = 2, V(1) = p</tt>. The Fibonacci numbers form the
--   Lucas sequence of the first kind for the parameters <tt>p = 1, q =
--   -1</tt> and the Lucas numbers form the Lucas sequence of the second
--   kind for these parameters. Here, the index must be non-negative, since
--   the terms of the sequence for negative indices are in general not
--   integers.
generalLucas :: Num a => a -> a -> Int -> (a, a, a, a)


-- | Bilinear recurrent sequences and Bernoulli numbers, roughly covering
--   Ch. 5-6 of <i>Concrete Mathematics</i> by R. L. Graham, D. E. Knuth
--   and O. Patashnik.
--   
--   <b>Note on memory leaks and memoization.</b> Top-level definitions in
--   this module are polymorphic, so the results of computations are not
--   retained in memory. Make them monomorphic to take advantages of
--   memoization. Compare
--   
--   <pre>
--   &gt;&gt;&gt; binomial !! 1000 !! 1000 :: Integer -- (0.01 secs, 1,385,512 bytes)
--   1
--   
--   &gt;&gt;&gt; binomial !! 1000 !! 1000 :: Integer -- (0.01 secs, 1,381,616 bytes)
--   1
--   </pre>
--   
--   against
--   
--   <pre>
--   &gt;&gt;&gt; let binomial' = binomial :: [[Integer]]
--   
--   &gt;&gt;&gt; binomial' !! 1000 !! 1000 :: Integer -- (0.01 secs, 1,381,696 bytes)
--   1
--   
--   &gt;&gt;&gt; binomial' !! 1000 !! 1000 :: Integer -- (0.01 secs, 391,152 bytes)
--   1
--   </pre>
module Math.NumberTheory.Recurrences.Bilinear

-- | Infinite zero-based table of binomial coefficients (also known as
--   Pascal triangle).
--   
--   <pre>
--   binomial !! n !! k == n! / k! / (n - k)!
--   </pre>
--   
--   Note that <a>binomial</a> !! n !! k is asymptotically slower than
--   <a>binomialLine</a> n !! k, but imposes only <a>Semiring</a>
--   constraint.
--   
--   <pre>
--   &gt;&gt;&gt; take 6 binomial :: [[Int]]
--   [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1]]
--   </pre>
binomial :: Semiring a => Infinite [a]

-- | Pascal triangle, rotated by 45 degrees.
--   
--   <pre>
--   binomialRotated !! n !! k == (n + k)! / n! / k! == binomial !! (n + k) !! k
--   </pre>
--   
--   Note that <a>binomialRotated</a> !! n !! k is asymptotically slower
--   than <a>binomialDiagonal</a> n !! k, but imposes only <a>Semiring</a>
--   constraint.
--   
--   <pre>
--   &gt;&gt;&gt; take 6 (map (take 6) binomialRotated) :: [[Int]]
--   [[1,1,1,1,1,1],[1,2,3,4,5,6],[1,3,6,10,15,21],[1,4,10,20,35,56],[1,5,15,35,70,126],[1,6,21,56,126,252]]
--   </pre>
binomialRotated :: Semiring a => Infinite (Infinite a)

-- | The n-th (zero-based) line of <a>binomial</a> (and the n-th diagonal
--   of <a>binomialRotated</a>).
--   
--   <pre>
--   &gt;&gt;&gt; binomialLine 5
--   [1,5,10,10,5,1]
--   </pre>
binomialLine :: (Enum a, GcdDomain a) => a -> [a]

-- | The n-th (zero-based) diagonal of <a>binomial</a> (and the n-th line
--   of <a>binomialRotated</a>).
--   
--   <pre>
--   &gt;&gt;&gt; take 6 (binomialDiagonal 5)
--   [1,6,21,56,126,252]
--   </pre>
binomialDiagonal :: (Enum a, GcdDomain a) => a -> Infinite a

-- | Prime factors of a binomial coefficient.
--   
--   <pre>
--   binomialFactors n k == factorise (binomial !! n !! k)
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; binomialFactors 10 4
--   [(Prime 2,1),(Prime 3,1),(Prime 5,1),(Prime 7,1)]
--   </pre>
binomialFactors :: Word -> Word -> [(Prime Word, Word)]

-- | Infinite zero-based table of <a>Stirling numbers of the first
--   kind</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (map (take 5) stirling1)
--   [[1],[0,1],[0,1,1],[0,2,3,1],[0,6,11,6,1]]
--   </pre>
--   
--   Complexity: <tt>stirling1 !! n !! k</tt> is O(n ln n) bits long, its
--   computation takes O(k n^2 ln n) time and forces thunks <tt>stirling1
--   !! i !! j</tt> for <tt>0 &lt;= i &lt;= n</tt> and <tt>max(0, k - n +
--   i) &lt;= j &lt;= k</tt>.
--   
--   One could also consider <a>unsignedStirling1st</a> from
--   <a>combinat</a> package to compute stand-alone values.
stirling1 :: (Num a, Enum a) => Infinite [a]

-- | Infinite zero-based table of <a>Stirling numbers of the second
--   kind</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (map (take 5) stirling2)
--   [[1],[0,1],[0,1,1],[0,1,3,1],[0,1,7,6,1]]
--   </pre>
--   
--   Complexity: <tt>stirling2 !! n !! k</tt> is O(n ln n) bits long, its
--   computation takes O(k n^2 ln n) time and forces thunks <tt>stirling2
--   !! i !! j</tt> for <tt>0 &lt;= i &lt;= n</tt> and <tt>max(0, k - n +
--   i) &lt;= j &lt;= k</tt>.
--   
--   One could also consider <a>stirling2nd</a> from <a>combinat</a>
--   package to compute stand-alone values.
stirling2 :: (Num a, Enum a) => Infinite [a]

-- | Infinite one-based table of <a>Lah numbers</a>. <tt>lah !! n !! k</tt>
--   equals to lah(n + 1, k + 1).
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (map (take 5) lah)
--   [[1],[2,1],[6,6,1],[24,36,12,1],[120,240,120,20,1]]
--   </pre>
--   
--   Complexity: <tt>lah !! n !! k</tt> is O(n ln n) bits long, its
--   computation takes O(k n ln n) time and forces thunks <tt>lah !! n !!
--   i</tt> for <tt>0 &lt;= i &lt;= k</tt>.
lah :: Integral a => Infinite [a]

-- | Infinite zero-based table of <a>Eulerian numbers of the first
--   kind</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (map (take 5) eulerian1)
--   [[],[1],[1,1],[1,4,1],[1,11,11,1]]
--   </pre>
--   
--   Complexity: <tt>eulerian1 !! n !! k</tt> is O(n ln n) bits long, its
--   computation takes O(k n^2 ln n) time and forces thunks <tt>eulerian1
--   !! i !! j</tt> for <tt>0 &lt;= i &lt;= n</tt> and <tt>max(0, k - n +
--   i) &lt;= j &lt;= k</tt>.
eulerian1 :: (Num a, Enum a) => Infinite [a]

-- | Infinite zero-based table of <a>Eulerian numbers of the second
--   kind</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (map (take 5) eulerian2)
--   [[],[1],[1,2],[1,8,6],[1,22,58,24]]
--   </pre>
--   
--   Complexity: <tt>eulerian2 !! n !! k</tt> is O(n ln n) bits long, its
--   computation takes O(k n^2 ln n) time and forces thunks <tt>eulerian2
--   !! i !! j</tt> for <tt>0 &lt;= i &lt;= n</tt> and <tt>max(0, k - n +
--   i) &lt;= j &lt;= k</tt>.
eulerian2 :: (Num a, Enum a) => Infinite [a]

-- | Infinite zero-based sequence of <a>Bernoulli numbers</a>, computed via
--   <a>connection</a> with <a>stirling2</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 bernoulli
--   [1 % 1,(-1) % 2,1 % 6,0 % 1,(-1) % 30]
--   </pre>
--   
--   Complexity: <tt>bernoulli !! n</tt> is O(n ln n) bits long, its
--   computation takes O(n^3 ln n) time and forces thunks <tt>stirling2 !!
--   i !! j</tt> for <tt>0 &lt;= i &lt;= n</tt> and <tt>0 &lt;= j &lt;=
--   i</tt>.
--   
--   One could also consider <a>bernoulli</a> from <a>combinat</a> package
--   to compute stand-alone values.
bernoulli :: Integral a => Infinite (Ratio a)

-- | The same sequence as <tt>euler'</tt>, but with type <tt>[a]</tt>
--   instead of <tt>[Ratio a]</tt> as the denominators in <tt>euler'</tt>
--   are always <tt>1</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 euler :: [Integer]
--   [1,0,-1,0,5,0,-61,0,1385,0]
--   </pre>
euler :: Integral a => Infinite a

-- | Infinite zero-based list of the <tt>n</tt>-th order Euler polynomials
--   evaluated at <tt>1</tt>. The algorithm used was derived from
--   <a>Algorithms for Bernoulli numbers and Euler numbers</a> by Kwang-Wu
--   Chen, third formula of the Corollary in page 7. Element-by-element
--   division of sequences <a>A1986631</a> and <a>A006519</a> in OEIS.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 eulerPolyAt1 :: [Rational]
--   [1 % 1,1 % 2,0 % 1,(-1) % 4,0 % 1,1 % 2,0 % 1,(-17) % 8,0 % 1,31 % 2]
--   </pre>
eulerPolyAt1 :: Integral a => Infinite (Ratio a)

-- | <a>Faulhaber's formula</a>.
--   
--   <pre>
--   &gt;&gt;&gt; sum (map (^ 10) [0..100])
--   959924142434241924250
--   
--   &gt;&gt;&gt; sum $ zipWith (*) (faulhaberPoly 10) (iterate (* 100) 1)
--   959924142434241924250 % 1
--   </pre>
faulhaberPoly :: (GcdDomain a, Integral a) => Int -> [Ratio a]


module Math.NumberTheory.Recurrences

-- | Infinite zero-based table of <a>partition numbers</a>.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 partition
--   [1,1,2,3,5,7,11,15,22,30]
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; import Data.Mod
--   
--   &gt;&gt;&gt; partition !! 1000 :: Mod 1000
--   (991 `modulo` 1000)
--   </pre>
partition :: Num a => Infinite a


-- | Primality tests.
module Math.NumberTheory.Primes.Testing

-- | <tt>isPrime n</tt> tests whether <tt>n</tt> is a prime (negative or
--   positive). It is a combination of trial division and Baillie-PSW test.
--   
--   If <tt>isPrime n</tt> returns <tt>False</tt> then <tt>n</tt> is
--   definitely composite. There is a theoretical possibility that
--   <tt>isPrime n</tt> is <tt>True</tt>, but in fact <tt>n</tt> is not
--   prime. However, no such numbers are known and none exist below
--   <tt>2^64</tt>. If you have found one, please report it, because it is
--   a major discovery.
isPrime :: Integer -> Bool

-- | <tt><a>isCertifiedPrime</a> n</tt> tests primality of <tt>n</tt>,
--   first trial division by small primes is performed, then a Baillie PSW
--   test and finally a prime certificate is constructed and verified,
--   provided no step before found <tt>n</tt> to be composite. Constructing
--   prime certificates can take a <i>very</i> long time, so use this with
--   care.
isCertifiedPrime :: Integer -> Bool

-- | Primality test after Baillie, Pomerance, Selfridge and Wagstaff. The
--   Baillie-PSW test consists of a strong Fermat probable primality test
--   followed by a (strong) Lucas primality test. This implementation
--   assumes that the number <tt>n</tt> to test is odd and larger than
--   <tt>3</tt>. Even and small numbers have to be handled before. Also,
--   before applying this test, trial division by small primes should be
--   performed to identify many composites cheaply (although the
--   Baillie-PSW test is rather fast, about the same speed as a strong
--   Fermat test for four or five bases usually, it is, for large numbers,
--   much more costly than trial division by small primes, the primes less
--   than <tt>1000</tt>, say, so eliminating numbers with small prime
--   factors beforehand is more efficient).
--   
--   The Baillie-PSW test is very reliable, so far no composite numbers
--   passing it are known, and it is known (Gilchrist 2010) that no
--   Baillie-PSW pseudoprimes exist below <tt>2^64</tt>. However, a
--   heuristic argument by Pomerance indicates that there are likely
--   infinitely many Baillie-PSW pseudoprimes. On the other hand, according
--   to <a>http://mathworld.wolfram.com/Baillie-PSWPrimalityTest.html</a>
--   there is reason to believe that there are none with less than several
--   thousand digits, so that for most use cases the test can be considered
--   definitive.
bailliePSW :: Integer -> Bool

-- | Miller-Rabin probabilistic primality test. It consists of the trial
--   division test and several rounds of the strong Fermat test with
--   different bases. The choice of trial divisors and bases are
--   implementation details and may change in future silently.
--   
--   First argument stands for the number of rounds of strong Fermat test.
--   If it is 0, only trial division test is performed.
--   
--   If <tt>millerRabinV k n</tt> returns <tt>False</tt> then <tt>n</tt> is
--   definitely composite. Otherwise <tt>n</tt> may appear composite with
--   probability <tt>1/4^k</tt>.
millerRabinV :: Int -> Integer -> Bool

-- | <tt><a>isStrongFermatPP</a> n b</tt> tests whether non-negative
--   <tt>n</tt> is a strong Fermat probable prime for base <tt>b</tt>.
--   
--   Apart from primes, also some composite numbers have the tested
--   property, but those are rare. Very rare are composite numbers having
--   the property for many bases, so testing a large prime candidate with
--   several bases can identify composite numbers with high probability. An
--   odd number <tt>n &gt; 3</tt> is prime if and only if
--   <tt><a>isStrongFermatPP</a> n b</tt> holds for all <tt>b</tt> with
--   <tt>2 &lt;= b &lt;= (n-1)/2</tt>, but of course checking all those
--   bases would be less efficient than trial division, so one normally
--   checks only a relatively small number of bases, depending on the
--   desired degree of certainty. The probability that a randomly chosen
--   base doesn't identify a composite number <tt>n</tt> is less than
--   <tt>1/4</tt>, so five to ten tests give a reasonable level of
--   certainty in general.
--   
--   Please consult <a>Deterministic variants of the Miller-Rabin primality
--   test</a> for the best choice of bases.
isStrongFermatPP :: Integer -> Integer -> Bool

-- | <tt><a>isFermatPP</a> n b</tt> tests whether <tt>n</tt> is a Fermat
--   probable prime for the base <tt>b</tt>, that is, whether <tt>b^(n-1)
--   <a>mod</a> n == 1</tt>. This is a weaker but simpler condition.
--   However, more is lost in strength than is gained in simplicity, so for
--   primality testing, the strong check should be used. The remarks about
--   the choice of bases to test from <tt><a>isStrongFermatPP</a></tt>
--   apply with the modification that if <tt>a</tt> and <tt>b</tt> are
--   Fermat bases for <tt>n</tt>, then <tt>a*b</tt> <i>always</i> is a
--   Fermat base for <tt>n</tt> too. A <i>Charmichael number</i> is a
--   composite number <tt>n</tt> which is a Fermat probable prime for all
--   bases <tt>b</tt> coprime to <tt>n</tt>. By the above, only primes
--   <tt>p &lt;= n/2</tt> not dividing <tt>n</tt> need to be tested to
--   identify Carmichael numbers (however, testing all those primes would
--   be less efficient than determining Carmichaelness from the prime
--   factorisation; but testing an appropriate number of prime bases is
--   reasonable to find out whether it's worth the effort to undertake the
--   prime factorisation).
isFermatPP :: Integer -> Integer -> Bool

-- | <tt><a>trialDivisionPrimeTo</a> bound n</tt> tests whether <tt>n</tt>
--   is coprime to all primes <tt>&lt;= bound</tt>. If <tt>n &lt;=
--   bound^2</tt>, this is a full prime test, but very slow if <tt>n</tt>
--   has no small prime divisors.
trialDivisionPrimeTo :: Integer -> Integer -> Bool


-- | Type for numbers, accompanied by their factorisation.
module Math.NumberTheory.Prefactored

-- | A container for a number and its pairwise coprime (but not necessarily
--   prime) factorisation. It is designed to preserve information about
--   factors under multiplication. One can use this representation to speed
--   up prime factorisation and computation of arithmetic functions.
--   
--   For instance, let <tt>p</tt> and <tt>q</tt> be big primes:
--   
--   <pre>
--   &gt;&gt;&gt; let p = 1000000000000000000000000000057 :: Integer
--   
--   &gt;&gt;&gt; let q = 2000000000000000000000000000071 :: Integer
--   </pre>
--   
--   It would be difficult to compute the totient function of their product
--   as is, because once we multiplied them the information of factors is
--   lost and <a>totient</a> (<tt>p</tt> * <tt>q</tt>) would take ages.
--   Things become different if we simply change types of <tt>p</tt> and
--   <tt>q</tt> to prefactored ones:
--   
--   <pre>
--   &gt;&gt;&gt; let p = 1000000000000000000000000000057 :: Prefactored Integer
--   
--   &gt;&gt;&gt; let q = 2000000000000000000000000000071 :: Prefactored Integer
--   </pre>
--   
--   Now the <a>totient</a> function can be computed instantly:
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.ArithmeticFunctions
--   
--   &gt;&gt;&gt; prefValue $ totient (p^2 * q^3)
--   8000000000000000000000000001752000000000000000000000000151322000000000000000000000006445392000000000000000000000135513014000000000000000000001126361040
--   
--   &gt;&gt;&gt; prefValue $ totient $ totient (p^2 * q^3)
--   2133305798262843681544648472180210822742702690942899511234131900112583590230336435053688694839034890779375223070157301188739881477320529552945446912000
--   </pre>
--   
--   Let us look under the hood:
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.ArithmeticFunctions
--   
--   &gt;&gt;&gt; prefFactors $ totient (p^2 * q^3)
--   Coprimes {unCoprimes = [(1000000000000000000000000000057,1),(41666666666666666666666666669,1),(2000000000000000000000000000071,2),(111111111111111111111111111115,1),(2,4),(3,3)]}
--   
--   &gt;&gt;&gt; prefFactors $ totient $ totient (p^2 * q^3)
--   Coprimes {unCoprimes = [(39521,1),(227098769,1),(22222222222222222222222222223,1),(2000000000000000000000000000071,1),(361696272343,1),(85331809838489,1),(6046667,1),(199937,1),(5,3),(41666666666666666666666666669,1),(2,22),(3,8)]}
--   </pre>
--   
--   Pairwise coprimality of factors is crucial, because it allows us to
--   process them independently, possibly even in parallel or concurrent
--   fashion.
--   
--   Following invariant is guaranteed to hold:
--   
--   <pre>
--   abs (prefValue x) = abs (product (map (uncurry (^)) (prefFactors x)))
--   </pre>
data Prefactored a

-- | Create <a>Prefactored</a> from a given number.
--   
--   <pre>
--   &gt;&gt;&gt; fromValue 123
--   Prefactored {prefValue = 123, prefFactors = Coprimes {unCoprimes = [(123,1)]}}
--   </pre>
fromValue :: (Eq a, GcdDomain a) => a -> Prefactored a

-- | Create <a>Prefactored</a> from a given list of pairwise coprime (but
--   not necessarily prime) factors with multiplicities.
--   
--   <pre>
--   &gt;&gt;&gt; fromFactors (splitIntoCoprimes [(140, 1), (165, 1)])
--   Prefactored {prefValue = 23100, prefFactors = Coprimes {unCoprimes = [(28,1),(33,1),(5,2)]}}
--   
--   &gt;&gt;&gt; fromFactors (splitIntoCoprimes [(140, 2), (165, 3)])
--   Prefactored {prefValue = 88045650000, prefFactors = Coprimes {unCoprimes = [(28,2),(33,3),(5,5)]}}
--   </pre>
fromFactors :: Semiring a => Coprimes a Word -> Prefactored a
instance GHC.Classes.Eq a => GHC.Classes.Eq (Math.NumberTheory.Prefactored.Prefactored a)
instance (GHC.Classes.Eq a, GHC.Internal.Num.Num a, Data.Euclidean.GcdDomain a) => GHC.Internal.Num.Num (Math.NumberTheory.Prefactored.Prefactored a)
instance (GHC.Classes.Eq a, Data.Euclidean.GcdDomain a) => Data.Semiring.Semiring (Math.NumberTheory.Prefactored.Prefactored a)
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.Prefactored.Prefactored a)
instance (GHC.Classes.Eq a, Data.Euclidean.GcdDomain a, Math.NumberTheory.Primes.UniqueFactorisation a) => Math.NumberTheory.Primes.UniqueFactorisation (Math.NumberTheory.Prefactored.Prefactored a)


-- | Generalised Möbius inversion
module Math.NumberTheory.MoebiusInversion

-- | <tt>generalInversion g n</tt> evaluates the generalised Möbius
--   inversion of <tt>g</tt> at the argument <tt>n</tt>.
--   
--   The generalised Möbius inversion implemented here allows an efficient
--   calculation of isolated values of the function <tt>f : N -&gt; Z</tt>
--   if the function <tt>g</tt> defined by
--   
--   <pre>
--   g n = sum [f (n `quot` k) | k &lt;- [1 .. n]]
--   </pre>
--   
--   can be cheaply computed. By the generalised Möbius inversion formula,
--   then
--   
--   <pre>
--   f n = sum [moebius k * g (n `quot` k) | k &lt;- [1 .. n]]
--   </pre>
--   
--   which allows the computation in <i>O</i>(n) steps, if the values of
--   the Möbius function are known. A slightly different formula, used
--   here, does not need the values of the Möbius function and allows the
--   computation in <i>O</i>(n^0.75) steps, using <i>O</i>(n^0.5) memory.
--   
--   An example of a pair of such functions where the inversion allows a
--   more efficient computation than the direct approach is
--   
--   <pre>
--   f n = number of reduced proper fractions with denominator &lt;= n
--   
--   g n = number of proper fractions with denominator &lt;= n
--   </pre>
--   
--   (a <i>proper fraction</i> is a fraction <tt>0 &lt; n/d &lt; 1</tt>).
--   Then <tt>f n</tt> is the cardinality of the Farey sequence of order
--   <tt>n</tt> (minus 1 or 2 if 0 and/or 1 are included in the Farey
--   sequence), or the sum of the totients of the numbers <tt>2 &lt;= k
--   &lt;= n</tt>. <tt>f n</tt> is not easily directly computable, but then
--   <tt>g n = n*(n-1)/2</tt> is very easy to compute, and hence the
--   inversion gives an efficient method of computing <tt>f n</tt>.
--   
--   Since the function arguments are used as array indices, the domain of
--   <tt>f</tt> is restricted to <a>Int</a>.
--   
--   The value <tt>f n</tt> is then computed by <tt>generalInversion g
--   n</tt>. Note that when many values of <tt>f</tt> are needed, there are
--   far more efficient methods, this method is only appropriate to compute
--   isolated values of <tt>f</tt>.
generalInversion :: forall t (v :: Type -> Type). (Num t, Vector v t) => Proxy v -> (Word -> t) -> Word -> t

-- | <tt>totientSum n</tt> is, for <tt>n &gt; 0</tt>, the sum of
--   <tt>[totient k | k &lt;- [1 .. n]]</tt>, computed via generalised
--   Möbius inversion. See
--   <a>http://mathworld.wolfram.com/TotientSummatoryFunction.html</a> for
--   the formula used for <tt>totientSum</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Proxy
--   
--   &gt;&gt;&gt; totientSum (Proxy :: Proxy Data.Vector.Unboxed.Vector) 100 :: Int
--   3044
--   
--   &gt;&gt;&gt; totientSum (Proxy :: Proxy Data.Vector.Vector) 100 :: Integer
--   3044
--   </pre>
totientSum :: forall t (v :: Type -> Type). (Integral t, Vector v t) => Proxy v -> Word -> t


-- | Singleton data types.
module Math.NumberTheory.Moduli.Singleton

-- | This singleton data type establishes a correspondence between a modulo
--   <tt>m</tt> on type level and its factorisation on term level.
data SFactors a (m :: Nat)

-- | Create a singleton from a type-level positive modulo <tt>m</tt>,
--   passed in a constraint.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; sfactors :: SFactors Integer 13
--   SFactors {unSFactors = [(Prime 13,1)]}
--   </pre>
sfactors :: forall a (m :: Nat). (Ord a, UniqueFactorisation a, KnownNat m) => SFactors a m

-- | Create a singleton from factors of <tt>m</tt>. Factors must be
--   distinct, as in output of <a>factorise</a>.
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.Primes
--   
--   &gt;&gt;&gt; someSFactors (factorise 98)
--   SFactors {unSFactors = [(Prime 2,1),(Prime 7,2)]}
--   </pre>
someSFactors :: (Ord a, Num a) => [(Prime a, Word)] -> Some (SFactors a)

-- | Factors of <tt>m</tt>.
unSFactors :: SFactors a m -> [(Prime a, Word)]

-- | Convert a singleton to a proof that <tt>m</tt> is known. Usage
--   example:
--   
--   <pre>
--   toModulo :: SFactors Integer m -&gt; Natural
--   toModulo t = case proofFromSFactors t of Sub Dict -&gt; natVal t
--   </pre>
proofFromSFactors :: forall a (m :: Nat). Integral a => SFactors a m -> () :- KnownNat m

-- | This singleton data type establishes a correspondence between a modulo
--   <tt>m</tt> on type level and a cyclic group of the same order on term
--   level.
data CyclicGroup a (m :: Nat)

-- | Create a singleton from a type-level positive modulo <tt>m</tt>,
--   passed in a constraint.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; import Data.Maybe
--   
--   &gt;&gt;&gt; cyclicGroup :: Maybe (CyclicGroup Integer 169)
--   Just (CGOddPrimePower' (Prime 13) 2)
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; :set -XTypeOperators -XNoStarIsType
--   
--   &gt;&gt;&gt; import GHC.TypeNats
--   
--   &gt;&gt;&gt; sfactorsToCyclicGroup (sfactors :: SFactors Integer 4)
--   Just CG4'
--   
--   &gt;&gt;&gt; sfactorsToCyclicGroup (sfactors :: SFactors Integer (2 * 13 ^ 3))
--   Just (CGDoubleOddPrimePower' (Prime 13) 3)
--   
--   &gt;&gt;&gt; sfactorsToCyclicGroup (sfactors :: SFactors Integer  (4 * 13))
--   Nothing
--   </pre>
cyclicGroup :: forall a (m :: Nat). (Integral a, UniqueFactorisation a, KnownNat m) => Maybe (CyclicGroup a m)

-- | Create a singleton from factors. Factors must be distinct, as in
--   output of <a>factorise</a>.
cyclicGroupFromFactors :: (Eq a, Num a) => [(Prime a, Word)] -> Maybe (Some (CyclicGroup a))

-- | Similar to <a>cyclicGroupFromFactors</a> . <a>factorise</a>, but much
--   faster, because it but performes only one primality test instead of
--   full factorisation.
cyclicGroupFromModulo :: (Integral a, UniqueFactorisation a) => a -> Maybe (Some (CyclicGroup a))

-- | Convert a cyclic group to a proof that <tt>m</tt> is known. Usage
--   example:
--   
--   <pre>
--   toModulo :: CyclicGroup Integer m -&gt; Natural
--   toModulo t = case proofFromCyclicGroup t of Sub Dict -&gt; natVal t
--   </pre>
proofFromCyclicGroup :: forall a (m :: Nat). Integral a => CyclicGroup a m -> () :- KnownNat m

-- | Unidirectional pattern for residues modulo 2.
pattern CG2 :: CyclicGroup a m

-- | Unidirectional pattern for residues modulo 4.
pattern CG4 :: CyclicGroup a m

-- | Unidirectional pattern for residues modulo <tt>p</tt>^<tt>k</tt> for
--   <b>odd</b> prime <tt>p</tt>.
pattern CGOddPrimePower :: Prime a -> Word -> CyclicGroup a m

-- | Unidirectional pattern for residues modulo 2<tt>p</tt>^<tt>k</tt> for
--   <b>odd</b> prime <tt>p</tt>.
pattern CGDoubleOddPrimePower :: Prime a -> Word -> CyclicGroup a m

-- | Invert <a>sfactorsToCyclicGroup</a>.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Maybe
--   
--   &gt;&gt;&gt; cyclicGroupToSFactors (fromJust (sfactorsToCyclicGroup (sfactors :: SFactors Integer 4)))
--   SFactors {unSFactors = [(Prime 2,2)]}
--   </pre>
cyclicGroupToSFactors :: forall a (m :: Nat). Num a => CyclicGroup a m -> SFactors a m

-- | Check whether a multiplicative group of residues, characterized by its
--   modulo, is cyclic and, if yes, return its form.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XTypeOperators -XNoStarIsType
--   
--   &gt;&gt;&gt; import GHC.TypeNats
--   
--   &gt;&gt;&gt; sfactorsToCyclicGroup (sfactors :: SFactors Integer 4)
--   Just CG4'
--   
--   &gt;&gt;&gt; sfactorsToCyclicGroup (sfactors :: SFactors Integer (2 * 13 ^ 3))
--   Just (CGDoubleOddPrimePower' (Prime 13) 3)
--   
--   &gt;&gt;&gt; sfactorsToCyclicGroup (sfactors :: SFactors Integer  (4 * 13))
--   Nothing
--   </pre>
sfactorsToCyclicGroup :: forall a (m :: Nat). (Eq a, Num a) => SFactors a m -> Maybe (CyclicGroup a m)

-- | Wrapper to hide an unknown type-level natural.
data Some (a :: Nat -> Type)
[Some] :: forall (a :: Nat -> Type) (m :: Nat). a m -> Some a
instance GHC.Classes.Eq (Math.NumberTheory.Moduli.Singleton.CyclicGroup a m)
instance GHC.Classes.Eq (Math.NumberTheory.Moduli.Singleton.SFactors a m)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.CyclicGroup a))
instance GHC.Classes.Ord a => GHC.Classes.Eq (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.SFactors a))
instance GHC.Internal.Generics.Generic (Math.NumberTheory.Moduli.Singleton.CyclicGroup a m)
instance GHC.Internal.Generics.Generic (Math.NumberTheory.Moduli.Singleton.SFactors a m)
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Math.NumberTheory.Moduli.Singleton.CyclicGroup a m)
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Math.NumberTheory.Moduli.Singleton.SFactors a m)
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.CyclicGroup a))
instance Control.DeepSeq.NFData a => Control.DeepSeq.NFData (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.SFactors a))
instance GHC.Classes.Ord (Math.NumberTheory.Moduli.Singleton.CyclicGroup a m)
instance GHC.Classes.Ord (Math.NumberTheory.Moduli.Singleton.SFactors a m)
instance GHC.Classes.Ord a => GHC.Classes.Ord (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.CyclicGroup a))
instance GHC.Classes.Ord a => GHC.Classes.Ord (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.SFactors a))
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.Moduli.Singleton.CyclicGroup a m)
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.Moduli.Singleton.SFactors a m)
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.CyclicGroup a))
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.Moduli.Singleton.Some (Math.NumberTheory.Moduli.Singleton.SFactors a))


-- | Modular square roots and <a>Jacobi symbol</a>.
module Math.NumberTheory.Moduli.Sqrt

-- | List all modular square roots.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; sqrtsMod sfactors (1 :: Mod 60)
--   [(1 `modulo` 60),(49 `modulo` 60),(41 `modulo` 60),(29 `modulo` 60),(31 `modulo` 60),(19 `modulo` 60),(11 `modulo` 60),(59 `modulo` 60)]
--   </pre>
sqrtsMod :: forall (m :: Nat). SFactors Integer m -> Mod m -> [Mod m]

-- | List all square roots modulo a number, the factorisation of which is
--   passed as a second argument.
--   
--   <pre>
--   &gt;&gt;&gt; sqrtsModFactorisation 1 (factorise 60)
--   [1,49,41,29,31,19,11,59]
--   </pre>
sqrtsModFactorisation :: Integer -> [(Prime Integer, Word)] -> [Integer]

-- | List all square roots modulo the power of a prime.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Maybe
--   
--   &gt;&gt;&gt; import Math.NumberTheory.Primes
--   
--   &gt;&gt;&gt; sqrtsModPrimePower 7 (fromJust (isPrime 3)) 2
--   [4,5]
--   
--   &gt;&gt;&gt; sqrtsModPrimePower 9 (fromJust (isPrime 3)) 3
--   [3,12,21,24,6,15]
--   </pre>
sqrtsModPrimePower :: Integer -> Prime Integer -> Word -> [Integer]

-- | List all square roots by prime modulo.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Maybe
--   
--   &gt;&gt;&gt; import Math.NumberTheory.Primes
--   
--   &gt;&gt;&gt; sqrtsModPrime 1 (fromJust (isPrime 5))
--   [1,4]
--   
--   &gt;&gt;&gt; sqrtsModPrime 0 (fromJust (isPrime 5))
--   [0]
--   
--   &gt;&gt;&gt; sqrtsModPrime 2 (fromJust (isPrime 5))
--   []
--   </pre>
sqrtsModPrime :: Integer -> Prime Integer -> [Integer]

-- | Represents three possible values of <a>Jacobi symbol</a>.
data JacobiSymbol
MinusOne :: JacobiSymbol
Zero :: JacobiSymbol
One :: JacobiSymbol

-- | <a>Jacobi symbol</a> of two arguments. The lower argument
--   ("denominator") must be odd and positive, this condition is checked.
--   
--   If arguments have a common factor, the result is <a>Zero</a>,
--   otherwise it is <a>MinusOne</a> or <a>One</a>.
--   
--   <pre>
--   &gt;&gt;&gt; jacobi 1001 9911 -- arguments have a common factor 11
--   Zero
--   
--   &gt;&gt;&gt; jacobi 1001 9907
--   MinusOne
--   </pre>
jacobi :: (Integral a, Bits a) => a -> a -> JacobiSymbol

-- | Convenience function to convert out of a Jacobi symbol
symbolToNum :: Num a => JacobiSymbol -> a


-- | This module exports functions for manipulating Gaussian integers,
--   including computing their prime factorisations.
module Math.NumberTheory.Quadratic.GaussianIntegers

-- | A Gaussian integer is a+bi, where a and b are both integers.
data GaussianInteger
(:+) :: !Integer -> !Integer -> GaussianInteger
[real] :: GaussianInteger -> !Integer
[imag] :: GaussianInteger -> !Integer
infix 6 :+

-- | The imaginary unit, where
--   
--   <pre>
--   ι .^ 2 == -1
--   </pre>
ι :: GaussianInteger

-- | Conjugate a Gaussian integer.
conjugate :: GaussianInteger -> GaussianInteger

-- | The square of the magnitude of a Gaussian integer.
norm :: GaussianInteger -> Integer

-- | An infinite list of the Gaussian primes. Uses primes in Z to
--   exhaustively generate all Gaussian primes (up to associates), in order
--   of ascending magnitude.
--   
--   <pre>
--   &gt;&gt;&gt; take 10 primes
--   [Prime 1+ι,Prime 2+ι,Prime 1+2*ι,Prime 3,Prime 3+2*ι,Prime 2+3*ι,Prime 4+ι,Prime 1+4*ι,Prime 5+2*ι,Prime 2+5*ι]
--   </pre>
primes :: Infinite (Prime GaussianInteger)

-- | Find a Gaussian integer whose norm is the given prime number of form
--   4k + 1 using <a>Hermite-Serret algorithm</a>.
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.Primes (nextPrime)
--   
--   &gt;&gt;&gt; findPrime (nextPrime 5)
--   Prime 2+ι
--   </pre>
findPrime :: Prime Integer -> Prime GaussianInteger
instance GHC.Classes.Eq Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance Data.Euclidean.Euclidean Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance Data.Euclidean.GcdDomain Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance GHC.Internal.Generics.Generic Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance Control.DeepSeq.NFData Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance GHC.Internal.Num.Num Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance GHC.Classes.Ord Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance Data.Semiring.Ring Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance Data.Semiring.Semiring Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance GHC.Internal.Show.Show Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger
instance Math.NumberTheory.Primes.UniqueFactorisation Math.NumberTheory.Quadratic.GaussianIntegers.GaussianInteger


-- | This module exports functions for manipulating Eisenstein integers,
--   including computing their prime factorisations.
module Math.NumberTheory.Quadratic.EisensteinIntegers

-- | An Eisenstein integer is <tt>a + bω</tt>, where <tt>a</tt> and
--   <tt>b</tt> are both integers.
data EisensteinInteger
(:+) :: !Integer -> !Integer -> EisensteinInteger
infix 6 :+

-- | The imaginary unit for Eisenstein integers, where
--   
--   <pre>
--   ω == (-1/2) + ((sqrt 3)/2)ι == exp(2*pi*ι/3)
--   </pre>
--   
--   and <tt>ι</tt> is the usual imaginary unit with <tt>ι² == -1</tt>.
ω :: EisensteinInteger

-- | Conjugate a Eisenstein integer.
conjugate :: EisensteinInteger -> EisensteinInteger

-- | The square of the magnitude of a Eisenstein integer.
norm :: EisensteinInteger -> Integer

-- | Produce a list of an <tt>EisensteinInteger</tt>'s associates.
associates :: EisensteinInteger -> [EisensteinInteger]

-- | List of all Eisenstein units, counterclockwise across all sextants,
--   starting with <tt>1</tt>.
ids :: [EisensteinInteger]

-- | Find an Eisenstein integer whose norm is the given prime number in the
--   form <tt>3k + 1</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.Primes (nextPrime)
--   
--   &gt;&gt;&gt; findPrime (nextPrime 7)
--   Prime 3+2*ω
--   </pre>
findPrime :: Prime Integer -> Prime EisensteinInteger

-- | An infinite list of Eisenstein primes. Uses primes in <tt>Z</tt> to
--   exhaustively generate all Eisenstein primes in order of ascending
--   norm.
--   
--   <ul>
--   <li>Every prime is in the first sextant, so the list contains no
--   associates.</li>
--   <li>Eisenstein primes from the whole complex plane can be generated by
--   applying <a>associates</a> to each prime in this list.</li>
--   </ul>
--   
--   <pre>
--   &gt;&gt;&gt; take 10 primes
--   [Prime 2+ω,Prime 2,Prime 3+2*ω,Prime 3+ω,Prime 4+3*ω,Prime 4+ω,Prime 5+3*ω,Prime 5+2*ω,Prime 5,Prime 6+5*ω]
--   </pre>
primes :: Infinite (Prime EisensteinInteger)
instance GHC.Classes.Eq Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance Data.Euclidean.Euclidean Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance Data.Euclidean.GcdDomain Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance GHC.Internal.Generics.Generic Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance Control.DeepSeq.NFData Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance GHC.Internal.Num.Num Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance GHC.Classes.Ord Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance Data.Semiring.Ring Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance Data.Semiring.Semiring Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance GHC.Internal.Show.Show Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger
instance Math.NumberTheory.Primes.UniqueFactorisation Math.NumberTheory.Quadratic.EisensteinIntegers.EisensteinInteger


-- | Polynomial modular equations.
module Math.NumberTheory.Moduli.Equations

-- | Find all solutions of ax + b ≡ 0 (mod m).
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; solveLinear (6 :: Mod 10) 4 -- solving 6x + 4 ≡ 0 (mod 10)
--   [(1 `modulo` 10),(6 `modulo` 10)]
--   </pre>
solveLinear :: forall (m :: Nat). KnownNat m => Mod m -> Mod m -> [Mod m]

-- | Find all solutions of ax² + bx + c ≡ 0 (mod m).
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; solveQuadratic sfactors (1 :: Mod 32) 0 (-17) -- solving x² - 17 ≡ 0 (mod 32)
--   [(9 `modulo` 32),(25 `modulo` 32),(7 `modulo` 32),(23 `modulo` 32)]
--   </pre>
solveQuadratic :: forall (m :: Nat). SFactors Integer m -> Mod m -> Mod m -> Mod m -> [Mod m]


-- | Multiplicative groups of integers modulo m.
module Math.NumberTheory.Moduli.Multiplicative

-- | This type represents elements of the multiplicative group mod m, i.e.
--   those elements which are coprime to m. Use <tt>isMultElement</tt> to
--   construct.
data MultMod (m :: Nat)

-- | Unwrap a residue.
multElement :: MultMod m -> Mod m

-- | Attempt to construct a multiplicative group element.
isMultElement :: forall (m :: Nat). KnownNat m => Mod m -> Maybe (MultMod m)

-- | For elements of the multiplicative group, we can safely perform the
--   inverse without needing to worry about failure.
invertGroup :: forall (m :: Nat). KnownNat m => MultMod m -> MultMod m

-- | <a>PrimitiveRoot</a> m is a type which is only inhabited by
--   <a>primitive roots</a> of m.
data PrimitiveRoot (m :: Nat)

-- | Extract primitive root value.
unPrimitiveRoot :: PrimitiveRoot m -> MultMod m

-- | Check whether a given modular residue is a <a>primitive root</a>.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; import Data.Maybe
--   
--   &gt;&gt;&gt; isPrimitiveRoot (fromJust cyclicGroup) (1 :: Mod 13)
--   Nothing
--   
--   &gt;&gt;&gt; isPrimitiveRoot (fromJust cyclicGroup) (2 :: Mod 13)
--   Just (PrimitiveRoot {unPrimitiveRoot = MultMod {multElement = (2 `modulo` 13)}})
--   </pre>
isPrimitiveRoot :: forall a (m :: Nat). (Integral a, UniqueFactorisation a) => CyclicGroup a m -> Mod m -> Maybe (PrimitiveRoot m)

-- | Computes the discrete logarithm. Currently uses a combination of the
--   baby-step giant-step method and Pollard's rho algorithm, with Bach
--   reduction.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; import Data.Maybe
--   
--   &gt;&gt;&gt; let cg = fromJust cyclicGroup :: CyclicGroup Integer 13
--   
--   &gt;&gt;&gt; let rt = fromJust (isPrimitiveRoot cg 2)
--   
--   &gt;&gt;&gt; let x  = fromJust (isMultElement 11)
--   
--   &gt;&gt;&gt; discreteLogarithm cg rt x
--   7
--   </pre>
discreteLogarithm :: forall (m :: Nat). CyclicGroup Integer m -> PrimitiveRoot m -> MultMod m -> Natural
instance GHC.Internal.TypeNats.KnownNat m => GHC.Internal.Enum.Bounded (Math.NumberTheory.Moduli.Multiplicative.MultMod m)
instance GHC.Classes.Eq (Math.NumberTheory.Moduli.Multiplicative.MultMod m)
instance GHC.Classes.Eq (Math.NumberTheory.Moduli.Multiplicative.PrimitiveRoot m)
instance GHC.Internal.TypeNats.KnownNat m => GHC.Internal.Base.Monoid (Math.NumberTheory.Moduli.Multiplicative.MultMod m)
instance GHC.Classes.Ord (Math.NumberTheory.Moduli.Multiplicative.MultMod m)
instance GHC.Internal.TypeNats.KnownNat m => GHC.Internal.Base.Semigroup (Math.NumberTheory.Moduli.Multiplicative.MultMod m)
instance GHC.Internal.Show.Show (Math.NumberTheory.Moduli.Multiplicative.MultMod m)
instance GHC.Internal.Show.Show (Math.NumberTheory.Moduli.Multiplicative.PrimitiveRoot m)


-- | Safe modular arithmetic with modulo on type level.
module Math.NumberTheory.Moduli.Class

-- | This data type represents <a>integers modulo m</a>, equipped with
--   useful instances.
--   
--   For example, 3 :: <a>Mod</a> 10 stands for the class of integers
--   congruent to &lt;math&gt;
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; 3 + 8 :: Mod 10 -- 3 + 8 = 11 ≡ 1 (mod 10)
--   1
--   </pre>
--   
--   <b>Note:</b> <a>Mod</a> 0 has no inhabitants, eventhough &lt;math&gt;
--   is technically isomorphic to &lt;math&gt;.
data Mod (m :: Nat)

-- | The canonical representative of the residue class, always between 0
--   and m-1 inclusively.
getVal :: forall (m :: Nat). Mod m -> Integer

-- | The canonical representative of the residue class, always between 0
--   and m-1 inclusively.
getNatVal :: forall (m :: Nat). Mod m -> Natural

-- | Linking type and value levels: extract modulo <tt>m</tt> as a value.
getMod :: forall (m :: Nat). KnownNat m => Mod m -> Integer

-- | Linking type and value levels: extract modulo <tt>m</tt> as a value.
getNatMod :: forall (m :: Nat). KnownNat m => Mod m -> Natural

-- | If an argument is <a>coprime</a> with the modulus, return its modular
--   inverse. Otherwise return <a>Nothing</a>.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; invertMod 3 :: Mod 10 -- 3 * 7 = 21 ≡ 1 (mod 10)
--   Just 7
--   
--   &gt;&gt;&gt; invertMod 4 :: Mod 10 -- 4 and 10 are not coprime
--   Nothing
--   </pre>
invertMod :: forall (m :: Nat). KnownNat m => Mod m -> Maybe (Mod m)

-- | Synonym of <a>(^%)</a>.
powMod :: forall (m :: Nat) a. (KnownNat m, Integral a) => Mod m -> a -> Mod m

-- | Drop-in replacement for <a>^</a> with much better performance.
--   Negative powers are allowed, but may throw <a>DivideByZero</a>, if an
--   argument is not <a>coprime</a> with the modulus.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XDataKinds
--   
--   &gt;&gt;&gt; 3 ^% 4 :: Mod 10    -- 3 ^ 4 = 81 ≡ 1 (mod 10)
--   1
--   
--   &gt;&gt;&gt; 3 ^% (-1) :: Mod 10 -- 3 * 7 = 21 ≡ 1 (mod 10)
--   7
--   
--   &gt;&gt;&gt; 4 ^% (-1) :: Mod 10 -- 4 and 10 are not coprime
--   (*** Exception: divide by zero
--   </pre>
(^%) :: forall (m :: Nat) a. (KnownNat m, Integral a) => Mod m -> a -> Mod m
infixr 8 ^%

-- | This type represents elements of the multiplicative group mod m, i.e.
--   those elements which are coprime to m. Use <tt>isMultElement</tt> to
--   construct.
data MultMod (m :: Nat)

-- | Unwrap a residue.
multElement :: MultMod m -> Mod m

-- | Attempt to construct a multiplicative group element.
isMultElement :: forall (m :: Nat). KnownNat m => Mod m -> Maybe (MultMod m)

-- | For elements of the multiplicative group, we can safely perform the
--   inverse without needing to worry about failure.
invertGroup :: forall (m :: Nat). KnownNat m => MultMod m -> MultMod m

-- | This type represents residues with unknown modulo and rational
--   numbers. One can freely combine them in arithmetic expressions, but
--   each operation will spend time on modulo's recalculation:
--   
--   <pre>
--   &gt;&gt;&gt; 2 `modulo` 10 + 4 `modulo` 15
--   (1 `modulo` 5)
--   
--   &gt;&gt;&gt; (2 `modulo` 10) * (4 `modulo` 15)
--   (3 `modulo` 5)
--   
--   &gt;&gt;&gt; import Data.Ratio
--   
--   &gt;&gt;&gt; 2 `modulo` 10 + fromRational (3 % 7)
--   (1 `modulo` 10)
--   
--   &gt;&gt;&gt; 2 `modulo` 10 * fromRational (3 % 7)
--   (8 `modulo` 10)
--   </pre>
--   
--   If performance is crucial, it is recommended to extract <tt>Mod m</tt>
--   for further processing by pattern matching. E. g.,
--   
--   <pre>
--   case modulo n m of
--     SomeMod k -&gt; process k -- Here k has type Mod m
--     InfMod{}  -&gt; error "impossible"
--   </pre>
data SomeMod
[SomeMod] :: forall (m :: Nat). KnownNat m => Mod m -> SomeMod
[InfMod] :: Rational -> SomeMod

-- | Create modular value by representative of residue class and modulo.
--   One can use the result either directly (via functions from <a>Num</a>
--   and <a>Fractional</a>), or deconstruct it by pattern matching. Note
--   that <a>modulo</a> never returns <a>InfMod</a>.
modulo :: Integer -> Natural -> SomeMod
infixl 7 `modulo`

-- | Computes the inverse value, if it exists.
--   
--   <pre>
--   &gt;&gt;&gt; invertSomeMod (3 `modulo` 10) -- because 3 * 7 = 1 :: Mod 10
--   Just (7 `modulo` 10)
--   
--   &gt;&gt;&gt; invertSomeMod (4 `modulo` 10)
--   Nothing
--   
--   &gt;&gt;&gt; import Data.Ratio
--   
--   &gt;&gt;&gt; invertSomeMod (fromRational (2 % 5))
--   Just 5 % 2
--   </pre>
invertSomeMod :: SomeMod -> Maybe SomeMod

-- | Drop-in replacement for <a>^</a>, with much better performance. When
--   -O is enabled, there is a rewrite rule, which specialises <a>^</a> to
--   <a>powSomeMod</a>.
--   
--   <pre>
--   &gt;&gt;&gt; powSomeMod (3 `modulo` 10) 4
--   (1 `modulo` 10)
--   </pre>
powSomeMod :: Integral a => SomeMod -> a -> SomeMod

-- | This class gives the integer associated with a type-level natural.
--   There are instances of the class for every concrete literal: 0, 1, 2,
--   etc.
class KnownNat (n :: Nat)


-- | Miscellaneous functions related to modular arithmetic.
module Math.NumberTheory.Moduli


-- | <a>Cubic symbol</a> of two Eisenstein Integers.
module Math.NumberTheory.Moduli.Cbrt

-- | Represents the <a>cubic residue character</a> It is either <tt>0</tt>,
--   <tt>ω</tt>, <tt>ω²</tt> or <tt>1</tt>.
data CubicSymbol
Zero :: CubicSymbol
Omega :: CubicSymbol
OmegaSquare :: CubicSymbol
One :: CubicSymbol

-- | <a>Cubic symbol</a> of two Eisenstein Integers. The first argument is
--   the numerator and the second argument is the denominator. The latter
--   must be coprime to <tt>3</tt>. This condition is checked.
--   
--   If the arguments have a common factor, the result is <a>Zero</a>,
--   otherwise it is either <a>Omega</a>, <a>OmegaSquare</a> or <a>One</a>.
--   
--   <pre>
--   &gt;&gt;&gt; cubicSymbol (45 + 23*ω) (11 - 30*ω)
--   0
--   
--   &gt;&gt;&gt; cubicSymbol (31 - ω) (1 +10*ω)
--   ω
--   </pre>
cubicSymbol :: EisensteinInteger -> EisensteinInteger -> CubicSymbol

-- | Converts a <a>cubic symbol</a> to an Eisenstein Integer.
symbolToNum :: CubicSymbol -> EisensteinInteger
instance GHC.Classes.Eq Math.NumberTheory.Moduli.Cbrt.CubicSymbol
instance GHC.Internal.Base.Semigroup Math.NumberTheory.Moduli.Cbrt.CubicSymbol
instance GHC.Internal.Show.Show Math.NumberTheory.Moduli.Cbrt.CubicSymbol

module Math.NumberTheory.Diophantine

-- | Finds all primitive solutions (x,y) to the diophantine equation | x^2
--   + d*y^2 = m | when 1 &lt;= d &lt; m and gcd(d,m)=1 | Given m is square
--   free these are all the positive integer solutions
cornacchiaPrimitive :: Integer -> Integer -> [(Integer, Integer)]

-- | Finds all positive integer solutions (x,y) to the | diophantine
--   equation: | x^2 + d*y^2 = m | when 1 &lt;= d &lt; m and gcd(d,m)=1
cornacchia :: Integer -> Integer -> [(Integer, Integer)]


-- | N-free number generation.
module Math.NumberTheory.ArithmeticFunctions.NFreedom

-- | For a given nonnegative integer power <tt>n</tt>, generate all
--   <tt>n</tt>-free numbers in ascending order, starting at <tt>1</tt>.
--   
--   When <tt>n</tt> is <tt>0</tt> or <tt>1</tt>, the resulting list is
--   <tt>[1]</tt>.
nFrees :: (Integral a, Bits a, UniqueFactorisation a, Enum (Prime a)) => Word -> [a]

-- | Generate <tt>n</tt>-free numbers in a block starting at a certain
--   value. The length of the list is determined by the value passed in as
--   the third argument. It will be lesser than or equal to this value.
--   
--   This function should not be used with a negative lower bound. If it
--   is, the result is undefined.
--   
--   The block length cannot exceed <tt>maxBound :: Int</tt>, this
--   precondition is not checked.
--   
--   As with <tt>nFrees</tt>, passing <tt>n = 0, 1</tt> results in an empty
--   list.
nFreesBlock :: (Integral a, Bits a, UniqueFactorisation a, Enum (Prime a)) => Word -> a -> Word -> [a]

-- | Evaluate the <a>isNFree</a> function over a block. Value at
--   <tt>0</tt>, if zero falls into block, is undefined.
--   
--   This function should <b>**not**</b> be used with a negative lower
--   bound. If it is, the result is undefined. Furthermore, do not:
--   
--   <ul>
--   <li>use a block length greater than <tt>maxBound :: Int</tt>.</li>
--   <li>use a power that is either of <tt>0, 1</tt>.</li>
--   </ul>
--   
--   None of these preconditions are checked, and if any occurs, the result
--   is undefined, <b>if</b> the function terminates.
--   
--   <pre>
--   &gt;&gt;&gt; sieveBlockNFree 2 1 10
--   [True,True,True,False,True,True,True,False,False,True]
--   </pre>
sieveBlockNFree :: (Integral a, Enum (Prime a), Bits a, UniqueFactorisation a) => Word -> a -> Word -> Vector Bool


-- | Values of <a>Möbius function</a>.
module Math.NumberTheory.ArithmeticFunctions.Moebius

-- | Represents three possible values of <a>Möbius function</a>.
data Moebius

-- | <ul>
--   <li>1</li>
--   </ul>
MoebiusN :: Moebius

-- | 0
MoebiusZ :: Moebius

-- | 1
MoebiusP :: Moebius

-- | Convert to any numeric type.
runMoebius :: Num a => Moebius -> a

-- | Evaluate the Möbius function over a block. Value of <tt>f</tt> at 0,
--   if zero falls into block, is undefined.
--   
--   Based on the sieving algorithm from p. 3 of <a>Computations of the
--   Mertens function and improved bounds on the Mertens conjecture</a> by
--   G. Hurst. It is approximately 5x faster than <a>sieveBlockUnboxed</a>.
--   
--   <pre>
--   &gt;&gt;&gt; sieveBlockMoebius 1 10
--   [MoebiusP,MoebiusN,MoebiusN,MoebiusZ,MoebiusN,MoebiusP,MoebiusN,MoebiusZ,MoebiusZ,MoebiusP]
--   </pre>
sieveBlockMoebius :: Word -> Word -> Vector Moebius
instance GHC.Classes.Eq Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance Data.Vector.Generic.Mutable.Base.MVector Data.Vector.Unboxed.Base.MVector Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance GHC.Internal.Base.Monoid Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance GHC.Classes.Ord Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance GHC.Internal.Base.Semigroup Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance GHC.Internal.Show.Show Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance Data.Vector.Unboxed.Base.Unbox Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius
instance Data.Vector.Generic.Base.Vector Data.Vector.Unboxed.Base.Vector Math.NumberTheory.ArithmeticFunctions.Moebius.Moebius


-- | This module provides an interface for defining and manipulating
--   arithmetic functions. It also defines several most widespreaded
--   arithmetic functions.
module Math.NumberTheory.ArithmeticFunctions

-- | A typical arithmetic function operates on the canonical factorisation
--   of a number into prime's powers and consists of two rules. The first
--   one determines the values of the function on the powers of primes. The
--   second one determines how to combine these values into final result.
--   
--   In the following definition the first argument is the function on
--   prime's powers, the monoid instance determines a rule of combination
--   (typically <a>Product</a> or <a>Sum</a>), and the second argument is
--   convenient for unwrapping (typically, <a>getProduct</a> or
--   <a>getSum</a>).
data ArithmeticFunction n a
[ArithmeticFunction] :: forall m n a. Monoid m => (Prime n -> Word -> m) -> (m -> a) -> ArithmeticFunction n a

-- | Convert to a function. The value on 0 is undefined.
runFunction :: UniqueFactorisation n => ArithmeticFunction n a -> n -> a

-- | Convert to a function on prime factorisation.
runFunctionOnFactors :: ArithmeticFunction n a -> [(Prime n, Word)] -> a

-- | See <a>divisorsToA</a>.
divisorsTo :: (UniqueFactorisation n, Integral n) => n -> n -> Set n

-- | Represents three possible values of <a>Möbius function</a>.
data Moebius

-- | <ul>
--   <li>1</li>
--   </ul>
MoebiusN :: Moebius

-- | 0
MoebiusZ :: Moebius

-- | 1
MoebiusP :: Moebius

-- | For a given nonnegative integer power <tt>n</tt>, generate all
--   <tt>n</tt>-free numbers in ascending order, starting at <tt>1</tt>.
--   
--   When <tt>n</tt> is <tt>0</tt> or <tt>1</tt>, the resulting list is
--   <tt>[1]</tt>.
nFrees :: (Integral a, Bits a, UniqueFactorisation a, Enum (Prime a)) => Word -> [a]

-- | Generate <tt>n</tt>-free numbers in a block starting at a certain
--   value. The length of the list is determined by the value passed in as
--   the third argument. It will be lesser than or equal to this value.
--   
--   This function should not be used with a negative lower bound. If it
--   is, the result is undefined.
--   
--   The block length cannot exceed <tt>maxBound :: Int</tt>, this
--   precondition is not checked.
--   
--   As with <tt>nFrees</tt>, passing <tt>n = 0, 1</tt> results in an empty
--   list.
nFreesBlock :: (Integral a, Bits a, UniqueFactorisation a, Enum (Prime a)) => Word -> a -> Word -> [a]

-- | Convert to any numeric type.
runMoebius :: Num a => Moebius -> a

-- | See <a>totientA</a>.
totient :: UniqueFactorisation n => n -> n

-- | See <a>divisorsA</a>.
divisors :: (UniqueFactorisation n, Ord n) => n -> Set n

-- | The set of all (positive) divisors of an argument.
divisorsA :: (Ord n, Num n) => ArithmeticFunction n (Set n)

-- | See <a>divisorsListA</a>.
divisorsList :: UniqueFactorisation n => n -> [n]

-- | The unsorted list of all (positive) divisors of an argument, produced
--   in lazy fashion.
divisorsListA :: Num n => ArithmeticFunction n [n]

-- | See <a>divisorsSmallA</a>.
divisorsSmall :: Int -> IntSet

-- | Same as <a>divisors</a>, but with better performance on cost of type
--   restriction.
divisorsSmallA :: ArithmeticFunction Int IntSet

-- | The set of all (positive) divisors up to an inclusive bound.
divisorsToA :: (UniqueFactorisation n, Integral n) => n -> ArithmeticFunction n (Set n)

-- | Create a multiplicative function from the function on prime's powers.
--   See examples below.
multiplicative :: Num a => (Prime n -> Word -> a) -> ArithmeticFunction n a

-- | Synonym for <a>tau</a>.
--   
--   <pre>
--   &gt;&gt;&gt; map divisorCount [1..10]
--   [1,2,2,3,2,4,2,4,3,4]
--   </pre>
divisorCount :: (UniqueFactorisation n, Num a) => n -> a

-- | See <a>tauA</a>.
tau :: (UniqueFactorisation n, Num a) => n -> a

-- | The number of (positive) divisors of an argument.
--   
--   <pre>
--   tauA = multiplicative (\_ k -&gt; k + 1)
--   </pre>
tauA :: Num a => ArithmeticFunction n a

-- | See <a>sigmaA</a>.
sigma :: (UniqueFactorisation n, Integral n, Num a, GcdDomain a) => Word -> n -> a

-- | The sum of the <tt>k</tt>-th powers of (positive) divisors of an
--   argument.
--   
--   <pre>
--   sigmaA = multiplicative (\p k -&gt; sum $ map (p ^) [0..k])
--   sigmaA 0 = tauA
--   </pre>
sigmaA :: (Integral n, Num a, GcdDomain a) => Word -> ArithmeticFunction n a

-- | Calculates the totient of a positive number <tt>n</tt>, i.e. the
--   number of <tt>k</tt> with <tt>1 &lt;= k &lt;= n</tt> and
--   <tt><a>gcd</a> n k == 1</tt>, in other words, the order of the group
--   of units in <tt>ℤ/(n)</tt>.
totientA :: Num n => ArithmeticFunction n n

-- | See <a>jordanA</a>.
jordan :: UniqueFactorisation n => Word -> n -> n

-- | Calculates the k-th Jordan function of an argument.
--   
--   <pre>
--   jordanA 1 = totientA
--   </pre>
jordanA :: Num n => Word -> ArithmeticFunction n n

-- | See <a>ramanujanA</a>.
ramanujan :: Integer -> Integer

-- | Calculates the <a>Ramanujan tau function</a> of a positive number
--   <tt>n</tt>, using formulas given <a>here</a>
ramanujanA :: ArithmeticFunction Integer Integer

-- | See <a>moebiusA</a>.
moebius :: UniqueFactorisation n => n -> Moebius

-- | Calculates the Möbius function of an argument.
moebiusA :: ArithmeticFunction n Moebius

-- | See <a>liouvilleA</a>.
liouville :: (UniqueFactorisation n, Num a) => n -> a

-- | Calculates the Liouville function of an argument.
liouvilleA :: Num a => ArithmeticFunction n a

-- | Create an additive function from the function on prime's powers. See
--   examples below.
additive :: Num a => (Prime n -> Word -> a) -> ArithmeticFunction n a

-- | See <a>smallOmegaA</a>.
smallOmega :: (UniqueFactorisation n, Num a) => n -> a

-- | Number of distinct prime factors.
--   
--   <pre>
--   smallOmegaA = additive (\_ _ -&gt; 1)
--   </pre>
smallOmegaA :: Num a => ArithmeticFunction n a

-- | See <a>bigOmegaA</a>.
bigOmega :: UniqueFactorisation n => n -> Word

-- | Number of prime factors, counted with multiplicity.
--   
--   <pre>
--   bigOmegaA = additive (\_ k -&gt; k)
--   </pre>
bigOmegaA :: ArithmeticFunction n Word

-- | See <a>carmichaelA</a>.
carmichael :: (UniqueFactorisation n, Integral n) => n -> n

-- | Calculates the Carmichael function for a positive integer, that is,
--   the (smallest) exponent of the group of units in <tt>ℤ/(n)</tt>.
carmichaelA :: Integral n => ArithmeticFunction n n

-- | See <a>expMangoldtA</a>.
expMangoldt :: UniqueFactorisation n => n -> n

-- | The exponent of von Mangoldt function. Use <tt>log expMangoldtA</tt>
--   to recover von Mangoldt function itself.
expMangoldtA :: Num n => ArithmeticFunction n n

-- | See <a>isNFreeA</a>.
isNFree :: UniqueFactorisation n => Word -> n -> Bool

-- | Check if an integer is <tt>n</tt>-free. An integer <tt>x</tt> is
--   <tt>n</tt>-free if in its factorisation into prime factors, no factor
--   has an exponent larger than or equal to <tt>n</tt>.
isNFreeA :: Word -> ArithmeticFunction n Bool


-- | Implementation and enumeration of Dirichlet characters.
module Math.NumberTheory.DirichletCharacters

-- | Similar to Maybe, but with different Semigroup and Monoid instances.
type OrZero a = Ap Maybe a

-- | <a>Ap</a> <a>Nothing</a>
pattern Zero :: OrZero a

-- | <a>Ap</a> (<a>Just</a> x)
pattern NonZero :: a -> OrZero a

-- | Interpret an <a>OrZero</a> as a number, taking the <a>Zero</a> case to
--   be 0.
orZeroToNum :: Num a => (b -> a) -> OrZero b -> a

-- | A Dirichlet character mod &lt;math&gt; is a group homomorphism from
--   &lt;math&gt; to &lt;math&gt;, represented abstractly by
--   <a>DirichletCharacter</a>. In particular, they take values at roots of
--   unity and can be evaluated using <a>eval</a>. A Dirichlet character
--   can be extended to a completely multiplicative function on
--   &lt;math&gt; by assigning the value 0 for &lt;math&gt; sharing a
--   common factor with &lt;math&gt;, using <a>evalGeneral</a>.
--   
--   There are finitely many possible Dirichlet characters for a given
--   modulus, in particular there are &lt;math&gt; characters modulo
--   &lt;math&gt;, where &lt;math&gt; refers to Euler's <a>totient</a>
--   function. This gives rise to <a>Enum</a> and <a>Bounded</a> instances.
data DirichletCharacter (n :: Nat)

-- | Give the dirichlet character from its number. Inverse of
--   <a>characterNumber</a>.
indexToChar :: forall (n :: Nat). KnownNat n => Natural -> DirichletCharacter n

-- | Give a collection of dirichlet characters from their numbers. This may
--   be more efficient than <a>indexToChar</a> for multiple characters, as
--   it prevents some internal recalculations.
indicesToChars :: forall (n :: Nat) f. (KnownNat n, Functor f) => f Natural -> f (DirichletCharacter n)

-- | We have a (non-canonical) enumeration of dirichlet characters.
characterNumber :: forall (n :: Nat). DirichletCharacter n -> Integer

-- | List all characters for the modulus. This is preferred to using
--   <tt>[minBound..maxBound]</tt>.
allChars :: forall (n :: Nat). KnownNat n => [DirichletCharacter n]

-- | Attempt to construct a character from its table of values. An inverse
--   to <a>evalAll</a>, defined only on its image.
fromTable :: forall (n :: Nat). KnownNat n => Vector (OrZero RootOfUnity) -> Maybe (DirichletCharacter n)

-- | For elements of the multiplicative group &lt;math&gt;, a Dirichlet
--   character evaluates to a root of unity.
eval :: forall (n :: Nat). DirichletCharacter n -> MultMod n -> RootOfUnity

-- | A character can evaluate to a root of unity or zero: represented by
--   <tt>Nothing</tt>.
evalGeneral :: forall (n :: Nat). KnownNat n => DirichletCharacter n -> Mod n -> OrZero RootOfUnity

-- | In general, evaluating a DirichletCharacter at a point involves
--   solving the discrete logarithm problem, which can be hard: the
--   implementations here are around O(sqrt n). However, evaluating a
--   dirichlet character at every point amounts to solving the discrete
--   logarithm problem at every point also, which can be done together in
--   O(n) time, better than using a complex algorithm at each point
--   separately. Thus, if a large number of evaluations of a dirichlet
--   character are required, <a>evalAll</a> will be better than
--   <a>evalGeneral</a>, since computations can be shared.
evalAll :: forall (n :: Nat). KnownNat n => DirichletCharacter n -> Vector (OrZero RootOfUnity)

-- | Give the principal character for this modulus: a principal character
--   mod &lt;math&gt; is 1 for &lt;math&gt; coprime to &lt;math&gt;, and 0
--   otherwise.
principalChar :: forall (n :: Nat). KnownNat n => DirichletCharacter n

-- | Test if a given Dirichlet character is prinicpal for its modulus: a
--   principal character mod &lt;math&gt; is 1 for &lt;math&gt; coprime to
--   &lt;math&gt;, and 0 otherwise.
isPrincipal :: forall (n :: Nat). DirichletCharacter n -> Bool

-- | Get the order of the Dirichlet Character.
orderChar :: forall (n :: Nat). DirichletCharacter n -> Integer

-- | A Dirichlet character is real if it is real-valued.
data RealCharacter (n :: Nat)

-- | Test if a given <a>DirichletCharacter</a> is real, and if so give a
--   <a>RealCharacter</a>.
isRealCharacter :: forall (n :: Nat). DirichletCharacter n -> Maybe (RealCharacter n)

-- | Extract the character itself from a <a>RealCharacter</a>.
getRealChar :: RealCharacter n -> DirichletCharacter n

-- | Evaluate a real Dirichlet character, which can only take values
--   &lt;math&gt;.
toRealFunction :: forall (n :: Nat). KnownNat n => RealCharacter n -> Mod n -> Int

-- | The <a>Jacobi symbol</a> gives a real Dirichlet character for odd
--   moduli.
jacobiCharacter :: forall (n :: Nat). KnownNat n => Maybe (RealCharacter n)

-- | A Dirichlet character is primitive if cannot be <a>induced</a> from
--   any character with strictly smaller modulus.
data PrimitiveCharacter (n :: Nat)

-- | Test if a Dirichlet character is <a>primitive</a>.
isPrimitive :: forall (n :: Nat). DirichletCharacter n -> Maybe (PrimitiveCharacter n)

-- | Extract the character itself from a <a>PrimitiveCharacter</a>.
getPrimitiveChar :: PrimitiveCharacter n -> DirichletCharacter n

-- | Induce a Dirichlet character to a higher modulus. If &lt;math&gt;,
--   then &lt;math&gt; can be reduced to &lt;math&gt;. Thus, the
--   multiplicative function on &lt;math&gt; induces a multiplicative
--   function on &lt;math&gt;.
--   
--   <pre>
--   &gt;&gt;&gt; :set -XTypeApplications -XDataKinds
--   
--   &gt;&gt;&gt; chi = indexToChar 5 :: DirichletCharacter 45
--   
--   &gt;&gt;&gt; chi2 = induced @135 chi :: Maybe (DirichletCharacter 135)
--   </pre>
induced :: forall (n :: Nat) (d :: Nat). (KnownNat d, KnownNat n) => DirichletCharacter d -> Maybe (DirichletCharacter n)

-- | This function also provides access to the new modulus on type level,
--   with a KnownNat instance
makePrimitive :: forall (n :: Nat). DirichletCharacter n -> WithNat PrimitiveCharacter

-- | Wrapper to hide an unknown type-level natural.
data WithNat (a :: Nat -> Type)
[WithNat] :: forall (m :: Nat) (a :: Nat -> Type). KnownNat m => a m -> WithNat a

-- | A representation of <a>roots of unity</a>: complex numbers
--   &lt;math&gt; for which there is &lt;math&gt; such that &lt;math&gt;.
newtype RootOfUnity
RootOfUnity :: Rational -> RootOfUnity

-- | Every root of unity can be expressed as &lt;math&gt; for some rational
--   &lt;math&gt; satisfying &lt;math&gt;, this function extracts it.
[fromRootOfUnity] :: RootOfUnity -> Rational

-- | Given a rational &lt;math&gt;, produce the root of unity &lt;math&gt;.
toRootOfUnity :: Rational -> RootOfUnity

-- | Convert a root of unity into an inexact complex number. Due to
--   floating point inaccuracies, it is recommended to avoid use of this
--   until the end of a calculation. Alternatively, with the
--   <a>cyclotomic</a> package, one can use <tt><a>polarRat</a> 1 .
--   </tt><a>fromRootOfUnity</a> to convert to a cyclotomic number.
toComplex :: Floating a => RootOfUnity -> Complex a

-- | Test if the internal DirichletCharacter structure is valid.
validChar :: forall (n :: Nat). KnownNat n => DirichletCharacter n -> Bool
instance GHC.Internal.TypeNats.KnownNat n => GHC.Internal.Enum.Bounded (Math.NumberTheory.DirichletCharacters.DirichletCharacter n)
instance GHC.Internal.TypeNats.KnownNat n => GHC.Internal.Enum.Enum (Math.NumberTheory.DirichletCharacters.DirichletCharacter n)
instance GHC.Classes.Eq (Math.NumberTheory.DirichletCharacters.DirichletCharacter n)
instance GHC.Classes.Eq Math.NumberTheory.DirichletCharacters.DirichletFactor
instance GHC.Classes.Eq (Math.NumberTheory.DirichletCharacters.PrimitiveCharacter n)
instance GHC.Classes.Eq (Math.NumberTheory.DirichletCharacters.RealCharacter n)
instance GHC.Internal.TypeNats.KnownNat n => GHC.Internal.Base.Monoid (Math.NumberTheory.DirichletCharacters.DirichletCharacter n)
instance GHC.Internal.Base.Semigroup (Math.NumberTheory.DirichletCharacters.DirichletCharacter n)


-- | Bulk evaluation of arithmetic functions over continuous intervals
--   without factorisation.
module Math.NumberTheory.ArithmeticFunctions.SieveBlock

-- | <a>runFunctionOverBlock</a> <tt>f</tt> <tt>x</tt> <tt>l</tt> evaluates
--   an arithmetic function for integers between <tt>x</tt> and
--   <tt>x+l-1</tt> and returns a vector of length <tt>l</tt>. It
--   completely avoids factorisation, so it is asymptotically faster than
--   pointwise evaluation of <tt>f</tt>.
--   
--   Value of <tt>f</tt> at 0, if zero falls into block, is undefined.
--   
--   Beware that for underlying non-commutative monoids the results may
--   potentially differ from pointwise application via <a>runFunction</a>.
--   
--   This is a thin wrapper over <a>sieveBlock</a>, read more details
--   there.
--   
--   <pre>
--   &gt;&gt;&gt; import Math.NumberTheory.ArithmeticFunctions
--   
--   &gt;&gt;&gt; runFunctionOverBlock carmichaelA 1 10
--   [1,1,2,2,4,2,6,2,6,4]
--   </pre>
runFunctionOverBlock :: ArithmeticFunction Word a -> Word -> Word -> Vector a

-- | A record, which specifies a function to evaluate over a block.
--   
--   For example, here is a configuration for the totient function:
--   
--   <pre>
--   SieveBlockConfig
--     { sbcEmpty                = 1
--     , sbcFunctionOnPrimePower = \p a -&gt; (unPrime p - 1) * unPrime p ^ (a - 1)
--     , sbcAppend               = (*)
--     }
--   </pre>
data SieveBlockConfig a
SieveBlockConfig :: a -> (Prime Word -> Word -> a) -> (a -> a -> a) -> SieveBlockConfig a

-- | value of a function on 1
[sbcEmpty] :: SieveBlockConfig a -> a

-- | how to evaluate a function on prime powers
[sbcFunctionOnPrimePower] :: SieveBlockConfig a -> Prime Word -> Word -> a

-- | how to combine values of a function on coprime arguments
[sbcAppend] :: SieveBlockConfig a -> a -> a -> a

-- | Create a config for a multiplicative function from its definition on
--   prime powers.
multiplicativeSieveBlockConfig :: Num a => (Prime Word -> Word -> a) -> SieveBlockConfig a

-- | Create a config for an additive function from its definition on prime
--   powers.
additiveSieveBlockConfig :: Num a => (Prime Word -> Word -> a) -> SieveBlockConfig a

-- | Evaluate a function over a block in accordance to provided
--   configuration. Value of <tt>f</tt> at 0, if zero falls into block, is
--   undefined.
--   
--   Based on Algorithm M of <a>Parity of the number of primes in a given
--   interval and algorithms of the sublinear summation</a> by A. V.
--   Lelechenko. See Lemma 2 on p. 5 on its algorithmic complexity. For the
--   majority of use-cases its time complexity is O(x^(1+ε)).
--   
--   For example, following code lists smallest prime factors:
--   
--   <pre>
--   &gt;&gt;&gt; sieveBlock (SieveBlockConfig maxBound (\p _ -&gt; unPrime p) min) 2 10 :: Data.Vector.Vector Word
--   [2,3,2,5,2,7,2,3,2,11]
--   </pre>
--   
--   And this is how to factorise all numbers in a block:
--   
--   <pre>
--   &gt;&gt;&gt; sieveBlock (SieveBlockConfig [] (\p k -&gt; [(unPrime p, k)]) (++)) 2 10 :: Data.Vector.Vector [(Word, Word)]
--   [[(2,1)],[(3,1)],[(2,2)],[(5,1)],[(2,1),(3,1)],[(7,1)],[(2,3)],[(3,2)],[(2,1),(5,1)],[(11,1)]]
--   </pre>
sieveBlock :: Vector v a => SieveBlockConfig a -> Word -> Word -> v a

-- | This is <a>sieveBlock</a> specialized to unboxed vectors.
--   
--   <pre>
--   &gt;&gt;&gt; sieveBlockUnboxed (SieveBlockConfig 1 (\_ a -&gt; a + 1) (*)) 1 10
--   [1,2,2,3,2,4,2,4,3,4]
--   </pre>
sieveBlockUnboxed :: Unbox a => SieveBlockConfig a -> Word -> Word -> Vector a

-- | Evaluate the Möbius function over a block. Value of <tt>f</tt> at 0,
--   if zero falls into block, is undefined.
--   
--   Based on the sieving algorithm from p. 3 of <a>Computations of the
--   Mertens function and improved bounds on the Mertens conjecture</a> by
--   G. Hurst. It is approximately 5x faster than <a>sieveBlockUnboxed</a>.
--   
--   <pre>
--   &gt;&gt;&gt; sieveBlockMoebius 1 10
--   [MoebiusP,MoebiusN,MoebiusN,MoebiusZ,MoebiusN,MoebiusP,MoebiusN,MoebiusZ,MoebiusZ,MoebiusP]
--   </pre>
sieveBlockMoebius :: Word -> Word -> Vector Moebius


-- | Values of <a>Mertens function</a>.
module Math.NumberTheory.ArithmeticFunctions.Mertens

-- | Compute individual values of Mertens function in O(n^(2/3)) time and
--   space.
--   
--   <pre>
--   &gt;&gt;&gt; map (mertens . (10 ^)) [0..9]
--   [1,-1,1,2,-23,-48,212,1037,1928,-222]
--   </pre>
--   
--   The implementation follows Theorem 3.1 from <a>Computations of the
--   Mertens function and improved bounds on the Mertens conjecture</a> by
--   G. Hurst, excluding segmentation of sieves.
mertens :: Word -> Int


-- | Computing inverses of multiplicative functions. The implementation is
--   based on <a>Computing the Inverses, their Power Sums, and Extrema for
--   Euler’s Totient and Other Multiplicative Functions</a> by M. A.
--   Alekseyev.
module Math.NumberTheory.ArithmeticFunctions.Inverse

-- | The inverse for <a>totient</a> function.
--   
--   The return value is parameterized by a <a>Semiring</a>, which allows
--   various applications by providing different (multiplicative)
--   embeddings. E. g., list all preimages (see a helper
--   <a>asSetOfPreimages</a>):
--   
--   <pre>
--   &gt;&gt;&gt; import qualified Data.Set as S
--   
--   &gt;&gt;&gt; import Data.Semigroup
--   
--   &gt;&gt;&gt; S.mapMonotonic getProduct (inverseTotient (S.singleton . Product) 120)
--   fromList [143,155,175,183,225,231,244,248,286,308,310,350,366,372,396,450,462]
--   </pre>
--   
--   Count preimages:
--   
--   <pre>
--   &gt;&gt;&gt; inverseTotient (const 1) 120
--   17
--   </pre>
--   
--   Sum preimages:
--   
--   <pre>
--   &gt;&gt;&gt; inverseTotient id 120
--   4904
--   </pre>
--   
--   Find minimal and maximal preimages:
--   
--   <pre>
--   &gt;&gt;&gt; unMinWord (inverseTotient MinWord 120)
--   143
--   
--   &gt;&gt;&gt; unMaxWord (inverseTotient MaxWord 120)
--   462
--   </pre>
inverseTotient :: (Semiring b, Integral a, Euclidean a, UniqueFactorisation a) => (a -> b) -> a -> b

-- | The inverse for <a>jordan</a> function.
--   
--   Generalizes the <a>inverseTotient</a> function, which is
--   <a>inverseJordan</a> 1.
--   
--   The return value is parameterized by a <a>Semiring</a>, which allows
--   various applications by providing different (multiplicative)
--   embeddings. E. g., list all preimages (see a helper
--   <a>asSetOfPreimages</a>):
--   
--   <pre>
--   &gt;&gt;&gt; import qualified Data.Set as S
--   
--   &gt;&gt;&gt; import Data.Semigroup
--   
--   &gt;&gt;&gt; S.mapMonotonic getProduct (inverseJordan 2 (S.singleton . Product) 192)
--   fromList [15,16]
--   </pre>
--   
--   Similarly to <a>inverseTotient</a>, it is possible to count and sum
--   preimages, or get the maximum/minimum preimage.
--   
--   Note: it is the <b>user's responsibility</b> to use an appropriate
--   type for <a>inverseSigmaK</a>. Even low values of k with <a>Int</a> or
--   <a>Word</a> will return invalid results due to over/underflow, or
--   throw exceptions (i.e. division by zero).
--   
--   <pre>
--   &gt;&gt;&gt; asSetOfPreimages (inverseJordan 15) (jordan 15 19) :: S.Set Int
--   fromList []
--   </pre>
--   
--   <pre>
--   &gt;&gt;&gt; asSetOfPreimages (inverseJordan 15) (jordan 15 19) :: S.Set Integer
--   fromList [19]
--   </pre>
inverseJordan :: (Semiring b, Integral a, Euclidean a, UniqueFactorisation a) => Word -> (a -> b) -> a -> b

-- | The inverse for <a>sigma</a> 1 function.
--   
--   The return value is parameterized by a <a>Semiring</a>, which allows
--   various applications by providing different (multiplicative)
--   embeddings. E. g., list all preimages (see a helper
--   <a>asSetOfPreimages</a>):
--   
--   <pre>
--   &gt;&gt;&gt; import qualified Data.Set as S
--   
--   &gt;&gt;&gt; import Data.Semigroup
--   
--   &gt;&gt;&gt; :set -XFlexibleContexts
--   
--   &gt;&gt;&gt; S.mapMonotonic getProduct (inverseSigma (S.singleton . Product) 120)
--   fromList [54,56,87,95]
--   </pre>
--   
--   Count preimages:
--   
--   <pre>
--   &gt;&gt;&gt; inverseSigma (const 1) 120
--   4
--   </pre>
--   
--   Sum preimages:
--   
--   <pre>
--   &gt;&gt;&gt; inverseSigma id 120
--   292
--   </pre>
--   
--   Find minimal and maximal preimages:
--   
--   <pre>
--   &gt;&gt;&gt; unMinWord (inverseSigma MinWord 120)
--   54
--   
--   &gt;&gt;&gt; unMaxWord (inverseSigma MaxWord 120)
--   95
--   </pre>
inverseSigma :: (Semiring b, Euclidean a, UniqueFactorisation a, Integral a, Enum (Prime a), Bits a) => (a -> b) -> a -> b

-- | The inverse for <a>sigma</a> function.
--   
--   Generalizes the <a>inverseSigma</a> function, which is
--   <a>inverseSigmaK</a> 1.
--   
--   The return value is parameterized by a <a>Semiring</a>, which allows
--   various applications by providing different (multiplicative)
--   embeddings. E. g., list all preimages (see a helper
--   <a>asSetOfPreimages</a>):
--   
--   <pre>
--   &gt;&gt;&gt; import qualified Data.Set as S
--   
--   &gt;&gt;&gt; import Data.Semigroup
--   
--   &gt;&gt;&gt; :set -XFlexibleContexts
--   
--   &gt;&gt;&gt; S.mapMonotonic getProduct (inverseSigmaK 2 (S.singleton . Product) 850)
--   fromList [24,26]
--   </pre>
--   
--   Similarly to <a>inverseSigma</a>, it is possible to count and sum
--   preimages, or get the maximum/minimum preimage.
--   
--   Note: it is the <b>user's responsibility</b> to use an appropriate
--   type for <a>inverseSigmaK</a>. Even low values of k with <a>Int</a> or
--   <a>Word</a> will return invalid results due to over/underflow, or
--   throw exceptions (i.e. division by zero).
--   
--   <pre>
--   &gt;&gt;&gt; asSetOfPreimages (inverseSigmaK 17) (sigma 17 13) :: S.Set Int
--   fromList *** Exception: divide by zero
--   </pre>
inverseSigmaK :: (Semiring b, Euclidean a, UniqueFactorisation a, Integral a, Enum (Prime a), Bits a) => Word -> (a -> b) -> a -> b

-- | Wrapper to use in conjunction with <a>inverseTotient</a> and
--   <a>inverseSigma</a>. Extracts the minimal preimage of function.
newtype MinWord
MinWord :: Word -> MinWord
[unMinWord] :: MinWord -> Word

-- | Wrapper to use in conjunction with <a>inverseTotient</a> and
--   <a>inverseSigma</a>. Extracts the maximal preimage of function.
newtype MaxWord
MaxWord :: Word -> MaxWord
[unMaxWord] :: MaxWord -> Word

-- | Wrapper to use in conjunction with <a>inverseTotient</a> and
--   <a>inverseSigma</a>. Extracts the minimal preimage of function.
data MinNatural
MinNatural :: !Natural -> MinNatural
[unMinNatural] :: MinNatural -> !Natural
Infinity :: MinNatural

-- | Wrapper to use in conjunction with <a>inverseTotient</a> and
--   <a>inverseSigma</a>. Extracts the maximal preimage of function.
newtype MaxNatural
MaxNatural :: Natural -> MaxNatural
[unMaxNatural] :: MaxNatural -> Natural

-- | Helper to extract a set of preimages for <a>inverseTotient</a> or
--   <a>inverseSigma</a>.
asSetOfPreimages :: (Ord a, Semiring a) => (forall b. Semiring b => (a -> b) -> a -> b) -> a -> Set a
instance GHC.Classes.Eq Math.NumberTheory.ArithmeticFunctions.Inverse.MaxNatural
instance GHC.Classes.Eq Math.NumberTheory.ArithmeticFunctions.Inverse.MaxWord
instance GHC.Classes.Eq Math.NumberTheory.ArithmeticFunctions.Inverse.MinNatural
instance GHC.Classes.Eq Math.NumberTheory.ArithmeticFunctions.Inverse.MinWord
instance GHC.Classes.Ord Math.NumberTheory.ArithmeticFunctions.Inverse.MaxNatural
instance GHC.Classes.Ord Math.NumberTheory.ArithmeticFunctions.Inverse.MaxWord
instance GHC.Classes.Ord Math.NumberTheory.ArithmeticFunctions.Inverse.MinNatural
instance GHC.Classes.Ord Math.NumberTheory.ArithmeticFunctions.Inverse.MinWord
instance Data.Semiring.Semiring Math.NumberTheory.ArithmeticFunctions.Inverse.MaxNatural
instance Data.Semiring.Semiring Math.NumberTheory.ArithmeticFunctions.Inverse.MaxWord
instance Data.Semiring.Semiring Math.NumberTheory.ArithmeticFunctions.Inverse.MinNatural
instance Data.Semiring.Semiring Math.NumberTheory.ArithmeticFunctions.Inverse.MinWord
instance GHC.Internal.Show.Show Math.NumberTheory.ArithmeticFunctions.Inverse.MaxNatural
instance GHC.Internal.Show.Show Math.NumberTheory.ArithmeticFunctions.Inverse.MaxWord
instance GHC.Internal.Show.Show Math.NumberTheory.ArithmeticFunctions.Inverse.MinNatural
instance GHC.Internal.Show.Show Math.NumberTheory.ArithmeticFunctions.Inverse.MinWord
instance GHC.Internal.Show.Show a => GHC.Internal.Show.Show (Math.NumberTheory.ArithmeticFunctions.Inverse.PrimePowers a)


-- | Numeric evaluation of various zeta-functions.
module Math.NumberTheory.Zeta

-- | Infinite sequence of approximate (up to given precision) values of
--   Riemann zeta-function at integer arguments, starting with
--   <tt>ζ(0)</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (zetas 1e-14) :: [Double]
--   [-0.5,Infinity,1.6449340668482264,1.2020569031595942,1.0823232337111381]
--   </pre>
--   
--   Beware to force evaluation of <tt>zetas !! 1</tt> if the type
--   <tt>a</tt> does not support infinite values (for instance,
--   <a>Fixed</a>).
zetas :: (Floating a, Ord a) => a -> Infinite a

-- | Infinite sequence of exact values of Riemann zeta-function at even
--   arguments, starting with <tt>ζ(0)</tt>. Note that due to numerical
--   errors conversion to <a>Double</a> may return values below 1:
--   
--   <pre>
--   &gt;&gt;&gt; approximateValue (zetasEven !! 25) :: Double
--   0.9999999999999996
--   </pre>
--   
--   Use your favorite type for long-precision arithmetic. For instance,
--   <a>Fixed</a> works fine:
--   
--   <pre>
--   &gt;&gt;&gt; import Data.Number.Fixed
--   
--   &gt;&gt;&gt; approximateValue (zetasEven !! 25) :: Fixed Prec50
--   1.00000000000000088817842111574532859293035196051773
--   </pre>
zetasEven :: Infinite ExactPi

-- | Infinite sequence of approximate (up to given precision) values of
--   Dirichlet beta-function at integer arguments, starting with
--   <tt>β(0)</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; take 5 (betas 1e-14) :: [Double]
--   [0.5,0.7853981633974483,0.9159655941772189,0.9689461462593694,0.9889445517411051]
--   </pre>
betas :: (Floating a, Ord a) => a -> Infinite a

-- | Infinite sequence of exact values of Dirichlet beta-function at odd
--   arguments, starting with <tt>β(1)</tt>.
--   
--   <pre>
--   &gt;&gt;&gt; import Data.ExactPi
--   
--   &gt;&gt;&gt; approximateValue (betasOdd !! 25) :: Double
--   0.9999999999999987
--   
--   &gt;&gt;&gt; import Data.Number.Fixed
--   
--   &gt;&gt;&gt; approximateValue (betasOdd !! 25) :: Fixed Prec50
--   0.99999999999999999999999960726927497384196726751694
--   </pre>
betasOdd :: Infinite ExactPi

-- | Values of Hurwitz zeta function evaluated at <tt>ζ(s, a)</tt> for
--   <tt>s ∈ [0, 1 ..]</tt>.
--   
--   The algorithm used was based on the Euler-Maclaurin formula and was
--   derived from <a>Fast and Rigorous Computation of Special Functions to
--   High Precision</a> by F. Johansson, chapter 4.8, formula 4.8.5. The
--   error for each value in this recurrence is given in formula 4.8.9 as
--   an indefinite integral, and in formula 4.8.12 as a closed form
--   formula.
--   
--   It is the <b>user's responsibility</b> to provide an appropriate
--   precision for the type chosen.
--   
--   For instance, when using <tt>Double</tt>s, it does not make sense to
--   provide a number <tt>ε &lt; 1e-53</tt> as the desired precision. For
--   <tt>Float</tt>s, providing an <tt>ε &lt; 1e-24</tt> also does not make
--   sense. Example of how to call the function:
--   
--   <pre>
--   &gt;&gt;&gt; zetaHurwitz 1e-15 0.25 !! 5
--   1024.3489745265808
--   </pre>
zetaHurwitz :: (Floating a, Ord a) => a -> a -> Infinite a
