TAOCP Vol 2: Seminumerical Algorithms · Week 84
TAOCP 4.5.4 Factoring into Primes
Updated
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.
This week's steps
3 stepsRead §4.5.4 Factoring into Primes
Implement trial division, Pollard rho (with Floyd's cycle detection) and a Miller-Rabin primality test.
Start with Ex 1, Ex 5, Ex 8; log what you solve below.
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 22M30▶ Recommended
Bound the error rate of the probabilistic primality test. The stretch.
Exercise 3825
Find the largest 50-digit primes made mostly of one digit. A fun programming exercise with Miller-Rabin.
Your log
Sign in to log the exercises you work: number, rating, how far you got.
Your notes
Only youSign 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 postsQuestions 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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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```spoilerblock.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.