iota-0.1.0.0
Safe HaskellSafe-Inferred
LanguageGHC2021

Math.NTT

Synopsis

Documentation

ntt :: forall p. KnownNat p => Vector (GF p) -> Vector (GF p) Source #

Number Theoretic Transform p: prime (c * 2 ^ k + 1)

n = 2 ^ i, n < 2 ^ k

O(n log n)

>>> ntt @998244353 [1,1,1,1]
[4,0,0,0]
>>> ntt @469762049 [123,0,0,0]
[123,123,123,123]

intt :: forall p. KnownNat p => Vector (GF p) -> Vector (GF p) Source #

convolute :: forall p. KnownNat p => Vector (GF p) -> Vector (GF p) -> Vector (GF p) Source #

>>> convolute @998244353 [1,1,1,0] [1,1,1,0]
[1,2,3,2,1,0,0]
>>> convolute @998244353 [1,1,1] [1,1,1,0]
[1,2,3,2,1,0]

data NTTRunner p Source #

Constructors

NTTRunner 

Fields

nttRunner :: forall p. KnownNat p => NTTRunner p Source #

butterfly :: (KnownNat p, PrimMonad m) => MVector (PrimState m) (GF p) -> m () Source #

invButterfly :: forall p m. (KnownNat p, PrimMonad m) => MVector (PrimState m) (GF p) -> m () Source #

growToPowerOfTwo :: (Num a, Unbox a) => Vector a -> Vector a Source #

>>> growToPowerOfTwo (U.fromListN 3 [1::Int,2,3])
[1,2,3,0]

extendToPowerOfTwo :: Int -> Int Source #

>>> extendToPowerOfTwo 0
1

primitiveRoot Source #

Arguments

:: Int

prime

-> Int 
>>> primitiveRoot 2
1
>>> primitiveRoot 998244353
3