 GFG App
Open App Browser
Continue

# Python | Inverse Number Theoretic Transformation

Inverse Number Theoretic Transform is a Fast Fourier transform theorem generalization. It is obtained by the replacement of e^(-2piik/N) with an nth primitive unity root. So this means, instead of the complex numbers C, use transform over the quotient ring Z/pZ. The theory is based on and uses the concepts of finite fields and number theory.

Inverse Number Theoretic Transform modulus needs to be prime necessarily. But if it is prime, it makes things simpler. One can perform the Inverse NTT with a composite modulus. For modulus :

• nth root of unity existence
• multiplicative inverse of n

A number-theoretic transform is basically a Fourier transform. Also, suppose that a Normal Discrete Fourier Transform is given and it can be done in matrix form by multiplying the data with a Fourier Matrix. Let us suppose N = 4. Then, the matrix can be –

```[ 1   1    1    1  ]
[ 1   w   w^2  w^3 ]
[ 1  w^2  w^4  w^6 ]
[ 1  w^3  w^6  w^9 ]
```

## sympy.discrete.transforms.intt( ) :

It can Inverse Number Theoretic Transform (NTT) of the sequence. It specializes over the Discrete Fourier Transform (DFT) quotient ring with Z/pZ for prime number instead of acomplex numbers.

Automatically the sequence is padded with zero to the right because the radix-2 FFT requires the sample point number as a power of 2.

```
Parameters :
-> seq       : [iterable] sequence on which DFT is to be applied.
-> prime no. : [Integer] prime modulus for INTT to perform on.

Returns :
Number Theoretic Transform
```

Example #1 :

 `# import sympy  ` `from` `sympy ``import` `intt ` ` `  `# sequence  ` `seq ``=` `[``15``, ``21``, ``13``, ``44``] ` ` `  `prime_no ``=` `3` `*` `2``*``*``8` `+` `1` ` `  `# intt ` `transform ``=` `intt(seq, prime_no) ` `print` `(``"Inverse NTT : "``, transform) `

Output :

`Inverse NTT :  [600, 357, 183, 413]`

Example #2 :

 `# import sympy  ` `from` `sympy ``import` `intt ` ` `  `# sequence  ` `seq ``=` `[``153``, ``321``, ``133``, ``44``, ] ` ` `  `# Prime modulus of the form (m * 2**k + 1) ` `prime_no ``=` `3` `*` `2``*``*``8` `+` `1` ` `  `# intt ` `transform ``=` `intt(seq, prime_no) ` `print` `(``"Inverse NTT : "``, transform) `

Output :

```Inverse NTT :  [355, 710, 557, 69]
```

My Personal Notes arrow_drop_up