Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Compute the number-theoretic transform of a list of integers
ResourceFunction["NumberTheoreticTransform"][{f1,f2,…},r,m] finds the number-theoretic transform of the integer list fi with the given root r and modulus m. | |
ResourceFunction["NumberTheoreticTransform"][{f1,f2,…},m] finds the number-theoretic transform of the integer list fi with given modulus prime m and automatically chosen root r. | |
ResourceFunction["NumberTheoreticTransform"][{f1,f2,…}] finds the number-theoretic transform of the integer list fi with automatically chosen root r and modulus m. |
The number-theoretic transform of the list {1,2,3} can be computed with modulus 7 = 2 × 3 + 1 and root PrimitiveRoot[7]2:
In[1]:= |
Out[1]= |
The number-theoretic transform of the list Range[10] can be computed with modulus 31 = 10 × 3 + 1 and root PrimitiveRoot[31]10:
In[2]:= |
Out[2]= |
The number-theoretic transform of the list Range[16] can be computed with modulus 4129 and root 1163:
In[3]:= |
Out[3]= |
The Inverse of a number-theoretic transform is a transform with the same modulus m, but with root ModularInverse[r,m] and prefactor ModularInverse[n,m]:
In[4]:= |
Out[4]= |
Number-theoretic transforms can be used immediately to compute exact convolutions of non-negative integer lists:
In[5]:= |
Out[13]= |
In[14]:= |
Out[14]= |
Number-theoretic transforms can be used to compute exact convolutions of general integer lists, including negative integers. However, an offset correction needs to be computed first:
In[15]:= |
Out[15]= |
Number-theoretic transforms can be computed much faster on lists with lengths that are powers of two:
In[16]:= |
Out[16]= |
If the chosen modulus m is too small, then overflow may cause the number-theoretic transform to have no inverse:
In[17]:= |
Out[17]= |
If the chosen modulus m is too small, then overflow may cause the number-theoretic transform to not support convolutions:
In[18]:= |
Out[18]= |
Using convolution with padding, number-theoretic transforms can compute polynomial multiplications:
In[19]:= |
Out[19]= |
This work is licensed under a Creative Commons Attribution 4.0 International License