The Image Preservation Theorem for Multivalued Functions

We’ll start this chapter on an unusual note — the NTT algorithm is quite simple and can be implemented in less than 20 lines of code. However, the key idea that makes it work, oddly enough, does not have a formal mathematical name. So we are going to take the liberty to give what we believe to be the core theorem behind the algorithm a (subjectively) catchy name:

The Image Preservation Theorem for Multivalued Functions

To explain the Image Preservation Theorem, we’ll go over one last (very simple) concept about roots of unity, then introduce the theorem.

kk-th roots of nested square roots

The literal definition for “k-th root of unity” is that the root of unity aa satisfies ak1a^k\equiv1. Stated another way:

a1ka\equiv\sqrt[k]{1}

Therefore, it should be no surprise that if ω\omega is the primitive 4-th root of unity then

14={1,ω,1,ω}\sqrt[4]{1}=\set{1,\omega,-1,-\omega}

Now let’s do the same operation if ω\omega is the primitive 8-th root of unity. The result would be

14={1,ω2,ω4,ω6}\sqrt[4]{1}=\set{1,\omega^2,\omega^4,\omega^6}

and the 8-th root of 1 generates all the 8-th roots of unity:

18={1,ω,ω2,ω3,ω4,ω5,ω6,ω7}\sqrt[8]{1}=\set{1,\omega,\omega^2,\omega^3,\omega^4,\omega^5,\omega^6,\omega^7}

These observations are simply a matter of definition. Of course, we do not want to directly compute the square root of 1. It’s much easier to first find the primitive kk-th root of unity first, then generate the set of answers for 18\sqrt[8]{1}. For example:

import galois
Fq = 17
k = 8
assert (Fq - 1) % k == 0, "no such subgroup"

GF = galois.GF(Fq)

pr = GF.primitive_root_of_unity(k)

roots = []
for i in range(0,k):
    roots.append(pr**i)
print(roots)

We can also observe that:

14=1\sqrt[4]{1}=\sqrt{\sqrt{1}}
18=1\sqrt[8]{1}=\sqrt{\sqrt{\sqrt{1}}}
116=1\sqrt[16]{1}=\sqrt{\sqrt{\sqrt{\sqrt{1}}}}

and so on. As noted above, directly computing the 1k\sqrt[k]{1} is not efficient. Instead, we consider the following diagram, where each arrow down is a square root of the number above it:

A binary tree showing the recursive square root of 1 for the 8-th roots of unity

We can compute the 8-th roots of unity by starting with 1 and repeatedly taking square roots.

For arbitrary kk, the diagram is as follows.

A binary tree showing the recursive square root of 1 for the k-th roots of unity

Here is a walkthrough of the square root computations:

The square root of 1 is {1,ωk/2}\set{1,\omega^{k/2}}. ωk/2\omega^{k/2} is congruent to -1

Recall from the previous chapter that the square root of ωm\omega^m is ωm/2\omega^{m/2} and ωm/2-\omega^{m/2} (assuming mm is even).

Thus, the square root of ωk/2\omega^{k/2} is {ωk/4,ωk/4}\set{\omega^{k/4},-\omega^{k/4}}.

Also recall that the additive inverse of ωi\omega^i is ωi+k/2\omega^{i+k/2}.

So to compute ωk/4-\omega^{k/4} without the negative sign, we compute ωk/4+k/2=ωk/4+2k/4=ω3k/4\omega^{k/4+k/2}=\omega^{k/4+2k/4}=\omega^{3k/4}. So the square root of ωk/2\omega^{k/2} is {ωk/4,ω3k/4}\set{\omega^{k/4},\omega^{3k/4}}.

The square root of ωk/4\omega^{k/4} is ωk/8,ωk/8{\omega^{k/8},-\omega^{k/8}}. Again, to get rid of the negative sign, we compute ωk/8+k/2=ω5k/8\omega^{k/8+k/2}=\omega^{5k/8}

Why the square root of ω3k/4={ω3k/8,ω7k/8}\omega^{3k/4}=\set{\omega^{3k/8},\omega^{7k/8}} is left as an exercise for the reader.

The height of the tree is log2n\log_2n

Computing the kk-th roots of unity by repeatedly taking the square roots of 1 creates a “tree” that is log2(n)\log_2(n) in height.

Conceptualizing intermediate states of the tree

