Feb 3 Generating Functions Fast Convolution Polynomials Combinatorial

Feb 3: Generating Functions • Fast Convolution & Polynomials • Combinatorial interpretations of polynomials • Inverting polynomials • Extract high coefficients without computing all coefficients

Fast Convolution •

From Mod p to mod 2 •

Aside: Magic Mods • Standard arithmetic (long in C++, long in Java) has 64 bits • So we can only compute (x * y) mod p for x, y w. 32 bits ‘efficiently’ • This is huuugely expensive, can only do about 108 of these per second • But note that if p = 264, x * y mod p is just multiply & drop overflow • I think it’s not hard to derive that (x * y) mod 263 + 1 can still be done quickly • But I have no idea how that works, or what other `magic modulos’ are there. • For rest of today, assume can convolve length n a & b in Õ(n) steps, up to some reasonable range / modulus.

Warmup •

Simplify further •

Simplify further •

What to do • We solve for G’(x) = A(x) G(x)2 + 1 • What if we only have a linear term: G’(x) = A(x) G(x) + B(x) • Fancy way: do it as an ODE, using ln() & exp(), • More straightforward: div-conquer, assume we have coefficeints 1. . t of G already, we want coefficients t+1… 2 t • xt. G’(x)t+1… 2 t = xt(A(x) G(x)1. . t)t+1… 2 t + xt. B(x)t+1… 2 t + A(x) xt G(x)t+1… 2 t Another convolution, using G(x)1…t First t terms of A(x) suffice • Another problem of size t, so we reduce problem of size 2 t to 2 problems of size t, recursion gives Õ(t) runtime.

Another Example of a Generating Function • `make change’ problem: can take steps of size 1, 2, 5. • How many different ways can I get to location n from location 0. • a[i]: # of ways to get to location i, • Recurrence is a[i] = a[i – 1] + a[i – 2] + a[i – 5]. • Q: how many ways to get to 10100 (mod 997)


Quickly compute 1/B(x) • Once again double • Assume have At(x) s. t. At(x)B(x) == 1 mod xt • Note that this gives (At(x)B(x) – 1) == 0 mod xt • Square: (At(x)B(x) – 1)2 == 0 mod x 2 t • Expand: At(x)B(x) – 2 At(x)B(x) == 1 mod x 2 t • Collect: (At(x)B(x)At(x) – 2 At(x)) == A 2 t(x) mod x 2 t • Asymptotically this is also faster: to get to 2 t, I only convolve length t sized things. So total size of all convolutions is O(n)

(At(x)B(x)At(x) – 2 At(x)) == A 2 t(x) mod x 2 t • Say I only want the leading k terms of A 2 t(x) • I can safely ignore At(x) • B(x) has degree at most n • At(x) has degree at most t • At(x)B(x)At(x) has degree at most 2 t + n, while I want everything w. degree at least 2 t – k • So at any point, I can’t loose more than n + k from the topmost term. • So finding the first k + n terms of At(x) suffices! • Propagating this means I only will need the first O(nlogt) coefficients of earlier polynomials
- Slides: 12