Try   HackMD

Revision Guide: Discrete Mathematics (Logic and Relations)

The aim of this note is to review just enough discrete mathematics in order to be able to understand the concepts of

  • "abstraction as a quotient by an equivalence relation" [1] and
  • "rewriting to normal form" [2] as a model of computation.
  • "meaning of a formal languages as a mapping to a semantic domain". [3]

All these notions can be connected, clarified and formalised with the help of a little discrete maths, which we will review now. [4]

For the main part, we only need to understand the concept of reflexive and transitive (and symmetric) closure of a relation. But let us get started with a review of some helpful notation from set theory and logic.

Logic

Set Theory

Relations

If you are familiar with databases then a (finite) relation is really very much the same as a table in a database. For our purposes, we actually only need binary relations, that is, tables that have two columns (attributes).

Anyway, we don't need to think about databases. The mathematical definition is that a relation[5]

R on a set
A
is a subset of
A×A
, in symbols

RA×A.

Notation: By convention, we also write

aRb instead of
(a,b)R
, or also
R(a,b)
, which in turn may be abbreviated to
Rab
. When drawing pictures we also write this as

aRb

which we abbreviate to

ab

if there is only one relation around anyway.

Remark: Later we will take

R to be the relation of "one-step computation", or rewriting, as we called it, but for now we make no assumptions on
A
and
R
.

We need to know what it means for a relation to be reflexive, symmetric, and transitive.

Defininition: Assume

RA×A. The relation
R
is said to be

  • reflexive if

    xRx for all
    xA
    .

  • symmetric if

    xRy  yRx for all
    x,yA
    .

  • transitive if

    xRy & yRz  xRz for all
    x,y,zA
    .

