# Fast extrapolation from āŸØšœ”āŸ© $$ \def\F{\mathbb F} $$ Given $P ∈ \F[X]$ with $\deg P < n$ and $šœ”$ a $n$-primitive root of unity. Evaluate $P$ on the subgroup generated by $šœ”$: $$ a_i = P(šœ”^i) $$ **Goal.** *Given only $a_i$ and arbitrary $z ∈ \F$, efficiently evaluate $P(z)$.* --- Observe the Lagrange basis for $āŸØšœ”āŸ©$: $$ L_i(X) = c_i \frac{X^n - 1}{X-šœ”^i} $$ where $c_i$ is set such that $L_i(šœ”^j) = \delta_{ij}$ (i.e. one when $i=j$ and zero otherwise). Using [L'Hospital rule](https://hackmd.io/ZxR4-iKsRRqqcMtHYj8duA) we find: $$ \left. \frac{X^n - 1}{X-šœ”^i} \right\vert_{X=šœ”^i} = \left. \frac{nā‹…X^{n-1}}{1} \right\vert_{X=šœ”^i} = n ā‹… šœ”^{i(n-1)} = \frac{n}{šœ”^i} $$ and thus $$ L_i(X) = \frac{šœ”^i}{n} \frac{X^n - 1}{X-šœ”^i} $$ --- $$ \begin{aligned} P(z) &= \sum_i a_i ā‹… L_i(z) \\&= \sum_i a_i ā‹… \frac{šœ”^i}{n} \frac{z^n - 1}{z - šœ”^i} \\&= \frac{z^n - 1}{n} \sum_i \frac{a_i ā‹… šœ”^i}{z - šœ”^i} \end{aligned} $$ This can be evaluated in $\mathcal{O}(1)$ space and $\mathcal{O}(m + \log n)$ time, where $m$ is the number of non-zero entries in $\vec a$.