TAOCP Vol 2: Seminumerical Algorithms · Week 84

TAOCP 4.5.4 Factoring into Primes

Updated

About 10 hours47 exercises, rated 10 to M50

Summary

TAOCP 4.5.4 Factoring into Primes: Methods for factoring integers and testing primality: trial division, Fermat's method, Pollard's rho, probabilistic primality testing, and the connection to public-key cryptography (RSA), plus a look at more advanced sieving methods. Budget about 10 hours; do exercises 1, 5 and 8.

Flashcards 15 cards for Anki and AnkiMobile · all decks

Anki deck.tsv

This week's steps

3 steps
  1. Read §4.5.4 Factoring into Primes

    Implement trial division, Pollard rho (with Floyd's cycle detection) and a Miller-Rabin primality test.

  2. Work the exercises (8 picked)

    Start with Ex 1, Ex 5, Ex 8; 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 47 exercises, rated 10 to M50, and Knuth marks 16 of them with the triangle for recommended. Implement trial division, Pollard rho, Miller-Rabin and a sieve with 64-bit or bignum arithmetic and do these alongside.

Worth your time

  • Exercise 110

    Why composite trial divisors never show up in the output.

    Discuss

  • Exercise 521

    Fermat's method by hand on a five-digit number.

    Discuss

  • Exercise 823▶ Recommended

    The sieve of Eratosthenes and how to do it well. Implement it.

    Discuss

  • Exercise 10M26▶ Recommended

    Selfridge's test for proving primality from the factors of n - 1.

    Discuss

  • Exercise 19M25▶ Recommended

    Pollard's p - 1 idea. Another factoring method to implement.

    Discuss

  • Exercise 22M30▶ Recommended

    Bound the error rate of the probabilistic primality test. The stretch.

    Discuss

  • Exercise 26M25▶ Recommended

    Pocklington's primality certificate.

    Discuss

  • Exercise 3825

    Find the largest 50-digit primes made mostly of one digit. A fun programming exercise with Miller-Rabin.

    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 110No 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 521No 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 823No 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 10M26No 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 19M25No 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 22M30No 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 26M25No 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 3825No 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

Primality testing and the hardness of factoring are the foundation of RSA. Pollard rho is also a neat use of cycle detection.

Before you start
  • 4.5.2 The Greatest Common Divisor
  • 4.3.2 Modular Arithmetic
How to approach it

Implement trial division, Pollard rho (with Floyd's cycle detection) and a Miller-Rabin primality test. Factor some 20-digit numbers. Read the advanced methods for the ideas only.

Common traps
  • Overflow in modular multiplication. Use 128-bit intermediates or bignums.
  • Treating a probabilistic test as deterministic.

Spot a mistake? Report it

Back to week 84