Cartesian Product and Relations - School of Mathematical Sciences

Notes for Science and Engineering Foundation Discrete Mathematics
by
Robin Whitty BSc PhD CMath FIMA
2009/2010
Contents
1
Introduction
1
1.1
2
The Laws of Arithmetic . . . . . . . . . . . . . . . . . . . . . . .
2 Polynomial Arithmetic
5
2.1
Laws of arithmetic for polynomials . . . . . . . . . . . . . . . . .
5
2.2
Powers of polynomials . . . . . . . . . . . . . . . . . . . . . . .
6
3 Matrix Arithmetic
3.1
3.2
9
Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
3.1.1
Addition and subtraction . . . . . . . . . . . . . . . . . .
9
3.1.2
Scalar multiplication . . . . . . . . . . . . . . . . . . . .
10
3.1.3
Vector Multiplication . . . . . . . . . . . . . . . . . . . .
10
3.1.4
Matrix Multiplication . . . . . . . . . . . . . . . . . . . .
11
Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . .
11
3.2.1
Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
3.2.2
Addition . . . . . . . . . . . . . . . . . . . . . . . . . .
12
3.2.3
Scalar multiplication . . . . . . . . . . . . . . . . . . . .
13
3.2.4
Matrix multiplication . . . . . . . . . . . . . . . . . . . .
13
3.2.5
Laws of arithmetic for matrices . . . . . . . . . . . . . .
14
3.2.6
Matrix transpose . . . . . . . . . . . . . . . . . . . . . .
14
4 Propositional Logic
4.1
15
Arithmetic with propositions . . . . . . . . . . . . . . . . . . . .
16
Disjunction: OR, ∨ (like ‘+’) . . . . . . . . . . . . . . .
16
4.1.1
i
CONTENTS
ii
5
6
4.1.2
Conjunction: AND, ∧ (like ‘×’) . . . . . . . . . . . . . .
17
4.1.3
Logical equivalence: ≡ (like ‘=’) . . . . . . . . . . . . .
18
4.1.4
Negation: ¬ (like unary ‘−’) . . . . . . . . . . . . . . . .
18
4.2
Laws of arithmetic for propositions . . . . . . . . . . . . . . . . .
19
4.3
Normal Form . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
Truth Tables
21
5.1
Enumerated Form Arithmetic Tables . . . . . . . . . . . . . . . .
22
5.2
Logic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
5.3
Proving Logical Equivalence . . . . . . . . . . . . . . . . . . . .
25
5.4
Logical Implication . . . . . . . . . . . . . . . . . . . . . . . . .
27
Set Theory
29
6.1
The Membership Predicate . . . . . . . . . . . . . . . . . . . . .
30
6.2
Specifying a set . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
6.3
The equality and subset predicates . . . . . . . . . . . . . . . . .
33
6.4
A set of cardinality n has 2 n subsets . . . . . . . . . . . . . . . .
34
6.5
The Arithmetic of sets . . . . . . . . . . . . . . . . . . . . . . .
35
6.5.1
Union, ∪ (like ‘∨’) . . . . . . . . . . . . . . . . . . . . .
35
6.5.2
Intersection, ∩ (like ‘∧’) . . . . . . . . . . . . . . . . . .
35
6.5.3
Difference: \ (like ‘¬ ⇒’) . . . . . . . . . . . . . . . . .
36
Laws of arithmetic for propositions . . . . . . . . . . . . . . . . .
36
6.6
7
8
Venn Diagrams and Region Tables
39
7.1
The Universal set . . . . . . . . . . . . . . . . . . . . . . . . . .
39
7.2
Venn diagrams and complementation . . . . . . . . . . . . . . . .
40
7.2.1
The complementation laws . . . . . . . . . . . . . . . . .
42
7.2.2
Venn diagrams for two sets . . . . . . . . . . . . . . . . .
42
7.3
Venn diagrams for three sets and truth tables again . . . . . . . .
46
7.4
Region tables . . . . . . . . . . . . . . . . . . . . . . . . . . . .
47
Cartesian Product and Relations
51
CONTENTS
8.1
8.2
1
The Cartesian Product . . . . . . . . . . . . . . . . . . . . . . . .
51
8.1.1
‘Laws of arithmetic’ and closure . . . . . . . . . . . . . .
52
Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
8.2.1
Graphs of relations . . . . . . . . . . . . . . . . . . . . .
54
8.2.2
Properties of relations . . . . . . . . . . . . . . . . . . .
55
8.2.3
Special types of relations . . . . . . . . . . . . . . . . . .
57
2
CONTENTS
50
CONTENTS
Chapter 8
Cartesian Product and Relations
Since Cartesian geometry gave us the idea of the x-y plane, over 400 years ago,
the idea of working with pairs of numbers has become a central to much of mathematics. The pairs (x, y) that are coordinates of points in the plane consist of real
numbers from the set R and are not of direct concern in discrete mathematics; but
we will see that we can make pairs using any sets.
8.1
The Cartesian Product
Suppose we have a universal set U and subsets A and B of U. The cartesian
product of A and B, denoted by A × B and said “A cross B”, is defined to be the
set of all pairs (a, b) with a ∈ A and b ∈ B:
A × B = {(a, b) | a ∈ A ∧ b ∈ B}.
Note that the pairs are ordered: (a, b) , (b, a) unless a = b. So, in particular,
{a, b} is not the same as (a, b): one is a set of cardinality 2 and the order in which
we list the elements does not matter; the other is a pair and the order does matter.
E.g. if A = {1, 2, 3} and B = {p, q} then
(a) A × B = {(1, p), (1, q), (2, p), (2, q), (3, p), (3, q)};
(b) B × A = {(p, 1), (p, 2), (p, 3), (q, 1), (q, 2), (q, 3)};
(c) A × A = {(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3)};
(d) B × B = {(p, p), (p, q), (q, p), (q, q)};
(e) (B × B) × B = { (p, p), p , (p, p), q , (p, q), p , (p, q), q ,
(q, p), p , (q, p), q , (q, q), p , (q, q), q };
(f) B × (B × B) = { p, (p, p) , q, (p, p) , p, (p, q) , q, (p, q) ,
p, (q, p) , q, (q, p) , p, (q, q) , q, (q, q) };
51
52
CHAPTER 8. CARTESIAN PRODUCT AND RELATIONS
We may visualise the cartesian product as a set of points in the plane, as in figure 8.1 for A × B in the above example. We should be careful about interpreting
this picture geometrically, however; for instance, the distance between the different points has no meaning. Later on we shall make a quite different visualisation
in which pairs are represented by arrows instead of points.
Figure 8.1: graphical representation of the set A × B, A = {1, 2, 3}, B = {p, q}.
The rectangle of points in figure 8.1 has size 2 × 3, so it contains 6 points in total.
In general, if A contains m elements (recall that we write this as |A| = m) and B
contains n elements, then A × B contains m × n elements:
|A × B| = |A| × |B|.
(There is a link to matrices here: a matrix with m rows and n columns has size
m × n (m by n) and contains m × n entries.)
8.1.1 ‘Laws of arithmetic’ and closure
In chapter 6 we met the set operations union ∪, intersection cap and set difference
c
\; then in chapter 7 we met the complement operation. These operations all
related to the arithmetic of propositions, although \, like ⇒ disobeyed all the rules:
associative, commutative and distributive. Now we have another set operation: ×.
We shall see that it too disobeys all the rules. And in fact it has a worse failing,
one which excludes from being considered as an arithmetic operation at all!
We will check the laws of arithmetic for × in a slightly different order than usual,
looking back to the example above:
Commutative laws: Does (A × B) × C = A × (B × C)?
NO: we saw in example (a) that (1, p) ∈ A × B but in (b) (1, p) < B × A;
Associative law:
Does (A × B) × C = A × (B × C)?
NO, not even if A, B and C are all the same set: we saw in example (e)
8.2. RELATIONS
53
that (p, p), p ∈ (B × B) × B but in (f) we saw thatB × (B × B) contained
p, (p, p) which is not the same;
Distributive law:
Does A ∩ (B × C) = (A ∩ B) × (A ∩ C)?
NO: suppose A, B and C are all the set {a}. Then
A ∩ (B × C) = {a} ∩ {a} × {a} = {a} ∩ (a, a) = ∅, but
(A ∩ B) × (A ∩ C) = {a} ∩ {a} × {a} ∩ {a} = {a} × a} = (a, a) .
In the last example, A ∩ (B × C) = ∅ because A, B and C contain single elements
from some universal set U but B × C contains pairs of elements and these will
not generally be elements of U. Until now, all the operations we have met have
‘stayed within U’: the sum of two polynomials is a polynomial; the sum of two
matrices is a matrix; P ∨ Q is a proposition; A ∪ B is a subset of U. But A × B is
not a subset of U.
We say that an operation is closed over U if its result always again belongs to U.
For sets, we can think of this as saying that the operation keeps within the box
c
of a Venn diagram; ∪, ∧, \ and all turn regions of the Venn diagram into new
regions. But × does not give a region of the Venn diagram. For this reason we do
not think of it as an arithmetic operator at all (computer scientists sometimes call
it a ‘constructor’).
E.g. (a) Z × Z = {(x, y) | x ∈ Z ∧ y ∈ Z} 1 Z;
(b) (Z × Z) × Z = { (x, y), z | x, y, z ∈ Z} 1 Z × Z ∪ Z;
(c) R × R = {(x, y) | x, y ∈ R} 1 R;
The set of pairs of integers Z×Z is usually denoted Z2 (as though it was multiplication—
but it definitely is not multiplication!) Actually the sets (Z × Z) × Z and Z × (Z × Z)
are both usually denoted Z3 even though they are different sets! In applications,
there is often no difference between (x, y), z and x, (y, z) . This is especially true
for R3 which denotes three-dimensional space: it does not matter if we look at the
x-y plane and then include the z axis, or look at the x axis and then include the y-z
plane. Einstein taught us that this remains true for R4 : time, the fourth dimension,
is no different from length, breadth and height.
8.2
Relations
If A is any set then we will write A2 for the cartesian product A × A. The subsets
of A2 are given a special name: they are called relations on A.
54
CHAPTER 8. CARTESIAN PRODUCT AND RELATIONS
E.g. (a) The subset of Z2 which pairs numbers with their squares:
R1 = {(x, y) | y = x2 }
= (0, 0), (1, 1), (−1, 1), (2, 4), (−2, 4) (3, 9), (−3, 9), . . . .
(b) If A = {a, b, c}, the subset of A2 consisting of pairs in alphabetical order:
R2 = {(x, y) | x comes before y in the alphabet}
= (a, b), (a, c), (b, c) .
(c) If A = {a, b, c}, the subset of A2 consisting of pairs not in alphabetical order:
R3 = {(x, y) | x does not come before y in the alphabet}
= (a, a), (b, a), (b, b), (c, a), (c, b), (c, c) .
c
Note that R2 ∪ R3 = A2 . In other words, R3 = R2 , as we would expect since the
membership predicate for R3 is the negation of the membership predicate for R2 .
Some textbooks allow relations between two different sets. For example, if A is
the set of living men and B is the set of living women then we could define
R ⊂ A × B = (x, y) | x is legally married to y .
However, we will call this a ‘mapping’ and deal with it later.
8.2.1 Graphs of relations
We can represent a relation R ⊂ A2 diagrammatically:
• each element of A is represented by a point, called a vertex;
• each pair (a, b) ∈ R is represented by an arrow, called an edge, joining
vertex a to vertex b.
This representation is valid for any set A, even if it is infinite, like Z. But we will
only consider cases where A is a small finite set, say five or six elements at most.
E.g. (a) The relation R1 on A = {a, b, c, d, e} given by
R1 = (a, b), (b, a), (b, c), (b, d), (c, d), (c, e), (d, a), (d, e)
is shown top-left in figure 8.2.
(b) The relation R2 on A = {a, b, c, d} given by
R2 = (a, a), (b, a), (b, b), (b, c), (b, d), (c, a), (c, c), (c, d), (d, a), (d, d)
8.2. RELATIONS
55
Figure 8.2: graphical representations of four relations.
is shown top-right in figure 8.2.
(c) The relation R3 on A = {a, b, c} given by
R3 = (a, a), (a, b), (a, c), (b, a), (b, b), (b, c), (c, a), (c, b), (c, c) = A2
is shown bottom-left in figure 8.2.
(d) The relation R4 on A = {a, b, c} given by
R4 = ∅
is shown bottom-right in figure 8.2.
There are many things we can do with a graphical representation of a relation and
in fact the theory of ‘graphs’ will take up a whole chapter later. But for now they
are mainly useful as a way of checking which properties a given relation has or
does not have.
8.2.2 Properties of relations
There are seven properties which allow us to distinguish some particularly important kinds of relations. It will be convenient to present them in a table. This
CHAPTER 8. CARTESIAN PRODUCT AND RELATIONS
56
is given below as table 8.1: each row gives the formal definition of the property
and then how it may be recognised in the graph of the relation. We can check the
Property Definition
Trivial R = ∅
no edges
Universal R = A2
an edge in both directions between any pair of vertices + a loop
at every vertex
Total for any a and b in A, a , b, (a, b) ∈ R ∨ (b, a) ∈ R
an edge in at least one direction between any pair of vertices
Reflexive for every a ∈ A, (a, a) ∈ R
a loop at every vertex:
Symmetric
for any a and b in A, if (a, b) ∈ R then (b, a) ∈ R
any edge matched by one in the opposite direction:
Antisymmetric
for any a and b in A, if (a, b) ∈ R and (b, a) ∈ R then a = b
no edge matched by the opposite edge:
Transitive for any a, b and c in A, if (a, b) ∈ R and (b, c) ∈ R then (a, c) ∈ R
consecutive edges must ‘complete a triangle’
Table 8.1: the seven key properties for a relation R on set A.
relations shown graphically in figure 8.2:
Trivial
Universal
Total
Reflexive
Symmetric
Antisymmetric
Transitive
R1
R2
R3
R4
You should confirm that you agree with all the ticks! In particular, notice that R4 ,
the trivial relation, is simultaneously symmetric and antisymmetric! All its edges
satisfy both conditions because it has no edges to fail! Mathematicians say the
properties are satisfied vacuously.
The most subtle property is transitivity. In R1 we have some consecutive edges
which form part of a triangle: (b, c) and (c, d) have the edge (b, d), for example.
But (a, b) and (b, d) do not have (a, d). There is a triangle with edge (d, a) but not
the right kind of triangle. And for (a, b) and (b, c) there is no triangle at all, not
even one of the wrong kind.
8.2. RELATIONS
57
8.2.3 Special types of relations
The reason for distinguishing the seven properties in the last section is that they
combine to distinguish some special types of relations which occur everywhere in
mathematics and computer science, from relational databases to algebraic geometry.
Equivalence Relation R is an equivalence relation, or an equivalence, if it is reflexive, symmetric and transitive;
Partial Order R is a partial order if it is reflexive, antisymmetric and transitive;
Total Order R is a total order if it is total and is a partial order.
We can summarise these in a table too:
Trivial
Universal
Total
Reflexive
Symmetric
Antisymmetric
Transitive
Equivalence
Partial order
Total order
If we look back to the table which summarised the properties of the graphs in
figure 8.2 then we see that R2 is a total order and R3 is an equivalence relation.
It is not a coincidence that the equivalence relation, R3 , also happened to be universal. We have the following, very important fact:
Theorem 23 Any equivalence relation R over a set A is made up of a union of
disjoint universal relations which together include all elements of A. In symbols,
there is a possibly infinite list of disjoint subsets A1 , A2 , . . . of A for which
1. A1 ∪ A2 ∪ . . . = A (the Ai are said to partition A);
2. A21 ∪ A22 ∪ . . . = R.
The sets Ai in Theorem 23 are called the equivalence classes of the relation.
E.g. (a) The relation R on A = {a, b, c, d, e, f } given by
R1 = (a, a), (a, b), (a, d), (b, a), (b, b), (b, d), (d, a), (d, b), (d, d),
(c, c), (c, f ), ( f, c), ( f, f ), (e, e)
is an equivalence relation with equivalence classes A1 = {a, b, d}, A2 = {c, f }
and A3 = {e}. Its graph is shown in figure 8.3.
(b) The relation R′ on the integers Z given by
58
CHAPTER 8. CARTESIAN PRODUCT AND RELATIONS
R′ = (x, y) | x, y ∈ Z ∧ x and y have the same parity (both odd or both even)
is an equivalence relation with equivalence classes:
A1 = {. . . , −5, −3, −1, 1, 3, 5, 7, . . .}, (the odd numbers)
A2 = {. . . , −4, −2, 0, 2, 4, 6, . . .}, (the even numbers).
We can think of these equivalence classes as being ‘the same’ as the elements of Z2 ,
the integers modulo 2.
(c) The relation R′′ on the positive integers Z>0 given by
R′′ = (x, y) | x, y ∈ Z>0 ∧ the highest power of 2 dividing x and y is the same
is an equivalence relation with equivalence classes:
A1 = {1, 3, 5, 7, . . .},
A2 = {2 × 1, 2 × 3, 2 × 5, . . .},
A3 = {22 × 1, 22 × 3, 22 × 5, . . .}
...
and so on—an infinite list of infinite equivalence classes!
Figure 8.3: an equivalence relation on A = {a, b, c, d, e, f } consisting of 3 disjoint
universal relations and partitioning A into three equivalence classes.
Partial orders have a theorem too. We know that in a partial order cyclic paths of
length two are banned because of antisymmetry (see row 6 of table 8.1). What
about cyclic paths of length three: (a, b), (b, c) and (c, a)? Well, a partial order
has to be transitive, so (a, b), (b, c) requires that (a, c) is in the relation. But now
we have (c, a) and (a, c) which is not allowed by antisymmetry. So there are no
cyclic triangles. In a similar way, we see that:
Theorem 24 Apart from loops, in the graph of a partial order there can be no
cyclic paths.
As a consequence of this theorem, we can draw the graph of a partial order so
that all the edges point in the same direction. It is traditional to make them point
upwards. Then we leave the arrows off since we know which direction they point
(upwards). Then we leave off the loops since we know that every vertex has a
loop because of reflexivity. Then we leave out all the triangle completions because we know they happen by transitivity. The result is a much simpler graph
8.2. RELATIONS
59
which still has all the information about the partial order. It is called a Hasse diagram. Figure 8.4 shows the derivation of the Hasse diagram for the relation R2 in
figure 8.2.
Figure 8.4: deriving the Hasse diagram of the relation R2 from figure 8.2.