COMPUTER ENGINEER

← BlogDATA STRUCTURES / ALGORITHMSPython example pack ↓

Geometry and numerical algorithms · 44 / 53

Strassen, FFT and numerical costs

Understand → trace → implement → justify

2 min reading · allow extra time for practice

Classical n×n matrix multiplication uses Θ(n³) arithmetic operations. Strassen combines seven half-size products rather than eight: T(n)=7T(n/2)+Θ(n²), yielding Θ(n^log₂7). Extra additions, temporary storage, cache effects and numerical error make it unattractive for small matrices. AI kernels do not universally use Strassen; hardware matters.

FFT accelerates convolution by evaluating polynomials at suitable roots. Direct convolution is Θ(n²); FFT-based convolution takes O(n log n) arithmetic operations at an appropriate padded length. Circular and linear convolution differ: insufficient zero-padding wraps coefficients. Floating-point rounding must be checked.

NTT computes exact modular convolution with suitable primes and roots. CRT can reconstruct larger coefficients only with proven bounds. Arithmetic counts differ from big-integer bit costs. BLAS, SIMD, GPU kernels and tiling are crucial practical factors.

A worked trace

[1,2] times [3,4] produces [3,10,8]; the middle coefficient is 1×4+2×3.

Cost and assumptions

Direct convolution costs O(nm); FFT costs O(N log N) for suitable N≥n+m−1.

Executable example

Run with Python 3. Assertions check a small example; they do not constitute a general correctness proof. Some advanced examples are explicitly small models or reference oracles, not full production implementations.

Python 3
def convolution(a,b):
    out=[0]*(len(a)+len(b)-1)
    for i,x in enumerate(a):
        for j,y in enumerate(b): out[i+j]+=x*y
    return out
assert convolution([1,2],[3,4])==[3,10,8]

TEST YOUR UNDERSTANDING

Your turn

Are random small coefficients sufficient FFT tests?

Reveal the reasoning

No. Include large coefficients, long arrays, cancellation and padding boundaries; compare small cases with an exact oracle.

Take it further

  1. Write down the input contract and the invariant before changing the example.
  2. Add empty, boundary, duplicate and adversarial cases where they are relevant. Compare with a simple oracle.
  3. Derive the cost under the stated model; measure several input sizes and explain discrepancies.

Primary reading & lecture notes

Original explanations in this course; these references provide proofs and further reading. Source links may cover the broader module.

MIT 6.046J · Design and Analysis ↗
Solve the exercise before moving on.