The set

1\sqrt{\sqrt{\sqrt{1}}}

is mathematically equivalent to the 8-th roots of unity. The set is also equivalent:

{1,1}\left\{\sqrt{\sqrt{1}},\sqrt{\sqrt{-1}}\right\}

Which is also equivalent to:

{1,1,ω2,ω2}\set{\sqrt{1},\sqrt{-1},\sqrt{\omega^2},\sqrt{-\omega^2}}

In other words:

1={1,1}={1,1,ω2,ω2}={1,...,ω7}\sqrt{\sqrt{\sqrt{1}}}=\left\{\sqrt{\sqrt{1}},\sqrt{\sqrt{-1}}\right\}=\set{\sqrt{1},\sqrt{-1},\sqrt{\omega^2},\sqrt{-\omega^2}}=\set{1,...,\omega^7}

Quick aside — multivalued functions and images

Admittedly, the observations we made above are trivial extensions of the definition of kk-th roots. The more interesting implications of these observations will be shown in the following section. However, it will be helpful to introduce some mathematical terminology first:

Image of a function — if we have a set of points that we evaluate a function on, then the set of evaluations is the image. For example, if the function is f(x)=2xf(x)=2x and the domain we evaluate ff on is {1,2}\set{1,2} then the image will be {2,4}\set{2,4}. The term range of a function means the set of values a function could output. In our context, the image of the function refers to the actual set of outputs for a given set of inputs.

Multivalued function — a function that may return more than one evaluation for a single point in the domain. For example, x\sqrt{x} evaluated on 0 returns 0, but x\sqrt{x} evaluated on 1 returns {1,1}\set{1, -1}.

Note: The multivalued function f(x)=xf(x)=\sqrt{x} has an image larger than its domain.

With these definitions in mind, the reader should understand the following statements:

“The image of f(x)=x+1f(x)=x+1 on the domain {0,2}\set{0,2} is {1,3}\set{1,3}

“The image of the multivalued function f(x)=xf(x)=\sqrt{x} on the domain {1}\set{1} is {1,1}\set{1,-1}

Now we get to a more interesting set of observations.

The image of f(x)=xf(x)=x evaluated on {1,...,ω7}\set{1,...,\omega^7} is the same as g(x)=x8g(x)=\sqrt[8]{x} evaluated on {1}\set{1} (k = 8)

This claim is a simple rephrasing of the concepts shown above, so we won’t elaborate further. The interesting part is how we can generalize this to other functions.

The nuance here is that g(x)g(x) is a multivalued function that returns eight elements.

The image of f(x)=axf(x)=ax evaluated on the 4-th roots of unity is the same as the multivalued function g(x)=ax4g(x)=a\sqrt[4]{x} evaluated on {1}\set{1} (k = 4)

Remember, 14={1,ω,ω2,ω3}\sqrt[4]{1}=\set{1,\omega,\omega^2,\omega^3}, so a14={a,aω,aω2,aω3}a\sqrt[4]{1}=\set{a,a\omega,a\omega^2,a\omega^3}. This is the same image as evaluating ff on each root of unity one-by-one. Since f(x)=axf(x)=ax

  • f(1)=af(1)=a
  • f(ω)=aωf(\omega)=a\omega
  • f(ω2)=aω2f(\omega^2)=a\omega^2
  • f(ω3)=aω3f(\omega^3)=a\omega^3

Exercise for the reader: Let f(x)=ax+cf(x)=ax+c. What is the image of f(x)f(x) on the 4-th roots of unity? What is the image of the multivalued function g(x)=ax4+bg(x)=a\sqrt[4]{x}+b on the domain {1}\set{1}?

In the following chapters, we will show how to handle more complex cases like f(x)=x2+x3f(x)=x^2+x^3, but for now, we show how to actually compute multivalued functions for the simple cases we showed here. But first, let’s give a formal definition to the observation we’ve made so far about image equivalence.

The image of f(x)=xf(x)=x evaluated on the 4-th roots of unity is the same as the multivalued function g(x)=xg(x)=\sqrt{x} evaluated on the second roots of unity {1,1}\set{1,-1} (k = 4)

This example is very similar to the above, except that we don’t “target” the domain {1}\set{1} but rather {1,1}\set{1,-1}.

