Evaluating multivalued functions by square root expansion

In the previous chapter on Image Preservation of Multivalued Functions we saw that instead of evaluating f(x)f(x) on the kk-th roots of unity, we can transform f(x)f(x) into a multivalued function and evaluate it on the domain {1}\set{1}.

Unwrapping Square Roots

It’s much easier to think of the 8-th root of 1 as nested square roots:

x8=x\sqrt[8]{x}=\sqrt{\sqrt{\sqrt{x}}}

We now show how to evaluate:

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

using square root expansion.

We know that 1\sqrt{1} evaluates to {1,1}\set{1,-1} so we replace the inner-most square root of 1 with its evaluations:

A diagram showing the that a times the 8-th root of 1 is equal to a times the fourth root of 1 and a times the fourth root of -1

This “removes” one layer of square roots. Next, we evaluate 1\sqrt{1} and 1\sqrt{-1}. Since we are working with the 8-th roots of unity, 1ω4-1\equiv\omega^4 so 1={ω2,ω2}\sqrt{-1}=\{\omega^2,-\omega^2\}

A diagram showing how the fourth roots can be expanded into two square roots

Then, we evaluate each of the remaining square roots:

A diagram showing how four square roots evaluate to the 8th roots of unity

Observe that the “leaves” of the evaluation tree are exactly ff evaluated on an 8-th root of unity.

Evaluating f(x)=x2f(x)=x^2 on the 8-th roots of unity

The nice thing about square root expansion is that for most powers of xx, the square roots “disappear early” as this example shows. We replace xx with x8\sqrt[8]{x}, but since xx is squared, we have end up with x4\sqrt[4]{x} or

x\sqrt{\sqrt{x}}

Here is the evaluation tree from repeatedly expanding the square roots until we have eight evaluations. In the final row, when there are no square roots, we simply copy the values down.

An evaluation tree for the 8-th roots of unity evaluated on x^2 using square root expansion

Now observe what happens if we evaluate the 8-th roots of unity {1,...,ω7}\set{1,...,\omega^7} directly on f(x)=x2f(x)=x^2 — the outcome is exactly the same.

f(1)=(1)2=1f(1)=(1)2=1f(ω2)=(ω2)2=1f(ω2)=(ω2)2=1f(ω)=(ω)2=ω2f(ω)=(ω)2=ω2f(ω3)=(ω3)2=ω2f(ω3)=(ω3)2=ω2\begin{align*} f(1)&=(1)^2&=1\\ f(-1)&=(-1)^2&=1\\ f(\omega^2)&=(\omega^2)^2&=-1\\ f(-\omega^2)&=(-\omega^2)^2&=-1\\ f(\omega)&=(\omega)^2&=\omega^2\\ f(-\omega)&=(-\omega)^2&=\omega^2\\ f(\omega^3)&=(\omega^3)^2&=-\omega^2\\ f(-\omega^3)&=(-\omega^3)^2&=-\omega^2\\ \end{align*}

Evaluating f(x)=x4f(x)=x^4 on the 8-th roots

Again, we replace xx with x8\sqrt[8]{x} which gives us x\sqrt{x}. Since we only have one square root, we will only expand the square root once, then simply copy the results down.

A diagram showing the square root expansion of 1 to the 8-th roots

We saw in an earlier chapter that xk/2x^{k/2} is 1 if evaluated on an even power of ω\omega and -1 otherwise. The result here matches the expected outcome.

Evaluating f(x)=ax+bx5f(x)=ax+bx^5 on the 8-th roots of unity

If we replace xx with x8\sqrt[8]{x}, we get a slightly awkward result:

f(x)=ax8+bx5/8f(x)=a\sqrt[8]{x}+bx^{5/8}

However, if we factor xx out first to turn f(x)f(x) into f(x)=x(a+bx4)f(x)=x(a+bx^4), the new form becomes a lot more manageable when we substitute x8\sqrt[8]{x} for xx:

g(x)=x8(a+bx)g(x)=\sqrt[8]{x}(a+b\sqrt{x})

The first square root will disappear after the first evaluation and (a+bx)(a+b\sqrt{x}) will become a constant for most of the tree.

Below is a diagram of expanding the square roots. At each level, we unwrap (evaluate) one square root. The square roots in blue represent the ones evaluated at each step. As a general rule, evaluate the innermost square root if it is nested:

A diagram showing the square root expansion of a + bx^4

Now let’s compare the result to evaluating f(x)=ax+bx5f(x)=ax+bx^5 on the 8-th roots of unity one-by-one:

