Polynomial Operations — Schoolbook Multiply & Horner Evaluation

Multiplying polynomials is convolving their coefficient arrays: (P·Q)[k] = Σi+j=k P[i]·Q[j]. Horner evaluates P(x₀) in O(n). All arithmetic is mod p.

step 0

Inputs

P (coefficient of xi at index i)
Q
Press Step to begin.
P[i] (current) Q[j] (current) target slot

Product (P·Q)

result[k] accumulates P[i]·Q[j] for every i+j=k
Multiply mode: each P[i]·Q[j] product drops into result slot i+j. Watch the product array fill cell by cell.

How to read this

Multiply mode shows schoolbook convolution. Edit P and Q as comma-separated coefficients (index 0 is the constant term). Each step highlights one P[i] (blue) and one Q[j] (gold), multiplies them, and adds the product into result slot k = i + j (green). After all i,j pairs, the green array is the full product P·Q mod p.

Horner mode evaluates P(x₀). Starting from acc = 0, each step walks one coefficient from the highest power down, applying acc = acc·x₀ + P[i] (mod p). The final accumulator is P(x₀) — computed in just n multiply-adds, the optimal cost.

Use Step to advance one operation, Run to autoplay, and Reset to rebuild from the current inputs. Change mod p to see how reduction keeps every coefficient in [0, p).

Self-contained visualization, no external dependencies. Coefficients are reduced mod p (default a small prime so values stay readable). Multiplying two polynomials is exactly convolving their coefficient arrays; fast methods (Karatsuba, FFT, NTT) compute this same convolution in O(n log n). Horner's rule evaluates P(x₀) with n multiply-adds. See junior.md and professional.md for details.