[Tutorial] Generalized Chirp Z-Transform

Revision en1, by box, 2020-10-10 11:23:53

My last blog was a bit too esoteric

This blog assumes that you can do a basic convolution (e.g. FFT). After I saw that many people did not know how to do Chirp Z-Transform with arbitrary exponents fast from my last blog I decided to shitpost write a short tutorial on it.

Let's say we have a polynomial $$$P(x)$$$, such that

$$$\begin{align}P(x)=\sum_{i=0}^{n-1}a_ix^i\end{align}$$$

Now, let's say we have $$$c$$$ and $$$m$$$, and we want to find $$$P(c^0),P(c^1),P(c^2),\dots,P(c^m)$$$. Let $$$b_j=P(c^j)$$$. Consider the implications of having $$$x$$$ as such a form:

$$$\begin{align}b_j=\sum_{i=0}^{n-1}a_ix^{ij}\end{align}$$$

Tinkering around with different expressions for $$$ij$$$, one finds that $$$ij=\frac{(i+j)^2}{2}-\frac{i^2}{2}-\frac{j^2}{2}$$$. This means that

$$$\begin{align}b_j=\sum_{i=0}^{n-1}a_ix^{\frac{(i+j)^2}{2}-\frac{i^2}{2}-\frac{j^2}{2}}\end{align}$$$
$$$\begin{align}b_jx^{\frac{j^2}{2}}=\sum_{i=0}^{n-1}(a_ix^{-\frac{i^2}{2}})x^{\frac{(i+j)^2}{2}}\end{align}$$$

Hence we can find $$$b_j$$$ from the difference-convolution of $$$a_ix^{-\frac{i^2}{2}}$$$ and $$$x^{\frac{i^2}{2}}$$$. However, in many cases — especially when working under a modulus — we can't find the $$$x^{\frac{i^2}{2}}$$$ as $$$i$$$ may be odd. We use a workaround: $$$ij=\binom{i+j}{2}-\binom{i}{2}-\binom{j}{2}$$$. Proof:

$$$ij=\binom{i+j}{2}-\binom{i}{2}-\binom{j}{2}$$$
$$$ij=\frac{(i+j)(i+j-1)}{2}-\frac{(i)(i-1)}{2}-\frac{(j)(j-1)}{2}$$$
$$$2ij=(i+j)(i+j-1)-(i)(i-1)-(j)(j-1)$$$
$$$2ij=(i)(i+j-1)+(j)(i+j-1)-(i)(i-1)-(j)(j-1)$$$
$$$2ij=(i)((i+j-1)-(i-1))+(j)((i+j-1)-(j-1))$$$
$$$2ij=(i)(j)+(j)(i)$$$

Modifying our formula a bit, we get

$$$\begin{align}b_jx^{\binom j2}=\sum_{i=0}^{n-1}(a_ix^{-\binom i2})x^{\binom{i+j}2}\end{align}$$$

As for implmentation details, notice that

$$$\begin{align}b_jx^{\binom j2}=\sum_{i=0}^{n-1}(a_{(n-(n-i))}x^{-\binom{n-(n-i)}2})x^{\binom{i+j}2}\end{align}$$$

Define $$$c_i=a_{n-i}x^{-\binom{n-i}2}$$$; $$$d_i=x^{\binom i2}$$$. We hence have

$$$b_jx^{\binom j2}=\sum_{i=0}^{n-1}c_{n-i}d_{i+j}$$$
$$$b_j=x^{-\binom j2}(c*d)_{n+j}$$$

(the second through definition of convolution)

You can test your implementations here, mod 998244353 and here, mod 10^9+7, although note that the second one is both intense in precision and constant factor.

My code for the former

This method can be used to cheese 1184A3 - Heidi Learns Hashing (Hard) and 1054H - Epic Convolution, and is also a core point in 901E - Cyclic Cipher.

Tags #basic math, #fft

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English box 2020-10-10 13:00:45 0 (published)
en3 English box 2020-10-10 13:00:17 44 (saved to drafts)
en2 English box 2020-10-10 11:26:24 17
en1 English box 2020-10-10 11:23:53 6875 Initial revision (published)