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

07. Induction

08. State Machines — Invariants

09. Recursive Definitions

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

Binary Relations

A binary relation is a mathematical object that maps elements from one set, called the domain, to another set, called the codomain.

Now, let's look at the definition of a function:

Functions are mappings that assign elements from one set (domain) to another (codomain).

The distinction is that in a function, every element should only map to at most one element, so, for example, an element aa in domain AA can only be mapped to bb in codomain BB, not both bb, and cc, etc.

So, a function is a special case of a binary relation.

A function that maps elements in domain AA to elements in codomain BB is denoted as f:ABf : A \rightarrow B.

If a function is a partial function, some elements in the domain can be undefined (some elements in the domain don't have an arrow coming out). For example, f(x)=1x2f(x) = \frac{1}{x^2} does not assign a value to 00.
On the other hand, if every element in the domain is defined, it is called a total function.

Function composition is as simple as taking the value of one function, and passing it to another one:

(gf)(x)=g(f(x))(g \circ f)(x) = g(f(x))

A binary relation RR has a set AA, domain of RR; a set BB, codomain of RR; and a subset of A×BA \times B, the graph of RR (this is the relation part — arrows from AA to BB).

The notation is similar to functions: R:ABR : A \rightarrow B. This is a relation "between AA and BB" (or, "from AA to BB").
If the domain and codomain are the same set AA, we can say that the relation is "on AA".

When a pair (a, b)(a, \ b) is in the graph of RR, it is denoted as a R ba \ R \ b.

The image of a set XX, under a relation RR, is written as R(X)R(X). It is the codomain set.

For example, look at this diagram:

An example of binary relation

XX is the domain, YY is the codomain, graph of RR is {(1,D), (2,C), (3,C)}\{(1, D), \ (2, C), \ (3, C)\}

Range is the actual elements with arrows coming in. In this example, while YY is the codomain, {D, C}\{D, \ C\} is the range.
So, the range is not always equal to codomain — it can be equal to, or smaller than the codomain.

The set of points with an arrow coming in from XX is the R(X)R(X), the image of XX.

We can write it in logical notation as such:

R(X)={bY  aX aRb}R(X) = \{b \in Y \ | \ \exists a \in X \ a R b\}

YY is the codomain set, and bb is an element in it; XX is the domain set, and aa is an element in it.

So, the formula above says that R(X)R(X) is the set of bb in YY such that there exists an aa in XX such that (a, b)(a, \ b) is a pair that's in the graph of RR (remember that's what aRba R b means).

This part itself [aX aRb][\exists a \in X \ a R b] indicates that there is an arrow to bb coming from the set of XX.


The inverse of a relation R:ABR : A \rightarrow B is denoted as R1R^{-1}, and it is the relation from BB to AA. It just flips the arrows around, so the codomain becomes the domain, and the domain becomes the codomain.
R1(x)R^{-1}(x) called the inverse image of xx under RR.

This formula holds true: aRb    bR1aaRb \iff bR^{-1}a
An arrow coming from aa ends in bb, and vice versa, an arrow that ends in bb is coming from aa.


Now, there are some terms that we are going to take a look at:


Here is a nice way to keep these in mind: think of totality, surjection, function, and injection as superheroes who are responsible for inspecting the arrows from one set to another.

Totality is concerned with the domain, surjection is concerned with the codomain. Both of them want at least one arrow.

Function is concerned with the domain, injection is concerned with the codomain. Both of them want at most one arrow.

Bijection always wants one-to-one correspondence.


RR is a function iff R1R^{-1} is an injection.
RR is a surjection iff R1R^{-1} is total.
RR is an injection iff R1R^{-1} is a function.
RR is a bijection iff R1R^{-1} is a bijection.