So far we talked a lot about "rewriting to normal form" as a model of computation. We also discussed how to give meaning to formal languages by mapping them to a semantics. All these notions can be connected, clarified and formalised with the help of a little discrete maths, which we will review now. 1
In fact, we only need to understand the concept of reflexive and transitive (and symmetric) closure of a relation. So lets get started.
I assume that we all understand what a set is, so feel free to jump to the next section.
The basic statement about a set
We also need to be able to say that
We also need to review different ways of defining sets. The simplest one is just to list the elements of a set as in
To illustrate the notation reviewed so far, we have
is the standard notation for the natural numbers.
Above, I am taking
Defining infinite sets inductively is very common and we have seen another example of this when we defined the language exp
of arithmetic expressions.
Another way of defining sets is called comprehension. A definition by comprehension has the form
For example, we may define the set of even numbers as
Here
Exercise: Define the set of odd numbers in the same style.
We can use comprehension to define the so-called cartesian product 2
which is just the set of pairs that can be built by taking elements of
Example: Fractions
More Notation (not so important now, but useful later): If in the above definition we have
If you are familiar with databases then a relation is really very nuch the same as a table in a database. For our purposes, we actually only need tables that have two columns (attributes).
Anyway, we don't need to think about databases at all. The mathematical definition is that a relation3
Notation: By convention, we also write
which we abbreviate to
if there is only one relation discussed at that moment.
Remark: Later we will take
We need to know what it means for a relation to be reflexive, symmetric, and transitive.
Defininition: Assume that
-
is reflexive if $$ xRx $$ for all
$x\in A$ . -
is symmetric if $$ xRy \ \Rightarrow \ yRx$$ for all
$x,y\in A$ . -
is transitive if $$ xRy \ & \ yRz \ \Rightarrow \ xRz$$ for all
$x,y,z\in A$ .
Example:
- The
$<$ -relation on numbers is transitivie but neither reflexive nor symmetric. - The
$\le$ -relation on numbers is reflexive and transitive but not symmetric. - A relation that is symmetric and transitive but not necessarily reflexive is called a partial equivalence relation. The linked article contains some references to applications to the semantics of programming languages.
- The relation
$a\equiv b\ ({\rm mod} \ n)$ of modular arithmetic is reflexive, transitive and symmetric. - The relation of "being siblings" is symmetric but not reflexive (hence also not transitive).
Exercise: Make up your own examples. Family relationshiops are a great source. Try parent, child, ancestor, etc and check each of them for reflexivity, transtivity and symmetry.
Without any doubt, equivalence relations and equivalence classes are one of the most important concepts in all of mathematics. It was discovered surprisingly late, as far as I know by Dedekind around 1880. 4
Definition: An equivalence relation is a relation that is reflexive, transitive and symmetric.
If
To say that the equivalence classes partition
We can now form the set of equivalence classes which is written as
Remark (Partition): Equivalence relations on
Remark (Equivalence relation/partition of a function): Every function
Example: Equality is an equivalence relation. In fact, equality is the smallest equivalence relation. There is also a largest equivalence relation (which is it?).
Notation and Terminology: If
Example: On the integers
Example of fractions and integers: Two famous examples of sets that are sets of equivalence classes are the integers and the fractions.
- The set of non-negative fractions
$\mathbb Q$ is a set of equivalence classes. The set$A$ is$\mathbb N\times\mathbb N_+$ where$N_+$ is the positive integers and the equivalence relation in question is the one which takes care of the fact that, eg, 1/2 = 2/4. - How would you implement integers
$\mathbb Z$ if you had only natural numbers? One way is to define the integers as equivalence classes where$A=\mathbb N\times\mathbb N$ and$(m,n)R(k,l)$ if$m+l=k+n$ . (Exercise: Can you figure out why this works? Can you find a rewriting system in which these equivalence classes have nice normal forms? How would you define addition, etc on these integers?)
The following exercise is crucial to understand equivalence classes.
Exercise: Show that every equivalence relation
- A is the union of its equivalence classes, symbolically,
$A = \bigcup_{a\in A} A/R$ - any two different equivalence classes are disjoint, ie,
$[a]\not=[b] \Rightarrow [a]\cap[b]=\emptyset$
We are almost done. Before we can relate the last lecture about syntax and semantics to the idea of computation as rewriting to normal form, we still need to define the notions of transitive closure and equivalence closure.
The idea of transitive closure is easily explained. Transitive closure is an operation on relations. Given a relation
or, shorter,
There is an elegant way to define the transitive closure
Definition: Assume that
- The transitive closure
$R^+$ of$R$ is the smallest transitive relation containing$R$ . - The reflexive and transitive closure
$R^*$ of$R$ is the smallest reflexive and transitive relation containing$R$ . - The equivalence closure
$\equiv_R$ of$R$ is the smallest reflexive, symmetric, transitive relation containing$R$ .
Remark: Let us now think of
Exercise: Make sense of the last sentence, by reviewing the laws of fractions you learned at school. Explain in our terminology why you were asked at school to cancel fractions.
As I said, I assume that the notion of a function is familiar, either form high-school or from a first semester discrete maths course. But we can review some terminology quickly.
To begin at the beginning, a function
-
single-valued, that is,
$(a,b)\in f$ and$(a,b')\in f$ implies$b=b'$ and is -
total, that is, for all
$a\in A$ there is$b\in B$ such that$(a,b)\in f$ .
These two properties together say that for all
We will also need further properties that functions may have. A function is called
-
injective, or one-to-one, if
$f(a)=f(a')$ implies that$a=a'$ , -
surjective, or onto, if for all
$b\in B$ there is$a\in A$ such that$f(a)=b$ , - bijective, if it is injective and surjective.
If we have a bijection between two sets, then the two sets can be considered equal up to the names of their elements. Intuitively, a bijection is like a dictionary that relates every word in one language to exactly one corresponding word in the other.
We will also need that a function
can be extended to subsets of
- the direct image of $X\subseteq A$ under $f$ as
$\ \ f[X]\ \stackrel{\rm def}{=}\ {f(x) \mid x\in X}$ - the inverse image of $Y\subseteq B$ under $f$ as
$\ \ f^{-1}(Y)\ \stackrel{\rm def}{=}\ {a\in A \mid f(a)\in Y}$
Remark (Partition of a function): Every function
Footnotes
-
I assume that students had a one semester course on discrete maths. But in many discrete-maths-texts relations only appear in the "second semester" part. For example in the widely used book "Discrete Mathematics and Its Application" by Rosen, relations only start on page 374. Btw, the book could be a good place to review some discrete maths. ↩
-
This is called "cartesian" product in honour of Descartes, who, in his "Geometry", about which we talked already, invented the represenation of points in the plane by $x$ and $y$-coordinates, that is, the representation of points as elements of $\mathbb R\times \mathbb R$. ↩
-
It is common to abbreviate $A\times A$ by $A^2$. If we need to emphasise that $R$ is a susbset of $A^2$ as opposed to a subset of $A^n$ for some other $n\in\mathbb N$, we call $R$ a "2-ary" relation or a binary relation. ↩
-
More information is available in this article on The Early Development of Set Theory. By the way, Dedekind was also the guy who defined integers and rationals as equivalence classes. You are asked to work on this in this exercise. ↩
-
In symbolic notaion, a partition of $A$ is a collection $(A_i){i\in I}$ of subsets of $A$ such that $i\not=j \ \Rightarrow A_i\cap A_j=\emptyset$ and $\bigcup{i\in I} A_i = A$. ↩