Bite-Sized Mathematics for Computer Science

Notes on MIT's 6.042J

Eda Eren
Table of Contents

Introduction

Prerequisites & Resources

Unit 1: Proofs

00. Introduction to Proofs

01. (Two) Proof Methods

02. The Well Ordering Principle

03. Logic & Propositions

04. Quantifiers and Predicate Logic

05. Sets

06. Binary Relations

07. Induction

08. State Machines — Invariants

10. Infinite Sets

Unit 2: Structures

11. GCDs

12. Congruences

13. Euler's Theorem

14. RSA Encryption

15. Digraphs: Walks and Paths

16. Directed Acyclic Graphs

17. Partial Orders and Equivalence

18. Degrees & Isomorphism

19. Coloring & Connectivity

20. Trees

21. Stable Matching

Unit 3: Counting

22. Sums & Products

23. Asymptotics

24. Counting with Bijections

25. Repetitions & Binomial Theorem

26. Pigeonhole Principle, Inclusion-Exclusion

Unit 4: Probability

27. Intro to Discrete Probability

28. Conditional Probability

29. Independence & Causality

30. Random Variables, Density Functions

31. Expectation

32. Deviation: Markov & Chebyshev Bounds

33. Sampling & Confidence

34. Random Walks & PageRank

Recursive Definitions

We can define a recursive definition as a way of constructing new data elements from previous ones, i.e., defining something in terms of a simpler version of the same thing.

There are two parts to it: base case(s) and constructor case(s).

We can look at a binary string as an example. Usually, a binary string is defined as a sequence of 00's and 11's. An example of the string 10111011 is the tuple (1, 0, 1, 1)(1, \ 0, \ 1, \ 1).
But, with recursive definition, we can denote it as nested pairs, such as 1,0,1,1,λ〉〉〉〉\textlangle1, \textlangle0, \textlangle 1, \textlangle 1, \lambda \textrangle \textrangle \textrangle \textrangle, where λ\lambda denotes the empty string — in this case, the base case.

A well-known example of a recursive function is the Fibonacci numbers:

F(0)=0F(0) = 0
F(1)=1F(1) = 1
F(n)=F(n1)+F(n2)for n2F(n) = F(n - 1) + F(n - 2) \quad \text{for }n \geq 2


Let's now look at another example.
Let's say we want to define a set of strings, MM, containing left and right brackets that match up: M{ ], [ }M \subseteq \{ \ ], \ [ \ \}^*.
Okay, the notation looks funky, but it's a way to denote a set of finite strings, using an asterisk.

So, the base case is the empty string λ\lambda, if we concatenate it to a string it doesn't change anything.

The constructor we have is this:

if s, tM then [s]tM\text{if }s, \ t \in M \text{ then } [s]t \in M

Okay, so what does it mean?

It says that if ss and tt are strings of brackets in MM, then the string [s]t[s]t is also in MM.

Let's see it in action.

We have the base case, that is, both ss and tt are empty. What we're left with is just a left and a right bracket: [ ].
If ss is [ ], and tt is empty, we have [ [ ] ] as a result.
If ss is empty, and tt is [ ], we have [ ] [ ].
And, if both ss and tt are [ ], we have [ [ ] ] [ ].
We can also imagine ss being [ [ ] ], and tt being empty, then we have [ [ [ ] ] ].

The cases we defined so far are these:

string values
[] s=λ, t=λs = \lambda, \ t = \lambda
[[]] s=[ ], t=λs = [ \ ], \ t = \lambda
[][] s=λ, t=[ ]s = \lambda, \ t = [ \ ]
[[]][] s=[ ], t=[ ]s = [ \ ], \ t = [ \ ]
[[[]]] s=[ [ ] ], t=λs = [ \ [ \ ] \ ], \ t = \lambda

Now, it can go on forever. But, how do we know that we will get matching brackets?

Well, one way we can look at it is this: if a string starts with ], then it is not going to be a matching brackets string because it has already lost starting with ], it has no pair.

We can assume that strings that start with ] won't be in MM.

Now, one thing we know is that the only way to get elements in MM is by applying the constructor, or it's going to come from the base case itself. This is called the extremal clause, everything that's in MM is obtained from the base case and the constructor.
Our base case for this matching brackets example is the empty sequence, so it definitely doesn't start with ] because it doesn't even start.
And, our constructor rule is [s]t[s]t, which also doesn't start with ], therefore a string starting with ] is not going to be in MM.


Structural induction is a method for proving that all the elements of a recursively defined data type have some property.

So, it is proving that a property P(x)P(x) holds for all xx in recursively defined set RR. In order to do that, we need to prove that every element in each base case in RR has the property (P(b)P(b) for each base case bb), also that each constructor holds the property (P(c(x))P(c(x)) for each constructor cc) as well.

Let's see it using our matching brackets example.

Lemma: Every string ss in MM has the same number of ]'s and ['s.
Let EQEQ be the set of strings with the same number of ]'s and ['s.
We assume MEQM \subseteq EQ.
Induction hypothesis P(s)P(s) is that sEQs \in EQ.
The base case is s=λs = \lambda, which means that MM is an empty set. The property holds because we have 00 left brackets and 00 right brackets, so we have an equal number of brackets. So, P(λ)P(\lambda) is true. ✅
The constructor step was in the form of [s]t[s]t, but we're using the variable ss to stand for the string, so let's use rr instead. In this case, the constructor step is [r]t[r]t.
The number of ]'s in ss = (the number of ]’s in r)+(the number of ]’s in t)+1(\text{the number of } ]\text{'s in }r) + (\text{the number of } ]\text{'s in }t) + 1
The number of ['s in ss = (the number of [’s in r)+(the number of [’s in t)+1(\text{the number of } [\text{'s in }r) + (\text{the number of } [\text{'s in }t) + 1
Because of P(r)P(r), the number of left and right brackets in rr have to be equal.
Likewise, because of P(t)P(t), the number of left and right brackets in tt have to be equal as well.
Then, ((the number of ]’s in r)+(the number of ]’s in t)+1)=((the number of [’s in r)+(the number of [’s in t)+1)\big((\text{the number of } ]\text{'s in }r) + (\text{the number of } ]\text{'s in }t) + 1\big) = \big((\text{the number of } [\text{'s in }r) + (\text{the number of } [\text{'s in }t) + 1\big)
Therefore, we realize that P(s)P(s) is true: (the number of ]’s in s)=(the number of [’s in s)(\text{the number of ]'s in } s) = (\text{the number of ['s in } s)
So, by structural induction, sM  sEQ\forall s \in M \ \ s \in EQ.
MEQ. M \subseteq EQ. \ \blacksquare