TAOCP Vol 2: Seminumerical Algorithms · Week 80

TAOCP 4.3.3 How Fast Can We Multiply?

Updated

About 9 hours19 exercises, rated M15 to M49

Summary

TAOCP 4.3.3 How Fast Can We Multiply?: Faster-than-schoolbook multiplication: splitting numbers in halves to trade a multiplication for additions (Karatsuba-style), Toom-Cook generalizations, and the Fourier transform approach that leads to Schonhage-Strassen. Budget about 9 hours; do exercises 1, 8 and 9.

Flashcards 14 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §4.3.3 How Fast Can We Multiply?

    Implement the half-splitting method on top of your 4.3.1 bignums and find the crossover size where it beats schoolbook.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 8, Ex 9; log what you solve below.

  3. Write down one thing you'd explain to someone

    A few sentences in your own words in Your notes: the idea, why it works, an example. 30 words ticks this.

Sign in to track this: tick each step off and it counts toward your week.

Exercises

This section has 19 exercises, rated M15 to M49, and Knuth marks 7 of them with the triangle for recommended. Implement Karatsuba and find the crossover with schoolbook multiplication on your machine; then try an FFT-based multiply. The picks support that work.

Worth your time

  • Exercise 122

    Karatsuba in decimal, by hand, on four-digit numbers.

    Discuss

  • Exercise 428▶ Recommended

    Evaluate at symmetric points to speed up Toom-Cook.

    Discuss

  • Exercise 8M20

    Can you skip the bit reversal in the FFT? A common shortcut question.

    Discuss

  • Exercise 9M15

    Replacing the root of unity by a power of it. Checks you understand the transform.

    Discuss

  • Exercise 1625▶ Recommended

    A discrete Fourier transform of any length in n log n operations.

    Discuss

  • Exercise 17M26

    Count exactly how many small products Karatsuba does.

    Discuss

  • Exercise 18M30▶ Recommended

    Schedule memory for recursive Karatsuba. The stretch, and a real implementation issue.

    Discuss

  • Exercise 19M23▶ Recommended

    Compute u*v mod m with a bounded number of safe operations.

    Discuss

Your log

Sign in to log the exercises you work: number, rating, how far you got.

Your notes

Only you

Sign in to keep private notes on this guide, in Markdown. They stay yours: never on your profile, and you can export them all.

Discussion

0 posts

Questions about the reading go here; each exercise has its own thread below. Hints over answers.

No posts yet. Ask a question or share a tip.

Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Exercise threads

One thread per exercise. Open one to ask for a nudge or check your thinking.

  • Exercise 122No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 428No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 8M20No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 9M15No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 1625No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 17M26No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 18M30No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

  • Exercise 19M23No posts yet

    Hints over answers. Say what you tried; put an answer or a full solution inside a spoiler: ||like this|| or a ```spoiler block.

    Sign in to postAnyone can read. Posting needs an account with a confirmed email.

Reference

Why it matters

These ideas are behind every fast bignum library and are a beautiful example of divide and conquer and of how the FFT connects to arithmetic.

Before you start
  • 4.3.1 The Classical Algorithms
  • Divide and conquer, recursion
How to approach it

Implement the half-splitting method on top of your 4.3.1 bignums and find the crossover size where it beats schoolbook. Read the FFT part for ideas; implementing an FFT multiply is a stretch goal.

Common traps
  • Recursing all the way down to single digits. Switch to schoolbook below a threshold.

Spot a mistake? Report it

Back to week 80