We have that

  • g(1)=1={1,1}g(1)=\sqrt{1}=\set{1,-1}
  • g(1)=1={ω,ω}g(-1)=\sqrt{-1}=\set{\omega,-\omega}

This is the same image as evaluating ff on {1,ω,1,ω}\set{1,\omega,-1,-\omega}

In summary, if we “shrink” the domain by a factor of rr and replace every xx in f(x)f(x) with xr\sqrt[r]{x} to create a new multivalued function gg, the images of ff and gg are identical.

We’ll now formally define the concept we’ve been illustrating

The core theorem of NTT: Image Preservation Theorem for Multivalued Functions

Let ω\omega be the primitive kk-th root of unity and ω={1,ω,ω2,...}\langle\omega\rangle=\set{1,\omega,\omega^2,...} be the kk-th roots of unity defined in Fq\mathbb{F}_q.

Let kk be a power of 2.

Let f(x)f(x) be a polynomial in Fq\mathbb{F}_q. Let rr be a power of 2 less than or equal to kk.

Let g(x)g(x) be a multivalued function created by replacing every xx in f(x)f(x) with xr\sqrt[r]{x}.

Let the domain ωr\langle\omega\rangle^r be {ωrωω}\set{\omega^r|\omega\in \langle\omega\rangle}. Note that if r=kr=k then ωr={1}\langle\omega\rangle^r=\set{1}.

The image of ff on ω\langle\omega\rangle exactly equals the image of gg on ωr\langle\omega\rangle^r.

It is of utmost importance that the reader understand the theorem above, as it is the key concept that the Number Theoretic Transform relies on!

Here are some examples to enforce the concept:

  • The image of f(x)=xf(x)=x on the 4-th roots of unity is equal to the image of g(x)=xg(x)=\sqrt{x} on the second roots of unity (as shown in the previous section).
  • The image of f(x)=xf(x) =x on 16th roots of unity is equal to image of g(x)=xg(x)=\sqrt{x} on 8th roots of unity
  • The image of f(x)=xf(x) =x on k-th roots of unity is equal to image of g1(x)=xg_1(x)=\sqrt{x} on k/2-th roots of unity
  • The image of g1(x)=xg_1(x)=\sqrt{x} on k/2-th roots of unity is equal to image of g2(x)=x4g_2(x)=\sqrt[4]{x} on k/4-th roots of unity

The following section shows examples where f(x)f(x) is slightly more complex.

Image Preservation Theorem Examples for f(x)=ax+bf(x)=ax+b

Let f(x)=ax+bf(x)=ax+b and the domain be the 4-th roots of unity {1,ω,ω2,ω3}\set{1,\omega,\omega^2,\omega^3}.

Let f1f_1 be the multivalued function ax+ba\sqrt{x}+b and the domain be{1,1}\set{1,-1} or equivalently {1,ω2}\set{1,-\omega^2}.

Let f2f_2 be the multivalued function ax4+ba\sqrt[4]{x}+b and the domain be {1}\set{1}

The images of ff, f1f_1, and f2f_2 are identical: {a+b,aω+b,aω2+b,aω3+b}\set{a+b,a\omega+b,a\omega^2+b,a\omega^3+b}

Connection to NTT

Remember, the goal of NTT is to evaluate f(x)f(x) on the kk-th roots of unity in O(nlogn)\mathcal{O}(n\log n) time. In other words, we want to compute the image of ff on the kk-th roots of unity.

You can probably guess where this is going.

Computing the image of f(x)f(x) on the kk-th roots of unity is equivalent to computing the image of a new function g(x)g(x) defined such that for each xx in ff, xxkx\rightarrow\sqrt[k]{x} evaluated on {1}\set{1}.

However, this leaves an open question:

Expanding xk\sqrt[k]{x} into {1,...,ωk1}\set{1,...,\omega^{k-1}} doesn’t directly lead to a speedup. Algorithmically, expanding a 1k\sqrt[k]{1} into the kk-th roots of unity is the same as evaluating f(x)f(x) on the kk points. How does this alternate way of evaluating f(x)f(x) help us?

In the next chapter, we will demonstrate how to evaluate multi-valued functions using square root expansion and explain how this approach can prevent redundant computation.

Ready to Get Started?Join Thousands of Users Today

Start your free trial now and experience the difference. No credit card required.

© 2025 Better-Start. All rights reserved.