fast-arithmetic-0.6.5.0: src/Numeric/NumberTheory.hs
{-|
Module : Numeric.NumberTheory
Copyright : Copyright (c) 2018 Vanessa McHale
This module provides fast number theoretic functions.
-}
module Numeric.NumberTheory ( totient
, tau
, littleOmega
, isPerfect
, sumDivisors
, isPrime
, radical
, isSemiprime
) where
import Foreign.C
import Numeric.Common
foreign import ccall unsafe totient_ats :: CInt -> CInt
foreign import ccall unsafe count_divisors_ats :: CInt -> CInt
foreign import ccall unsafe sum_divisors_ats :: CInt -> CInt
foreign import ccall unsafe little_omega_ats :: CInt -> CInt
foreign import ccall unsafe is_perfect_ats :: CInt -> CBool
foreign import ccall unsafe is_prime_ats :: CInt -> CBool
foreign import ccall unsafe is_semiprime_ats :: CInt -> CBool
foreign import ccall unsafe radical_ats :: CInt -> CInt
-- | Radical of an integer
--
-- \( \text{rad}(n) = \displaystyle\prod_{p | n} p \)
radical :: Int -> Int
radical = conjugate radical_ats
-- | \( O(\sqrt(n)) \)
isPrime :: Int -> Bool
isPrime = asTest is_prime_ats
-- | @since 0.6.5.0
isSemiprime :: Int -> Bool
isSemiprime = asTest is_semiprime_ats
-- | See [here](http://mathworld.wolfram.com/PerfectNumber.html)
isPerfect :: Int -> Bool
isPerfect = asTest is_perfect_ats
-- | Sum of proper divisors. May overflow.
sumDivisors :: Int -> Int
sumDivisors = conjugate sum_divisors_ats
-- | Number of distinct prime factors
littleOmega :: Int -> Int
littleOmega = conjugate little_omega_ats
-- | Number of distinct divisors.
tau :: Int -> Int
tau = conjugate count_divisors_ats
-- | Euler totient function.
totient :: Int -> Int
totient = conjugate totient_ats