“mcs” — 2017/6/5 — 19:42 — page i — #1
Mathematics for Computer Science
revised Monday 5th June, 2017, 19:42
Eric Lehman
Google Inc.
F Thomson Leighton
Department of Mathematics
and the Computer Science and AI Laboratory,
Massachussetts Institute of Technology;
Akamai Technologies
Albert R Meyer
Department of Electrical Engineering and Computer Science
and the Computer Science and AI Laboratory,
Massachussetts Institute of Technology
2017, Eric Lehman, F Tom Leighton, Albert R Meyer. This work is available under the
terms of the Creative Commons Attribution-ShareAlike 3.0 license.
,“mcs” — 2017/6/5 — 19:42 — page ii — #2
, “mcs” — 2017/6/5 — 19:42 — page iii — #3
Contents
I Proofs
Introduction 3
0.1 References 4
1 What is a Proof? 5
1.1 Propositions 5
1.2 Predicates 8
1.3 The Axiomatic Method 8
1.4 Our Axioms 9
1.5 Proving an Implication 11
1.6 Proving an “If and Only If” 13
1.7 Proof by Cases 15
1.8 Proof by Contradiction 16
1.9 Good Proofs in Practice 17
1.10 References 19
2 The Well Ordering Principle 29
2.1 Well Ordering Proofs 29
2.2 Template for WOP Proofs 30
2.3 Factoring into Primes 32
2.4 Well Ordered Sets 33
3 Logical Formulas 47
3.1 Propositions from Propositions 48
3.2 Propositional Logic in Computer Programs 52
3.3 Equivalence and Validity 54
3.4 The Algebra of Propositions 57
3.5 The SAT Problem 62
3.6 Predicate Formulas 63
3.7 References 68
4 Mathematical Data Types 97
4.1 Sets 97
4.2 Sequences 102
4.3 Functions 103
4.4 Binary Relations 105
4.5 Finite Cardinality 109
, “mcs” — 2017/6/5 — 19:42 — page iv — #4
iv Contents
5 Induction 131
5.1 Ordinary Induction 131
5.2 Strong Induction 140
5.3 Strong Induction vs. Induction vs. Well Ordering 147
6 State Machines 167
6.1 States and Transitions 167
6.2 The Invariant Principle 168
6.3 Partial Correctness & Termination 176
6.4 The Stable Marriage Problem 181
7 Recursive Data Types 211
7.1 Recursive Definitions and Structural Induction 211
7.2 Strings of Matched Brackets 215
7.3 Recursive Functions on Nonnegative Integers 219
7.4 Arithmetic Expressions 221
7.5 Games as a Recursive Data Type 226
7.6 Induction in Computer Science 230
8 Infinite Sets 257
8.1 Infinite Cardinality 258
8.2 The Halting Problem 267
8.3 The Logic of Sets 271
8.4 Does All This Really Work? 275
II Structures
Introduction 299
9 Number Theory 301
9.1 Divisibility 301
9.2 The Greatest Common Divisor 306
9.3 Prime Mysteries 313
9.4 The Fundamental Theorem of Arithmetic 315
9.5 Alan Turing 318
9.6 Modular Arithmetic 322
9.7 Remainder Arithmetic 324
9.8 Turing’s Code (Version 2.0) 327
9.9 Multiplicative Inverses and Cancelling 329
9.10 Euler’s Theorem 333
9.11 RSA Public Key Encryption 338
Mathematics for Computer Science
revised Monday 5th June, 2017, 19:42
Eric Lehman
Google Inc.
F Thomson Leighton
Department of Mathematics
and the Computer Science and AI Laboratory,
Massachussetts Institute of Technology;
Akamai Technologies
Albert R Meyer
Department of Electrical Engineering and Computer Science
and the Computer Science and AI Laboratory,
Massachussetts Institute of Technology
2017, Eric Lehman, F Tom Leighton, Albert R Meyer. This work is available under the
terms of the Creative Commons Attribution-ShareAlike 3.0 license.
,“mcs” — 2017/6/5 — 19:42 — page ii — #2
, “mcs” — 2017/6/5 — 19:42 — page iii — #3
Contents
I Proofs
Introduction 3
0.1 References 4
1 What is a Proof? 5
1.1 Propositions 5
1.2 Predicates 8
1.3 The Axiomatic Method 8
1.4 Our Axioms 9
1.5 Proving an Implication 11
1.6 Proving an “If and Only If” 13
1.7 Proof by Cases 15
1.8 Proof by Contradiction 16
1.9 Good Proofs in Practice 17
1.10 References 19
2 The Well Ordering Principle 29
2.1 Well Ordering Proofs 29
2.2 Template for WOP Proofs 30
2.3 Factoring into Primes 32
2.4 Well Ordered Sets 33
3 Logical Formulas 47
3.1 Propositions from Propositions 48
3.2 Propositional Logic in Computer Programs 52
3.3 Equivalence and Validity 54
3.4 The Algebra of Propositions 57
3.5 The SAT Problem 62
3.6 Predicate Formulas 63
3.7 References 68
4 Mathematical Data Types 97
4.1 Sets 97
4.2 Sequences 102
4.3 Functions 103
4.4 Binary Relations 105
4.5 Finite Cardinality 109
, “mcs” — 2017/6/5 — 19:42 — page iv — #4
iv Contents
5 Induction 131
5.1 Ordinary Induction 131
5.2 Strong Induction 140
5.3 Strong Induction vs. Induction vs. Well Ordering 147
6 State Machines 167
6.1 States and Transitions 167
6.2 The Invariant Principle 168
6.3 Partial Correctness & Termination 176
6.4 The Stable Marriage Problem 181
7 Recursive Data Types 211
7.1 Recursive Definitions and Structural Induction 211
7.2 Strings of Matched Brackets 215
7.3 Recursive Functions on Nonnegative Integers 219
7.4 Arithmetic Expressions 221
7.5 Games as a Recursive Data Type 226
7.6 Induction in Computer Science 230
8 Infinite Sets 257
8.1 Infinite Cardinality 258
8.2 The Halting Problem 267
8.3 The Logic of Sets 271
8.4 Does All This Really Work? 275
II Structures
Introduction 299
9 Number Theory 301
9.1 Divisibility 301
9.2 The Greatest Common Divisor 306
9.3 Prime Mysteries 313
9.4 The Fundamental Theorem of Arithmetic 315
9.5 Alan Turing 318
9.6 Modular Arithmetic 322
9.7 Remainder Arithmetic 324
9.8 Turing’s Code (Version 2.0) 327
9.9 Multiplicative Inverses and Cancelling 329
9.10 Euler’s Theorem 333
9.11 RSA Public Key Encryption 338