f(1)=a(1)+b(1)5=a+bf(1ω4)=aω4+bω20=a(1)+b(1)=abf(ω2)=aω2+bω10=aω2+bω2=(a+b)ω2f(ω2ω6)=aω6+bω30=a(ω2)+b(ω2)=(a+b)ω2f(ω)=aω+bω5=aωbωf(ωω5)=aω5+bω25=a(ω)+bω=aω+bω=(ba)ωf(ω3)=aω3+bω15=aω3+bω7=aω3bω3=(ab)ω3f(ω3ω7)=aω7+bω35=a(ω3)+b(ω3)=(a+b)ω3\begin{array}{rcll} f(1) &=& a(1) + b(1)^5 &= a + b\\[4pt] f(-1\equiv\omega^4) &=& a\omega^4 + b\omega^{20} = a(-1) + b(-1) &= -a - b\\[4pt] f(\omega^2) &=& a\omega^2 + b\omega^{10} = a\omega^2 + b\omega^2 &= (a + b)\omega^2\\[4pt] f(-\omega^{2}\equiv\omega^6) &=& a\omega^6 + b\omega^{30} = a(-\omega^2) + b(-\omega^2) &= -(a + b)\omega^2\\[4pt] f(\omega) &=& a\omega + b\omega^5 &= a\omega - b\omega \\[4pt] f(-\omega\equiv\omega^5) &=& a\omega^5 + b\omega^{25} = a(-\omega) + b\omega &= -a\omega + b\omega = (b - a)\omega\\[4pt] f(\omega^3) &=& a\omega^3 + b\omega^{15} = a\omega^3 + b\omega^7 &= a\omega^3 - b\omega^3 = (a - b)\omega^3\\[4pt] f(-\omega^3\equiv\omega^7) &=& a\omega^7 + b\omega^{35} = a(-\omega^3) + b(-\omega^3) &= -(a + b)\omega^3 \end{array}

Evaluating the terms using the method above requires 8 additions and 16 multiplications.

However, using square root expansion, we only need 2 additions and 10 multiplications. Whenever a square root is expanded into its two solutions, we multiply it by the adjacent term. So whenever the “final” square root is unwrapped, it results in two multiplications. These are highlighted in red below. The additions are highlighted in blue.

A diagram counting the number of additions and multiplications in the square root expansion.

Note that “computing the square root” is completely deterministic. We know it always follows the pattern of {1}\set{1}, 2nd roots of unity, 4-th roots of unity, 8-th roots of unity, and so on. Thus, there is no need to explicitly compute the square roots.

Easy terms and hard terms

We can see that terms xk/2x^{k/2} are easiest to evaluate because they only require 1 evaluation, and the rest is just copying values down the tree.

On the other hand, xx with no power is the “hardest” to evaluate because we need to do a square root expansion at every step down the tree.

The nice thing about the function f(x)=a+bxk/2f(x)=a+bx^{k/2}, which becomes the multivalued function g(x)=(a+bx)g(x)=(a+b\sqrt{x}) on the kk-th roots of unity is that we fully evaluate the square root at the second level of the tree, and simply copy down the sum of a+ba+b for the rest of the evaluation.

In fact, any polynomial can be written to “maximize” the amount of a+bxk/2a+bx^{k/2} terms and “minimize” the amount of xx terms.

Suppose we have a 7-degree polynomial that we want to evaluate on the 8-th roots of unity.

f(x)=a0+a1x+a2x2+a3x3+a4x4+a5x5+a6x6+a7x7f(x)= a_0 + a_1x + a_2x^2 + a_3x^3 + a_4x^4 + a_5x^5 + a_6x^6 + a_7x^7

To maximize the number of x4x^4 terms and have only one xx term, we factor it as follows:

f(x)=a0+a2x2+a4x4+a6x6+a1x+a5x5+a3x3+a7x7f(x)= a_0 + a_2x^2 + a_4x^4 + a_6x^6 + a_1x + a_5x^5 + a_3x^3+ a_7x^7
f(x)=a0+a4x4+(a2x2+a6x6)+(a1x+a5x5)+(a3x3+a7x7)f(x)= a_0 + a_4x^4 + (a_2x^2 + a_6x^6) + (a_1x + a_5x^5) + (a_3x^3+ a_7x^7)
f(x)=a0+a4x4+x2(a2+a6x4)+x(a1+a5x4)+x3(a3x+a7x4)f(x)= a_0 + a_4x^4 + x^2(a_2 + a_6x^4) + x(a_1 + a_5x^4) + x^3(a_3x+ a_7x^4)
f(x)=a0+a4x4+x2(a2+a6x4)+x((a1+a5x4)+x2(a3x+a7x4))f(x)= a_0 + a_4x^4 + x^2(a_2 + a_6x^4) + x((a_1 + a_5x^4) + x^2(a_3x+ a_7x^4))

Exercise: How should the polynomial f(x)=a0+a1x+a2x2+a3x3f(x)=a_0+a_1x+a_2x^2+a_3x^3 evaluated on the 4th roots of unity be factored to have only one xx term and as many x2x^2 terms as possible? Remember, xk/2x^{k/2} is x2x^2 in this case.

In the next chapter, we will show how to evaluate a general degree 4 and degree 8 polynomial using square root expansion, which also happens to be exactly the NTT algorithm.

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.