# Lecture 30: relations and start of finite automata

• Relations
• relations on multiple sets
• relations on two different sets
• relations generalize functions
• xRy notation
• key terms: equivalence relation, equivalence class, quotient of a set, closure
• Finite automata
• motivation
• example
• definitions: Σ  * , DFA

## More on Relations

• (review) a binary relation R on a set S is a set of pairs of elements of S. In other words, R ⊆ S × S. In other words, R is a set of edges in a directed graph with vertices S.

• Relations can relate more than two sets. In general, a relation on S, T, U, is a subset of S × T × U × ⋯.

• Example: a database table can be thought of as a set of rows; each row can be thought of as a tuple. Thus the table is a relation on S, T, U, where S is the set of possible values for the first column, T is the set of possible values for the second column, and so on.

• notation: if R is a binary relation and (x, y) ∈ R we write xRy. this generalizes relations like " = " and "".

• relations generalize functions. You can think of a function F as a relation: yFx if y = F(x). Relation composition (as defined last lecture) is then the same as function composition.

## Equivalence relations

(review) if R is a relation on a set S then

• R is reflexive if for all x ∈ S, xRx.
• R is symmetric if for all x and y ∈ S, if xRy then yRx
• R is transitive if for all x, y, and z ∈ S, if xRy and yRz then xRz.

A relation satisfying all three properties is called an equivalence relation. Equivalence relations "act like" the  =  relation.

If you ever write a function as part of a program and call it something like "equals" or "equiv", you should check that it actually defines an equivalence relation!

### Equivalence classes

Recall when discussing number theory, we defined the equivalence class of x (written [x]m) as $\{Y \in \N | x \equiv y (mod~m)\}$.

This construction generalizes to any equivalence relation. If R is an equivalence relation on S, and if x ∈ S, then we can define the equivalence class of x ([x]R) as {y ∈ SxRy}.

The set of all equivalence classes of S (using the relation R) is called the quotient of S by R, or simply S / R (read "S mod R").

If you think of R as a graph, it must consist of a collection of a collection of subgraphs, each of which is completely connected; these subgraphs are the equivalence classes of S / R.

# Automata

For the last portion of the lecture we started discussing finite automata. Finite automata are a very simple way to model certain computations that take strings as input and output yes or no.

Key definitions:

• An alphabet (usually denoted Σ ) is a finite set. The elements of the alphabet are called characters.
• common alphabets include {0, 1}, {a, b, …, z}, the set of all ASCII characters, the set of all Unicode characters, the set of all hexadecimal digits, etc.
• If Σ  is an alphabet, then Σ  *  is the set of strings of characters from Σ .
• example: 0010110 ∈ {0, 1} *
• A language (also called a problem or a specification) is a subset of Σ  * .
• example: the set of even length strings
• A deterministic finite automaton (plural automata) (abbreviated DFA) is a 5-tuple (Q, Σ , δ, q0, F) where
• Q is a finite set. Elements of Q are called states
• Σ  is an alphabet
• δ: Q × Σ  → Q is called the transition function
• q0 ∈ Q is called the initial state
• F ⊆ Q is called the set of accepting (or final) states
• Example: the image on the right (click image for LaTeX source) depicts M = (Q, Σ, δ, q0, F) where:
• Q = {q1, q2}, Σ  = {0, 1}, q0 = q1, and F = {q1}
• δ is given by
• δ: (q1, 1)↦q1; δ: (q1, 0)↦q2
• δ: (q2, 1)↦q2; δ: (q2, 0)↦q1
• Note: because δ is a function, there must be a transition from every state on every character.

• A machine processes a string one character at a time, starting in the start state and following a transition for each character until it consumes the whole string. After it processes the string, it accepts if it ends in a final state, and it rejects otherwise.

• Convince yourself that the above machine accepts all (and only) the strings in the language L = {xx has an even number of 0's}.