Copyright | (c) 2018 Andrew Lelechenko |
---|---|
License | MIT |
Maintainer | Andrew Lelechenko <andrew.lelechenko@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Computing inverses of multiplicative functions. The implementation is based on Computing the Inverses, their Power Sums, and Extrema for Euler’s Totient and Other Multiplicative Functions by M. A. Alekseyev.
Synopsis
- inverseTotient :: (Semiring b, Euclidean a, UniqueFactorisation a, Ord a) => (a -> b) -> a -> b
- inverseSigma :: (Semiring b, Euclidean a, UniqueFactorisation a, Integral a) => (a -> b) -> a -> b
- newtype MinWord = MinWord {}
- newtype MaxWord = MaxWord {}
- data MinNatural
- = MinNatural {
- unMinNatural :: !Natural
- | Infinity
- = MinNatural {
- newtype MaxNatural = MaxNatural {}
- asSetOfPreimages :: (Euclidean a, Integral a) => (forall b. Semiring b => (a -> b) -> a -> b) -> a -> Set a
Documentation
inverseTotient :: (Semiring b, Euclidean a, UniqueFactorisation a, Ord a) => (a -> b) -> a -> b Source #
The inverse for totient
function.
The return value is parameterized by a Semiring
, which allows
various applications by providing different (multiplicative) embeddings.
E. g., list all preimages (see a helper asSetOfPreimages
):
>>>
import qualified Data.Set as S
>>>
import Data.Semigroup
>>>
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]
Count preimages:
>>>
inverseTotient (const 1) 120
17
Sum preimages:
>>>
inverseTotient id 120
4904
Find minimal and maximal preimages:
>>>
unMinWord (inverseTotient MinWord 120)
143>>>
unMaxWord (inverseTotient MaxWord 120)
462
inverseSigma :: (Semiring b, Euclidean a, UniqueFactorisation a, Integral a) => (a -> b) -> a -> b Source #
The inverse for sigma
1 function.
The return value is parameterized by a Semiring
, which allows
various applications by providing different (multiplicative) embeddings.
E. g., list all preimages (see a helper asSetOfPreimages
):
>>>
import qualified Data.Set as S
>>>
import Data.Semigroup
>>>
S.mapMonotonic getProduct (inverseSigma (S.singleton . Product) 120)
fromList [54,56,87,95]
Count preimages:
>>>
inverseSigma (const 1) 120
4
Sum preimages:
>>>
inverseSigma id 120
292
Find minimal and maximal preimages:
>>>
unMinWord (inverseSigma MinWord 120)
54>>>
unMaxWord (inverseSigma MaxWord 120)
95
Wrappers
Wrapper to use in conjunction with inverseTotient
and inverseSigma
.
Extracts the minimal preimage of function.
Wrapper to use in conjunction with inverseTotient
and inverseSigma
.
Extracts the maximal preimage of function.
data MinNatural Source #
Wrapper to use in conjunction with inverseTotient
and inverseSigma
.
Extracts the minimal preimage of function.
Instances
Eq MinNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse (==) :: MinNatural -> MinNatural -> Bool # (/=) :: MinNatural -> MinNatural -> Bool # | |
Ord MinNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse compare :: MinNatural -> MinNatural -> Ordering # (<) :: MinNatural -> MinNatural -> Bool # (<=) :: MinNatural -> MinNatural -> Bool # (>) :: MinNatural -> MinNatural -> Bool # (>=) :: MinNatural -> MinNatural -> Bool # max :: MinNatural -> MinNatural -> MinNatural # min :: MinNatural -> MinNatural -> MinNatural # | |
Show MinNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse showsPrec :: Int -> MinNatural -> ShowS # show :: MinNatural -> String # showList :: [MinNatural] -> ShowS # | |
Semiring MinNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse plus :: MinNatural -> MinNatural -> MinNatural # zero :: MinNatural # times :: MinNatural -> MinNatural -> MinNatural # one :: MinNatural # |
newtype MaxNatural Source #
Wrapper to use in conjunction with inverseTotient
and inverseSigma
.
Extracts the maximal preimage of function.
Instances
Eq MaxNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse (==) :: MaxNatural -> MaxNatural -> Bool # (/=) :: MaxNatural -> MaxNatural -> Bool # | |
Ord MaxNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse compare :: MaxNatural -> MaxNatural -> Ordering # (<) :: MaxNatural -> MaxNatural -> Bool # (<=) :: MaxNatural -> MaxNatural -> Bool # (>) :: MaxNatural -> MaxNatural -> Bool # (>=) :: MaxNatural -> MaxNatural -> Bool # max :: MaxNatural -> MaxNatural -> MaxNatural # min :: MaxNatural -> MaxNatural -> MaxNatural # | |
Show MaxNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse showsPrec :: Int -> MaxNatural -> ShowS # show :: MaxNatural -> String # showList :: [MaxNatural] -> ShowS # | |
Semiring MaxNatural Source # | |
Defined in Math.NumberTheory.ArithmeticFunctions.Inverse plus :: MaxNatural -> MaxNatural -> MaxNatural # zero :: MaxNatural # times :: MaxNatural -> MaxNatural -> MaxNatural # one :: MaxNatural # |
Utils
asSetOfPreimages :: (Euclidean a, Integral a) => (forall b. Semiring b => (a -> b) -> a -> b) -> a -> Set a Source #
Helper to extract a set of preimages for inverseTotient
or inverseSigma
.