Example:

  • The
    <
    -relation on numbers is transitivie but neither reflexive nor symmetric.
  • The
    -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
    ab (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:

  • Family relationships and social networks: Check parent, ancestor, sibling, having the same parents, friend, following, being a member of the same group, etc for reflexivity, transtivity and symmetry.

Exercise:

  • Is it true that a relation which is symmetric and transitive is also reflexive?
  • Is the empty relation symmetric and transitive? Is it reflexive?

Transitive Closure

We have seen examples of transitive closure above.

  • Ancestor is the transitive closure of parent.
  • On natural numbers (or integers), "greater than" is the transtive closure of the successor relation. [6]:

More generally, given a relation

R, two elements
a,b
are in the transitive closure
R+
of
R
if there is a sequence of elements
a1,an
such that

aRa1,a1Ra2,anRb

or, shorter,

aRa1Ra2anRb.

Remark:

R+ can be defined recursively as follows.

  • aR+b
    if
    aRb
    ,
  • aR+b
    if there is
    c
    such that
    aRc
    and
    cR+b
    .

Note how this is similar to a recursive definition in, say, Haskell.

Another way of expressing the same idea is as follows.

Definition: Let

RA×A.

  • 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
    .

Remark: If

R is a relation of "one-step computation" we often write
instead of
R
and
for the reflexive and transitive closure.

Exercise: Let

(A,R) be an ARS. The relation
R
can be represented by an adjacency matrix
M
defined as
Mab={1if (a,b)R0if (a,b)R
Describe an algorithm that computes the transitive closure of
R
via matrix multiplication.

Equivalence Relations

Equivalence relations and equivalence classes are one of the most important concepts in mathematics and computer science. It was discovered surprisingly late, as far as I know by Dedekind around 1880. [7] For a general introduction see my notes on What is Abstraction?

Definition: An equivalence relation is a relation that is reflexive, transitive and symmetric. The equivalence closure

R of
R
is the smallest reflexive, symmetric, transitive relation containing
R
.

Remark: We will be interested in the situation where

R specifies the equational properties of a computational problem and
R
describes a non-determinstic algorithm solving the problem.

Notation and Terminology: If

R is an equivalence relation it is often written as
or
or any other symbol that emphasises the analogy with equality. If we write
instead of
R
, we write
for the equivalence closure

Equivalence relations solve the problem of how to account for the fact that two things can be considered equal and different at the same time.

For example,

2+3 and
1+4
are different as expressions, but they are equal as numbers. Now we can just say they are equivalent wrt an appropriate equivalence relation.

Example (fractions): Define

abcd if
ad=bc
. Show that every fraction is equivalent to its simplified fraction.

Example (modular arithmetic): Let

n2 be a natural number. Define
ab
if there is an integer
i
such that
ba=in
. Show that
abcda+cb+dabcdacbd
The relation
is often called congruence modulo
n
. Congruence relations are equivalence relations that satisfy additional compatibility properties with operations such as the two above for addition and multiplication.

Example (integers): Define an INTEGER as a pair

(n,m) of natural numbers. Define
(n,m)(n,m)
if
n+m=n+m
. Define zero as
(0,0)
and
(n,m)+(n,m)=(n+n,m+m)
. Show how to define negation on INTEGERs and show that it satisfies the usual equations one would expect from integers.

Quotienting by an Equivalence Relation

The purpose of an equivalence relation is that it makes precise when it is safe to consider two different things equal. In one of the examples above, we defined an equivalence relation

such that
3264
. It is more common to write
32=64
. In this section we will see how to give this notation a rigorous mathematical foundation.

If

is an equivalence relation on
A
, then
partitions
A
into equivalence classes. For
aA
, the equivalence class of
a
is denoted by
[a]
or
[a]
and defined as

[a]={bAab}

To say that the equivalence classes partition

A is to say that equivalences classes are disjoint and cover all of
A
. We will come back to this below.

We can now form the set of equivalence classes which is written as

A/R and defined as

A/ =def {[a]aA}

Remark (Partition): Equivalence relations on

A are in bijective correspondence with partitions of
A
. A partition of
A
is a set of subsets of
A
that are pairwise disjoint and cover all of
A
.[8] Given an equivalence relation, its equivalence classes form a partition. Conversely, every partition defines the equivalence relation of "being in the same part".

Remark (Equivalence relation/partition of a function): Every function

f:AB defines an equivalence relation via
aaf(a)=f(a)
. In other words,
f
partitions
A
into the subsets of elements that are identified by
f
.

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: The set

A/ is also called
A
modulo
or
A
quotiented by
or the quotient of
A
by
.

Let us review the examples above.

Example (fractions): The set of non-negative fractions

Q can be implemented as a set of equivalence classes. The set
A
is
N×N+
where
N+
is the positive integers and the equivalence relation in question is the one (defined above) which takes care of the fact that, eg, 1/2 = 2/4.

Example (modular arithmetic): On the integers

Z, the relation
ab
of congruence modulo
n
is an equivalence relation. The set of equivalence classes is denoted by
Z/nZ
. The operation of "dividing by
nZ
" has some properties similar to division on numbers, see eg the Chinese Remainder Theorem which explains some of the terminology just introduced.

Example (integers): The set of integers can be represented as a quotient of

N×N by an equivalence reation (defined above).

The following exercise is crucial to understand equivalence classes.

Exercise: Show that every equivalence relation

on
A
partitions
A
, that is,

  • A is the union of its equivalence classes, symbolically,
    A=aAA/R
  • any two different equivalence classes are disjoint, ie,
    [a][b][a][b]=

Functions

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

f:AB is often defined to be a relation
fA×B={(a,b)aA,bB}
, which, moreover, is

  • single-valued, that is,
    (a,b)f
    and
    (a,b)f
    implies
    b=b
    and is
  • total, that is, for all
    aA
    there is
    bB
    such that
    (a,b)f
    .

These two properties together say that for all

aA there is one and only one related
bB
and this is the element that is, by convention, written as
f(a)
.

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
    bB
    there is
    aA
    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

f:AB

can be extended to subsets of

A and
B
. We define

  • the direct image of
    XA
    under
    f
    as
      f[X] =def {f(x)xX}
  • the inverse image of
    YB
    under
    f
    as
      f1(Y) =def {aAf(a)Y}

Remark (Partition of a function): Every function

f:AB defines a partition
f1(b)bB
on
A
. The sets
f1(b)
are sometimes known as the fibres over
b
.

Isomorphisms

Finally, we bring everything together. First a definition.

Definition (isomorphism): An isomorphism is a function

f which has an inverse, that is, there is a function
g
such that
f(g(y))=y
and
g(f(x))=x
.

Exercise: Show that a function is an isomorphism if and only if it is bijective.

The reason we prefer the definition of isomorphism as a map that has an inverse is that it is more abstract and also applies to situations other than sets and functions.

Each of the examples above (fractions, modulo arithmetic, integers) fits into the following picture, where the equivalence

and
[]
have been defined above, the horizontal arrow is an isomorphism,
L
and
D
are indicated in the table below and
[[]]
is left as an exercise.

L
D
fractions
N×N+
Q
modulo arithmetic
Z
Z/nZ
integers
N×N
Z

In the case of fractions,

Q is often defined to coincide with
L/
. In the other cases the domain
D
has an independent definition and the horizontal ismorphism is not an identity, formally speaking. But we can treat it as an identity as all the structure is preserved and only the data is represented in a different way.


  1. What is Abstraction? ↩︎

  2. Rewriting and the Call Stack. ↩︎

  3. Operational and Denotational Semantics. ↩︎

  4. 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. ↩︎

  5. It is common to abbreviate

    A×A by
    A2
    . If we need to emphasise that
    R
    is a susbset of
    A2
    as opposed to a subset of
    An
    for some other
    nN
    , we call
    R
    a "2-ary" relation or a binary relation. ↩︎

  6. What about fractions? ↩︎

  7. 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. ↩︎

  8. In symbolic notaion, a partition of

    A is a collection
    (Ai)iI
    of subsets of
    A
    such that
    ij AiAj=
    and
    iIAi=A
    . ↩︎