#separator:tab
#html:true
#notetype:Basic
#tags column:3
#deck:cracked.guide::TAOCP Vol 1::1.2.4 Integer Functions and Elementary Number Theory
#columns:Front	Back	Tags
TAOCP §1.2.4 Integer Functions and Elementary Number Theory: what does it cover?	Floor, ceiling, the mod operation defined for any real numbers, and the basics of congruences: divisibility, primes, relatively prime numbers, and Fermat's theorem.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::about
TAOCP §1.2.4: why does it matter?	Floor and mod show up in every array index calculation, hash function, ring buffer and pagination bug you will ever write. Knuth's definition of mod for negative numbers is worth comparing with how your favorite language does it, because they differ.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::why
TAOCP §1.2.4, a common trap: “Assuming floor(-x) = -floor(x).” What's the catch?	It does not.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::trap
TAOCP §1.2.4, a common trap: “Assuming C's % is Knuth's mod.” What's the catch?	For negative operands it is not.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::trap
TAOCP §1.2.4, exercise 4 (rated M10, recommended): what is it asking?	Relate the floor of -x to the ceiling of x. The identity behind half the off-by-one fixes you will ever write.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 6 (rated 20, recommended): what is it asking?	Decide which floor and ceiling of square root identities really hold.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 8 (rated 00): what is it asking?	Quick mod values with negative operands. Compare each one with what % gives in your language.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 10 (rated 10, recommended): what is it asking?	Mod with non-integer and negative arguments under Knuth's definition.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 14 (rated 12, recommended): what is it asking?	Combine two remainders into one. A tiny Chinese remainder problem.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 19 (rated M10, recommended): what is it asking?	Prove modular inverses exist using extended Euclid. The basis of division mod m.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 35 (rated M20, recommended): what is it asking?	Show that nested integer divisions can be flattened. Why floor((x+m)/n) does not care whether x was floored first.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4, exercise 37 (rated M30, recommended): what is it asking?	Evaluate a floor sum in closed form, with the gcd showing up. The stretch.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercise
TAOCP §1.2.4: how many exercises, and how are they rated?	49 exercises, rated 00 to HM46.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::exercises
TAOCP §1.2.4: what should you be comfortable with first?	<ul><li>1.2.2 Numbers, Powers, and Logarithms</li></ul>	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::prereqs
TAOCP §1.2.4: how should you work through it?	Work every identity about floor and ceiling with a few positive and negative examples. Then write a short program in C or Python comparing x mod y for negative x in Knuth's definition versus your language's % operator. Read the congruence material with pencil; it returns in Vol 2 chapter 4.	cracked.guide cracked.guide::phase::taocp-1 cracked.guide::section::1.2.4 cracked.guide::kind::approach
