MATU9S1 A Notes
MATU9S1 A Notes
Discrete Structures
University of Stirling
Autumn Semester
These notes are not to be regarded as a substitute for attending lectures. They sum-
marise the key points and give a general outline of the topics covered in this module.
However, additional information and explanation will be given in lectures and is also
available in the recommended textbooks. As with all mathematics, doing the tutorial
questions is the best way to ensure that you understand the material.
0
1 Set Theory
This first section serves two purposes. The concept of a set is fundamental to mathematics
and will be used throughout this module and, indeed, throughout future modules also.
On the face of it, it is a very straightforward concept (and so gives us a good starting
point) although the ideas can become surprisingly difficult the more deeply you look into
them! Secondly, this gives a good structure on which to develop the precision required
to read and write mathematics, which is rather different from reading and writing plain
English.
1.1 Definitions
The language of mathematics is built around a number of definitions. Before we can prove
statements, we need to be absolutely sure that we know exactly what we are talking about.
Often these will be definitions of ordinary English words, and will fit very closely with
our previous understanding of the meaning of these words. Sometimes new terms will be
introduced.
Knowing definitions is essential to understanding what questions mean, and often the
solution to a problem will begin by re-examining the definitions of some of the terms used
in the question.
The objects can be numbers, letters, shapes, animals, addresses or anything else we
want, including a mixture of different types of object. Each of the objects in a set is
known as a member or element of the set.
Normally we shall use upper-case letters, A, B, C, . . . to stand for sets and lower-case
letters x, y, z, . . . to represent members of sets.
Definition 1.3 Two sets are equal if they contain precisely the same members.
Small sets are usually defined by listing the members between braces (curly brackets).
When listing a set, each member should be included once and once only but the order
does not matter.
1
• If B = {UK, USA, Germany, France} then France ∈ B but Italy 6∈ B.
• We could define the set C by C = {1, a, Stirling, StJohnstone FC}, though why
we would want to do such a thing I don’t know!
This listing notation becomes clumsy for larger sets and so we more usually define
a set by giving a rule or rules that describe the members of the set. This is known as
set-builder notation. For example, {x : x is a vowel} is read as ‘the set of (objects) x such
that x is a vowel’ and is exactly the same as {a, e, i, o, u}.
Notice that the first and last examples above are exactly the same and in fact have
nothing to do with the variables x and t. These are merely labels to allow us to talk about
the members of the set generally and are therefore sometimes called dummy variables.
The example on even numbers also shows that a set might have an infinite number of
members. Often in these cases the set-builder notation is more accurate than trying to
list the members and finishing with ‘. . . ’ meaning ‘and so on’.
One special set, which may seem trivial but is in fact very useful, is the empty set, the
set which does not contain any members at all.
Definition 1.5 The set B is a subset of the set A if every member of B is also a member
of A. This can be written as ‘x ∈ B ⇒ x ∈ A’ where ⇒ is read ‘implies’, in other words
‘if x is a member of B then x is a member of A’.
If B is a subset of A we write B ⊆ A.
Warning: be careful of the difference between ‘⊆’ (is a subset of) and ‘∈’ (is a member
of). For example:
2
Note also that you may come across a different notation in some books. The symbol
⊂ is often used as an alternative to ⊆, while some authors reserve ⊂ to indicate a proper
subset, ie a subset that is not equal to the original set.
Solution. This should be intuitively obvious, but it gives a good example of how defi-
nitions can form the basis of a rigorous proof. We simply turn our intuition into more
mathematical language.
Let x ∈ P . Then, since P ⊆ Q, x ∈ Q. Now, since Q ⊆ R, it follows that x ∈ R.
Hence any member of P (ie every member of P ) is a member of R and so P ⊆ R.
Definition 1.6 The order of a set is the number of members it contains. The order of
A is written |A|. If A contains an infinite number of members we say that |A| = ∞. The
order of a set is sometimes called the cardinality of the set.
• |{integers}| = ∞.
You will sometimes see the natural numbers defined to include zero, but I shall use
N to mean only positive integers.
Rational numbers are those that can be written as fractions. Note that, by the defini-
tion above, the integers are all included in Q since, for example, 5 = 5/1, −3 = −3/1 and
even 0 = 0/1. All terminating decimals are rational, and some non-terminating decimals
also, eg 0.333 . . . = 1/3.
Irrational numbers are those that cannot be written as fractions. You have already
√ √
met examples of these, such as 2, 3, π and possibly e. If you try to write any of these
3
as a decimal, it will go on for ever but without settling into a recurring pattern. We shall
√
prove in Section 5 that 2 is irrational.
Real numbers consist of all the rational and irrational numbers taken together and can
almost be thought of as ‘all numbers’. However, you may have previously met complex
numbers, denoted by C, which do go beyond real numbers. We shall not be concerned
with complex numbers in this module but will learn about them in MAT912.
Notice that each of these sets is contained in the next one on the list:
N ⊆ Z ⊆ Q ⊆ R ⊆ C.
All real numbers are either positive, negative or zero, but note that zero itself is neither
positive nor negative. Hence the positive integers are the same as the natural numbers,
ie {1, 2, 3, 4, . . .}, whereas the set {0, 1, 2, 3, 4, . . .} would be described as the non-negative
integers.
When defining sets of numbers, it is sometimes clear from the context what type of
numbers we are talking about, but if there is any doubt then this should be made explicit
in the definition. For example:
• {x : 5 < x < 6 and x ∈ R} cannot be listed but includes, for example, the numbers
√
5.3, 5.8726 and 30.
This general description of type of number is sometimes included in the first part of
the set-builder notation, so that the first example above might be written
• {x : x < 4 and x ∈ N} = {x ∈ N : x < 4}, read ‘the set of x in N such that x is less
than 4’.
Definition 1.8 The union of two sets A and B is the set {x : x ∈ A or x ∈ B} and is
denoted by A ∪ B.
The word ‘or’ is used here in its inclusive sense, so that an object is in the union of A
and B if it is either in A, or in B, or possibly in both.
Taking A = {2, 5, 7, 12}, B = {1, 2, 5, 11} and C = {prime numbers less than 10} we
have:
4
• A ∪ B = {1, 2, 5, 7, 11, 12}.
• B ∪ C = {1, 2, 3, 5, 7, 11}.
• A ∪ N = N.
Definition 1.9 The intersection of two sets A and B is the set {x : x ∈ A and x ∈ B}
and is denoted by A ∩ B.
• A ∩ B = {2, 5}.
• B ∩ C = {2, 5}.
• A ∩ N = A.
Definition 1.10 The difference of two sets A and B is the set {x : x ∈ A and x 6∈ B}
and is denoted by A\B, read ‘A minus B’.
• A\N = ∅.
This definition only makes sense if it is clear what objects are under consideration in
any particular question. We do not want the complement of a set to include every other
object in the entire universe! This gives us the concept of a universal set, often denoted
by E (standing for ‘entirety’) or U , which will vary from question to question.
5
• If the universal set is {letters of the alphabet}, the complement of {vowels} is
{consonants}.
You will see other notations in use for the complement of a set, such as A0 and AC .
In other words, disjoint sets are completely separate and have no members in common.
Example 1.2 Prove the associative law for union of sets, ie that for any sets A, B, C,
A ∪ (B ∪ C) = (A ∪ B) ∪ C.
Solution. In lecture.
This result shows that the position of brackets in the expression A ∪ B ∪ C does not
matter and so we can write A ∪ B ∪ C without any ambiguity. Since this can be extended
to any number of sets, it is possible to extend the definition of union of sets to include
more than two sets at a time.
The ideas of union and intersection of sets are fairly obvious ones to explore but our
next operation, the multiplication of sets is perhaps not so natural.
Definition 1.14 The Cartesian Product of two sets A and B is the set
A × B = {(x, y) : x ∈ A, y ∈ B}.
This means that A × B is a set of ordered pairs where the first member of each pair
is in A and the second is in B. By ‘ordered pair’ we mean that (x, y) is not the same as
(y, x). Some examples will help to clarify this.
• If A = {a, b} and B = {4, 7} then A × B = {(a, 4), (a, 7), (b, 4), (b, 7)}.
• If S = {soup, salad} and M = {meat, fish, eggs} then S ×M is the set of all possible
2-course menus choosing a starter from S and a main course from M :
S×M = {(soup,meat), (soup,fish), (soup,eggs), (salad,meat), (salad,fish), (salad,eggs)}.
• R × R = {(x, y) : x, y ∈ R} = R2 .
This last example is very important. R2 is the set of all ordered pairs of real numbers
and can be thought of as being the coordinates of all points in the plane. For any set A
we use the abbreviation A × A = A2 .
It should be clear that, for any finite sets A and B, |A × B| = |A|.|B|.
6
1.4 Venn diagrams
Venn diagrams are a very simple but effective way of representing sets visually. One shape
(usually a rectangle) is used to represent the universal set and other shapes (usually circles)
are placed within this to represent other sets. Unless we are told otherwise, we should
always bear in mind that different sets may have some members in common and so the
typical 2-set Venn diagram will look like this.
In the left-hand diagram the rectangle has been divided into 4 regions, which are labelled
in the right-hand diagram so that we can refer to them.
Thus set A consists of regions (i) and (ii), while set B consists of regions (ii) and (iii).
We can describe the 4 regions by their contents.
(i) Members of A which are not in B, ie A\B;
(ii) Members which are in both A and B, ie A ∩ B;
(iii) Members of B which are not in A, ie B\A;
(iv) Members which are not in either A or B, ie A ∪ B.
It is very important to remember that set A includes both regions (i) and (ii), not just (i),
and similarly region (i) cannot be described as A, but as A\B. The bounding rectangle
indicates all the objects (people, numbers, letters, events etc) which we are considering
in a particular problem, ie the universal set.
The basic operations union, intersection and complement can now be thought of in
terms of these diagrams.
7
disjoint sets B⊆A
A typical Venn diagram for three sets needs to show a possible intersection of any two
of them and so will generally be drawn like this.
It is very difficult to illustrate more than three general sets neatly in a Venn diagram,
though if we know, for example, that some of the sets are disjoint (do not intersect), or
that one set is a subset of another, then the picture will be significantly simplified.
Venn diagrams can be used to help us think about problems and to give us an idea
of how to prove certain results, though strictly speaking looking at a picture does not
constitute a proof: it merely points us in the right direction.
Example 1.3 Illustrate the sets A = {p, q, r, s} and B = {q, s, v} on a Venn diagram
with the universal set E = {p, q, r, s, t, u, v}. List the members of A ∩ B.
Solution.
Example 1.4 Use Venn diagrams to illustrate that (A ∪ B) ∩ C is not usually the same
as A ∪ (B ∩ C).
8
Solution. Build up pictures of these two sets (second and fourth diagrams below) and
note that they are not the same.
A∪B (A ∪ B) ∩ C B∩C A ∪ (B ∩ C)
We saw in Example 1.2 that the associative law applies to the operation ‘union’, ie
that we can write A ∪ B ∪ C without ambiguity since the positioning of brackets makes
no difference, and the same is true for ‘intersection’. However, Example 1.4 demonstrates
that when we have a mixture of intersections and unions it is crucial to show by brackets
the order in which the operations are to be carried out.
The expressions A ∪ B ∩ C and A ∩ B ∪ C are ambiguous and should never be written
without brackets.
We shall return to Venn diagrams and their uses in Section 4.
Definition 1.15 The power set of a set A is the set whose members are all the possible
subsets of A. The power set of A is denoted by P(A).
Solution. A has 4 subsets and so P(A) = {∅, {x}, {y}, {x, y}}.
Solution. Without listing the subsets, if we count them systematically we can see that
there is 1 subset with no elements (∅), 3 subsets with one element, 3 subsets with two
elements and 1 subset with three elements (B itself). Hence there are 8 subsets in all and
so |P(B)| = 8.
Clearly what the actual members are in this example does not matter and so any set
with 3 members will have 8 subsets.
9
Another way of doing that calculation would be to argue like this. Subsets can be
constructed by choosing to include or exclude each element in turn. Thus a could be in
the subset or not (two choices). For each of these choices, b could be in the subset or not,
which doubles the number of choices from 2 to 4. Finally for each of these 4 choices, we
can choose to include or exclude c, giving 8 possible subsets in all.
Extending this argument, it should be clear that a set containing n members will have
n
2 subsets.
It seems natural to say that if we can pair up the elements of one set precisely with
the elements of another then the orders (or cardinalities) of the two sets are the same.
We extend this idea to sets of infinite order. This can lead to some odd-looking results.
Let A be the set of positive even numbers and compare this with N. There is a natural
pairing of the elements, given by 2 ↔ 1, 4 ↔ 2, 6 ↔ 3, 8 ↔ 4, . . .
Each member of A has a ‘partner’ in N and vice versa. We therefore say that A and
N have the same cardinality. It may seem strange that after throwing out all the odd
numbers from N there are still, in a sense, as many numbers remaining as there were
originally!
Definition 1.16 Any infinite set whose elements can be paired in this way with the nat-
ural numbers is called a countable set. Not every infinite set is countable.
Solution. The problem here is that the integers are usually listed as {. . . , −2, −1, 0, 1, 2, . . .},
stretching out for ever in both directions. This means that we cannot simply count the
integers from left to right. However, we can set up the pairing between N and Z as follows:
1 ↔ 0, 2 ↔ 1, 3 ↔ −1, 4 ↔ 2, 5 ↔ −2, 6 ↔ 3, . . . , in other words we count the
integers from the middle out, in the order 0, 1, − 1, 2, − 2, 3, − 3 etc. This shows
that N and Z have the same cardinality and that Z is countable.
10
2 Number Bases
Have you ever wondered why our number system is based on the number ten? This has
become such a part of our lives that it is hard to imagine anything else, but in fact there
is no good mathematical reason for it. Of course we might argue that we only have digits
0-9 and it makes decimal fractions and percentages easier, but that is actually a circular
argument: decimal fractions and percentages arise because we use 10 as our base, not the
other way around.
If we were reinventing counting systems now, and nobody already had a built-in fa-
miliarity with base 10, there would be no reason why we could not use a system based
on 8, or 12, or 16. (I think my vote might go to 12!) In fact, over the course of history,
there have been civilisations which used 12, 20 and even 60 as their base, and computers
work best in base 2.
11
Example 2.1 What digits are needed in base 7 and in base 5, and what would the headings
be for the columns?
Solution. In lecture.
To convert the other way, from base 10 to another base, it is sometimes possible to
do this almost by inspection by thinking what the headings of the columns will be and
making up the number you require by starting with the large values, ie moving from left
to right.
Example 2.3 Convert these numbers from base 10 to the bases shown.
(i) 4710 to base 5. (ii) 14110 to base 4. (iii) 16710 to base 8.
Solution. (i) How do we make up 47 by using 1, 5 and 25? Start at the high end (the
leftmost column). We need one 25 and that leaves 22 still to be found. For 22, we need
four 5s and that leaves 2. Hence 4710 = 25 × 1 + 5 × 4 + 2 = 1425 .
(ii) and (iii) in lecture.
If this seems rather an informal approach, or if you are dealing with much bigger
numbers, there is an algorithm we can use, ie a routine method. It may not be so clear
why this works, but it is a good practical method.
Keep dividing the base-10 number by the new base, removing the remainder each time.
When you can divide no more, read off all the remainders from the bottom to the top
and that will be the representation in the new base.
12
Example 2.4 Repeat the previous example by this method.
Solution. (i) 5 47 Reading the remainders from bottom to top gives 4710 = 1425 .
5 9 2
5 1 4
0 1
(ii) and (iii) in lecture.
The reason this works (referring to part (i) above) is that the first division told us
that 47 = 5 × 9 + 2. We have expressed 47 in groups of 5, with 2 units left over. The
second division takes these 9 groups of 5 and creates 1 group of five fives (ie 25) and 4
groups of 5 left over. Thus we have 47 = 25 × 1 + 5 × 4 + 2.
The above methods allow you to change to and from base 10. If you need to change
from one base to another (neither of which is 10) usually the easiest way is to convert
into base 10 first and then convert out. However we shall later see one or two particular
cases where there is a shortcut.
Example 2.5 Carry out the following calculations in the bases indicated.
(i) 478 + 268 (ii) 3468 + 5748 + 3748 (iii) 2314 + 3324 (iv) 5347 × 5
(v) 2213 × 2 (vi) 3689 + 7589 (vii) 556 + 436 + 546 (viii) 4325 × 4
Solution. (i) 4 7
+ 21 6
7 5
7 + 6 = 13. This is 1 eight and 5 units so we put down 5 and carry 1. Then 4 + 2 + 1 = 7.
(ii) 3 4 6
5 7 4
+ 32 71 4
1 5 3 6
13
Starting from the right, 6 + 4 + 4 = 14. This is 1 eight and 6 units so write down 6 and
carry 1. 4 + 7 + 7 + 1 = 19. This is 2 eights and 3 units so write down 3 and carry 2.
Finally, 3 + 5 + 3 + 2 = 13 so write down 5 and carry 1, which goes in a column on its
own.
Other parts in lecture or as exercises.
Example 2.6 Check the answers to the previous example by converting the original num-
bers into base 10, doing the calculation in base 10 and converting your answer back into
the given base.
Solution. (i) 478 = 3910 and 268 = 2210 . Adding 39 and 22 in base 10 gives 61. 61 is 7
eights and 5 units and so 6110 = 758 , which agrees with our original answer.
Other parts in lecture or as exercises.
Another very common number base greater than 10 is 16, giving rise to the hexadecimal
system. This is used a lot in computing science because 16 is a power of 2 (more later).
Here we need new symbols for 10, 11, 12, 13, 14 and 15 and we can no longer extend
the idea of using initial letters because too many of these start with t or f . Instead it
is conventional to use the letters A-E (sometimes in lower-case a-e) with the meanings
A=10, B=11, C=12, D=13, E=14 and F=15.
The headings for the columns are the powers of 16, from right to left 1, 16, 256 etc.
Thus 4716 represents 16 × 4 + 7 or 7110 , 3B16 represents 16 × 3 + 11 or 5910 and AF16
represents 16 × 10 + 15 or 17510 .
14
Other notations are used to indicate that a number is in hexadecimal. 0xf3, 0xF3,
F3x, F316 and f316 all mean the same thing. (x means hex, short for hexadecimal.)
Example 2.7 (i) Convert the hexadecimal numbers 7A, 4E and 216 into decimal.
(ii) Convert the duodecimal numbers t5, 47 and 3e1 into decimal.
(iii) Convert the decimal numbers 57, 183 and 622 into both base 16 and base 12.
Solution. In lecture.
2.5 Binary
Another very useful number base is base 2, also known as binary. This is the system used
by computers to store numbers. In base 10 we use the digits 0-9, in base 7 we use the
digits 0-6 and therefore in base 2 we only use the digits 0 and 1.
This is both an advantage and a disadvantage. The benefit is that we need only two
states: 0 and 1, on and off, yes and no, true and false, positive or negative etc to be able
to represent all numbers. The downside is that large numbers are very long and strings
of 1s and 0s can be a bit confusing to the eye.
The headings for the columns are the powers of 2: from right to left these are 1, 2,
4, 8, 16, 32, etc. Thus 19 can be made up of 16 + 2 + 1 and so 1910 = 100112 , that is
a 16, no 8s, no 4s, a 2 and a 1. Notice that this is the only way of representing 19 as
a sum of (different) powers of 2. Note that this could also have been worked out by the
algorithm we used earlier: to change from base 10 to base 2 keep dividing by 2 and taking
the remainder.
2 19
2 9 1
2 4 1
Now read the remainders up the way, giving 10011.
2 2 0
2 1 0
0 1
Example 2.8 Convert the following binary numbers to decimal (base 10).
(i) 1011 (ii) 10010 (iii) 101101 (iv) 1001001
Solution. In lectures.
Solution. In lectures.
15
Example 2.10 Carry out the following calculations in binary. Check your answers by
converting the numbers to decimal and converting the answer back to binary.
(i) 1011 + 10 (ii) 10010 + 11011 (iii) 101101 × 11 (iv) 10101 × 10
Solution. (i) Remember that we can only use the digits 0 and 1 in binary and whenever
we have 2 in a column we need to represent this as a 1 in the column to the left (carry 1).
1 0 1 1
1 0
1 1 0 1
The only thing to watch here is that in the second column from the right we added 1 and
1 and got 2, which is 10 in binary and so we put down 0 and carry 1.
Check by converting: 10112 + 102 = 1110 + 2 = 1310 = 11012 .
Other parts in lecture.
Since 16 is a power of 2, there is a very close connection between binary and hexadec-
imal numbers. Hexadecimal numbers are expressed in powers of 16, which are themselves
powers of 2, and so each hexadecimal digit is exactly equivalent to 4 binary digits. Note
that 4 binary digits (called bits in computing parlance) can represent any number from 0
to 15, the same as one hex digit.
To convert a hex number to binary, therefore, we can take each digit and convert it
to 4 binary digits, stringing our answers together.
Solution. Take the hexadecimal number digit by digit. 3 becomes 112 . D (ie 1310 )
becomes 1101 and 6 becomes 0110. (Note the initial zero to pad this out to 4 digits.)
Putting these together gives 3D616 = 11110101102 . Check: the hexadecimal version
means 256 × 3 + 16 × 13 + 6 = 982 in decimal and the binary version translates as
512 + 256 + 128 + 64 + 16 + 4 + 2 = 982 also.
Converting the other way is similar. Take a binary number and split it up into groups
of 4 bits from the right-hand end. Each set of 4 bits can then be turned into a single hex
digit.
Solution. Grouping in fours from the right gives 110 1011 0111. (It is OK that the
leftmost group has only 3 digits in it.) These groups now convert, in decimal, to 6, 11
and 7 making the hexadecimal number 6B7.
16
2.6 Applications
In computers, all data is stored in binary, using only ones and zeros. We have seen how
numbers can be represented, but in fact all letters, pictures and sounds can also be stored
this way, ie in a digital format. Here are some examples to illustrate how this can be
done.
2.6.1 Colours
“All the colours of the rainbow” should really refer to an infinite number of colours, not
just seven, since there can be tiny variations between similar colours. Computers are
not good at storing an infinite number of things, but they can certainly deal with large
numbers.
One way of storing a colour is to think of it as a mixture of red, green and blue,
specifying how much of each is required. This is known as the RGB format. If we allow
256 (ie 28 ) shades of each of red, green and blue that gives us a combination of 2563 or
224 or 16 777 216 colours, more than enough for our human eyes to cope with!
If we call the 256 shades of each colour 0 (none of it) up to 255 (as much as you
can get) then we can represent each of R, G and B by a 2-digit hexadecimal number
from 00 up to FF (255). Putting these numbers together gives us a 6-digit hex number
representing one of the 16 777 216 colours.
For example, FFFF00 means “lots of red, lots of green and no blue”, in other words
yellow. 000000 means no colour at all, ie black, and FFFFFF mixes all colours fully, giving
white. Similarly, 808080 mixes each colour equally at about half-strength (8016 = 12810 )
and so this gives grey.
The way in which a computer stores a picture is to split it up into a rectangular array
of ‘picture elements’ or pixels and then to record what colour each pixel should be. The
simplest case is a black and white image, where we can use 0 to stand for white and 1 to
stand for black. (This assumes that the background is white: there are other conventions.)
Then we store the picture row by row, from left to right, but conventionally from the
bottom to the top, which is maybe not what you would expect.
17
Hence the above 8 × 8 image can be saved as follows:
binary hexadecimal
row 8 (top) 00000000 00
row 7 10000000 80
row 6 11000000 C0
row 5 01111110 7E
row 4 00111100 3C
row 3 00010010 12
row 2 00001001 09
row 1 (bottom) 00000000 00
Conversely, given a 16-digit hexadecimal number we can reconstruct a black and white
picture on an 8 × 8 grid.
Example 2.13 Reconstruct the 8 × 8 black and white picture which has been saved in
hexadecimal as FF 10 10 7C 54 54 54 10.
Solution. Remember this goes from the bottom to the top, with 2 digits for each row.
hexadecimal binary
row 8 (top) 10 00010000
row 7 54 01010100
row 6 54 01010100
row 5 54 01010100
row 4 7C 01111100
row 3 10 00010000
row 2 10 00010000
row 1 (bottom) FF 11111111
18
Example 2.14 Reconstruct the 4 × 4 black and white picture which has been saved in
hexadecimal as ECA1.
Solution. For a 4 × 4 grid, the 4 bits in each row can be represented by a single hex digit,
again going from bottom to top.
hexadecimal binary
row 4 (top) 1 0001
row 3 A 1010
row 2 C 1100
row 1 (bottom) E 1110
In black and white pictures, we used one bit (0 or 1) for each pixel. For colour pictures we
need to use as many bits for each pixel as are required to cover all colours, but the principle
is the same. For a full ‘millions of colours’ RGB picture we would need 24 bits per pixel,
but we can illustrate this by restricting our picture to only 4 colours, coded as 0, 1, 2 and 3.
1 1 0 0 0 1 1 0 0 0 0 1 4 0
1 1 0 0 0 1 1 0 0 0 0 1 4 0
3 3 3 3 3 3 0 3 3 3 3 3 3 0 3 F F C
2 2 2 2 0 0 2 2 2 2 0 0 0 A A 0
→ →
1 1 0 0 0 1 1 0 0 0 0 1 4 0
2 2 2 2 0 0 2 2 2 2 0 0 0 A A 0
3 3 3 3 3 3 0 3 3 3 3 3 3 0 3 F F C
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5 5 5 5
The second table is in base 4. The third table is a conversion into base 16, with every
two base-4 digits making one base-16 digit. For example, to convert the row 03333330,
note that 034 = 310 = 316 , 334 = 1510 =F16 and 304 = 1210 =C16 . Hence the final hex
coding for the picture is 55 55 3F FC 0A A0 01 40 0A A0 3F FC 01 40 01 40.
It should be straightforward to see how to reverse this process to construct a 4-colour
picture from its hexadecimal coding.
19
2.6.4 ASCII coding
We have seen how colours and pictures can be stored in a computer purely in binary. The
same is true of text: letters and punctuation marks. All that is needed is to give each
character a unique numeric code. Two frequently used schemes for doing this are ASCII
(American Standard Code for Information Interchange) and UNICODE, which is much
more extensive, including Japanese and Chinese characters.
ASCII uses 7 bits and therefore has a range of 0-127. In reference tables, these are
usually given in hex (00-7F) rather than binary (00000000-01111111) and the ones that
are of most interest to us are in the range 20-7E. These are given below.
0 1 2 3 4 5 6 7 8 9 A B C D E F
2 sp ! ” # $ % & ’ ( ) * + , - . /
3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ˆ
6 ‘ a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ˜
Solution. Two hex characters are required for each ASCII character. From the left,
47→G, 6F→o, 6F→ o, 64→d, 20→ space, etc, giving the phrase ‘Good luck.’
20
3 Switching Circuits
A switching circuit is a network containing a set of switches that allow or prevent flow
along the branches of the network. This can be thought of in terms of electricity in wires
(with switches), or fluid flow along pipes (with taps or valves) or even traffic on a country
road (with gates).
However, note that the concepts open and closed are different for these different mod-
els. We shall use the electrical model here, meaning that when a switch is closed a
connection is made and so the current can flow, whereas when a switch is open the circuit
is broken and current cannot flow. Note that this is the opposite of the ‘gates on roads’
model!
series parallel
To help us analyse such circuits, we shall use the convention that 0 indicates an open
switch (so current is blocked) while 1 indicates a closed switch (so current can flow).
(Remember 1 for yes and 0 for no.) We are particularly interested in which circuits allow
a flow from beginning to end and we shall use the same notation for the output, ie 1 if
flow is possible right through the circuit and 0 otherwise.
The above circuits can now be represented by truth tables or input-output tables.
series parallel
p q output p q output
1 1 1 1 1 1
1 0 0 1 0 1
0 1 0 0 1 1
0 0 0 0 0 0
21
The 4 rows of each table show the 4 possible combinations of open and closed switches
and the output column indicates whether or not flow is possible through the entire circuit.
When you are constructing truth tables, it is conventional to follow this order of rows, ie
11, 10, 01, 00. It makes comparison of different tables easier if the rows are always in the
same order.
In some circuits, switches can be linked in the sense that they are either both open
or both closed (we shall simply label them with the same letter) or whenever one is open
the other is closed (in which case we shall label the ‘opposite’ of p as p).
Example 3.1 Construct the truth table for the following circuit.
Solution. p q output
1 1 0
1 0 0
0 1 1
0 0 0
Notice that it is always impossible to pass through the top branch of the parallel part of
this circuit since if p is closed then p is open and vice versa. Hence the only way through
the circuit is if q and p are both closed, ie if q = 1 and p = 0.
Example 3.2 Construct the truth table for the following circuit.
22
Solution. Here we have 3 unconnected switches, p, q and r, and so our truth table will
now require 8 lines to cover all possible combinations of open and closed switches. Again,
note the conventional order of rows and try to stick to this yourself.
Example 3.3 The hall light of a house is controlled by two switches, one upstairs and
one downstairs. Design a switching circuit such that flicking either of the switches turns
the light on if it was off and off if it was on.
Solution. Let us say that the light is on when both switches are closed. By considering
what happens when either switch is flicked, it is easy to see that the truth table we require
is as follows.
p q light
1 1 1
1 0 0
0 1 0
0 0 1
Check the lines of the truth table to convince yourself that it satisfies the conditions of
the question in every state the switches can be in.
Now we use the truth table to construct a possible circuit. Notice that there are two
lines which produce an output of 1, ie that put the light on. If we make a branch of the
circuit for each of these and then set the branches in parallel, that will mean that either
of these combinations of switches will work.
23
We want one branch to allow flow when both switches are closed (so put p and q in
series) and the other to allow flow when both switches are open (so put p and q in series).
This gives:
(The diagram has been simplified by putting the switch-labels inside the switches. We
shall adopt this convention from now on.)
Example 3.4 Design a switching circuit in which a lamp lights up if the majority of
members of a committee of 3 vote ‘yes’ on a motion.
Solution. In lecture.
Solution. In lecture.
To find the algebraic expression for a more complicated circuit we break that circuit down
into parallel and series components.
24
Example 3.6 Represent the following circuits with algebraic expressions.
(i) (ii)
Solution. (i) The lower part consists of q and r in parallel and so is denoted by q + r.
This part is then put in parallel with p, giving p + (q + r). It is safer to use brackets when
first constructing algebraic expressions, to show the order in which the circuit has been
constructed, although in this case the expression is equivalent to (p + q) + r and so we
can just write p + q + r without ambiguity.
(ii) In lecture.
Note that, as with ordinary algebra, the convention is that products are carried out before
sums unless the brackets indicate otherwise. Thus p+q.r means p+(q.r) and not (p+q).r.
Example 3.7 Draw the circuit represented by the expression (p + q).(r + s).
Solution. In lecture.
3.4 Equivalences
We have used the terms product and sum and the symbols . and + to stand for series and
parallel, so we might wonder if there is any similarity with multiplication and addition in
ordinary algebra. It turns out that certain rules are the same, but not all.
Consider the following two circuits.
25
(E1) p.(q + r) = p.q + p.r
(E1) is referred to as an (algebraic) identity because it is true for any switches, or even
mini-circuits, p, q and r in the same way that in ordinary algebra this would be true for
any numbers p, q and r: it is just our familiar ‘multiplying out of brackets’.
However, there is another identity for circuits which does not apply to ordinary algebra.
This can again be seen by comparing the circuits visually or by constructing their truth
tables.
p + q.r (p + q).(p + r)
These identities involved 3 switches but there are a few which only involve 2 or even
only 1 switch.
(E3) p + p.q = p
(E4) p + p.q = p + q
(E5) p+p=p
(E6) p.p = p
There are two special circuits which we include in our algebra. 0 means ‘always open’, ie
no current can flow, and 1 means ‘always closed’, ie current can always flow. These can
be included in our equivalences. They behave a little like the numbers 0 and 1 but be
careful because the similarities cannot always be assumed.
(E7) p.1 = p
(E8) p+0=p
(E9) p.0 = 0
(E10) p+1=1
(E11) p.p = 0
(E12) p+p=1
Solution. These can be done by considering the circuits visually. They can also be
confirmed by constructing the truth tables for both sides of the identity and noting that
they are the same. Some will be illustrated in lecture and the rest are left as an exercise.
26
Example 3.9 Express the following circuit algebraically and then simplify the expression
using the equivalences (E1) to (E12).
Solution. The top branch is p.(p+q) and the bottom branch is p+p.q. These are combined
in parallel and so the whole circuit can be expressed as p.(p + q) + (p + p.q).
p.(p + q) + (p + p.q)
= p.p + p.q + (p + p.q) (E1)
= p + p.q + (p + p.q) (E6)
= (p + p.q) + p (E3)
= p+p (E3)
= 1 (E12)
So there is always a flow through the circuit, whatever position the switches are in. Quite
a simplification!
There is an important point illustrated in step 4 concerning the use of the equivalences.
In specifying these identities we used p, q and r but of course these can be replaced by
any other switches or combinations of switches. Thus since p + p.q = p it also follows that
p + p.q = p.
Example 3.10 Look back to the majority voting circuit produced in Example 3.4. By
expressing it algebraically and simplifying the resulting expression, redraw the circuit with
fewer switches.
Solution. In lecture.
27
4 Venn Diagrams
4.1 Organising information
Venn diagrams were introduced in section 1.4 as a useful way of visualising sets and how
they relate to one another. We now look at some more uses of Venn diagrams. Firstly
they can be used to organise information effectively. Note that in questions involving sets
containing a large number of members we sometimes mark the number of elements in each
region of the Venn diagram rather than indicating each element individually.
Example 4.1 Of the 100 students in a first-year class, 42 had passed Higher Physics.
Of these, 11 had also passed Higher French. 45 of the class did not have a pass in either
Physics or French. Draw a Venn diagram to illustrate this situation and determine how
many of the students had passed French.
Solution. We start by drawing a blank 2-set Venn diagram (which I have labelled for
reference). Some of the information cannot immediately be filled in because it refers to
more than one of our regions. However, we can start with the 45 who have passed neither
subject (region(iv)) and the 11 who have passed both (region (ii)). Then we can complete
the Physics set (42 − 11 = 31 in region (i)). Finally, since there are 100 students in
the class (which must be the total of all the regions) we see that region (iii) contains
100 − 31 − 11 − 45 = 13 students.
This lets us see that the number of students who passed French is 24, the total of regions
(ii) and (iii) (NB not just region (iii) - they are the ones who passed French but not
Physics).
Example 4.2 Of 250 people questioned in Edinburgh yesterday, 137 said they normally
travelled by public transport when they went to Glasgow. Of these, 107 had at some time
used the train and 65 had gone by bus. How many of the people questioned used only the
train, how many only the bus and how many had used both?
Solution. In lecture.
28
If our problem involves 3 different sets, we need to draw 3 intersecting circles, which
divide the rectangle into 8 regions. The typical diagram looks like this.
Now, for example, set A consists of regions (i), (ii), (iv) and (v). Region (vii) has to be
described as ‘the members of C which are not in A or B’. ‘The members which are in
both B and C’ describes the two regions (v) and (vi).
Solution. In lecture. The final Venn diagram is shown and the answer is 21.
4.2 Probability
Venn diagrams can also be used to illustrate different events and hence to calculate the
probability of their occurrence.
29
Example 4.4 Two 4-sided dice (showing 1-4) are thrown. Let A be the event that the
sum of the numbers is 4 and let B be the event that the two numbers shown are equal.
What is the probability that (i) A occurs, (ii) B occurs and (iii) either A or B occurs,
when the dice are thrown?
Solution. There are 16 possible outcomes when the dice are thrown, which we shall denote
by (1,1), (1,2), (2,1) ... (4,4). Event A consists of the outcomes {(1,3), (2,2), (3,1)} and
event B consists of the outcomes {(1,1), (2,2), (3,3), (4,4)}. These can be represented
in a Venn diagram, but note that (2,2) occurs in both sets. Start completing the Venn
diagram from the centre.
1
Since the different outcomes are equally likely, each has a probability of 16 . We can now
3
see from the Venn diagram that since event A consists of 3 outcomes its probability is 16 ;
4 1
B consists of 4 outcomes, with probability 16 or 4 ; and the event A or B, corresponding
6
to the set A ∪ B, consists of 2 + 1 + 3 = 6 outcomes with probability 16 or 38 .
Example 4.5 Add a third event C to the previous example, that the product of the num-
bers on the two dice is odd. What is the probability that, on any throw of the dice, the
numbers are equal and either the sum is 4 or the product is odd, ie B and either A or C?
Solution. We now need a 3-set Venn diagram. C = {(1, 1), (1, 3), (3, 1), (3, 3)}. Since
2 of these outcomes are in A and 2 are in B but none are in both A and B we can now
adjust the Venn diagram for the previous example to become:
The shaded region is the part we are interested in, representing B ∩ (A ∪ C), and so the
3
probability is 16 .
30
4.3 Elementary logic
So far we have used Venn diagrams to help us count different categories but they are also
very useful when we do not know how many people are represented by each region, using
them in a more structural manner.
Example 4.6 (i) All students regularly attending lectures pass the course. Lazy students
do not regularly attend lectures. Does it follow that no lazy students pass the course?
(ii) All students regularly attending lectures pass the course. Lazy students do not pass
the course. Does it follow that no lazy students regularly attend lectures?
Solution. (i) Draw a 3-set Venn diagram to represent the qualities ‘attend lectures’, ‘pass’
and ‘lazy’.
The first statement tells us that regions (i) and (iv) are empty, since anyone in these parts
attends lectures but does not pass. The second statement tells us that regions (iv) and
(v) are empty. In the second diagram, the shaded regions are empty. However, region
(vi), marked X, is not necessarily empty and so it is possible that some lazy students pass
the course.
(ii) In lecture.
31
union: A ∪ B intersection: A ∩ B complement: A
Solution. In lecture.
Solution. In lecture.
Note that the two Venn diagrams in each part of the last example are identical. This
illustrates the very important distributive laws, that:
A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
You should recognise the similarity between these two identities and the equivalences (E1)
and (E2) we had with switching circuits:
This connection between switching circuits and Venn diagrams is not a coincidence! In
fact, all the equivalences we obtained for switching circuits have their analogies for Venn
diagrams.
32
Solution. Exercise.
De Morgan’s Laws
Two very important identities which we did not include with switching circuits are De
Morgan’s Laws, which tell us how to take complements of compound sets:
Solution. In lecture
Note carefully what these laws say. The complement of an intersection is a union and
vice versa. These have clear parallels in everyday language.
For example, consider the set of bachelors who are both rich and handsome. Now take
a bachelor who is not in this set, ie he is in the complement of the set. He is either not
rich or not handsome. He does not have to be both not rich and not handsome (though
of course he may be!).
Similarly, consider the set of people who like either plain chocolate or milk chocolate.
Anyone not in this set must dislike both plain and milk chocolate.
33
Boolean Algebra Identities
(B1) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) (B2) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
(B3) A ∪ (A ∩ B) = A (B4) A ∩ (A ∪ B) = A
(B5) A ∪ (A ∩ B) = A ∪ B (B6) A ∩ (A ∪ B) = A ∩ B
(B7) A∪B =A∩B (B8) A ∩ B = A ∪ B
(B9) A=A
(B10) A∪A=A (B11) A∩A=A
(B12) A∪A=1 (B13) A∩A=0
(B14) A∪0=A (B15) A∩1=A
(B16) A∪1=1 (B17) A∩0=0
(B18) A∪B =B∪A (B19) A∩B =B∩A
(B20) A ∪ (B ∪ C) = (A ∪ B) ∪ C (B21) A ∩ (B ∩ C) = (A ∩ B) ∩ C
(B22) 0=1 (B23) 1=0
Note the duality between the identities in the two columns: those on the right can be
formed from those on the left by interchanging ∪ and ∩ and also interchanging 0 and 1.
These identities are not all independent: for example, (B5) can be deduced from (B2),
(B12), (B19) and (B15).
Some of these identities have special names:
(B1) and (B2) are distributive laws;
(B3) and (B4) are absorption laws;
(B5) and (B6) are redundancy laws;
(B7) and (B8) are De Morgan’s laws;
(B18) and (B19) are commutative laws; and
(B20) and (B21) are associative laws.
These identities can be extended to any compound sets. Thus, since A ∩ A = 0, it
follows that (B ∪ C) ∩ B ∪ C = 0 also.
Recall from Examples 1.2 and 1.4 that the associative laws allow us to write A ∪ B ∪ C
and A ∩ B ∩ C without brackets and with no ambiguity, but that any expression involving
both union and intersection must have brackets to indicate which operation is to be
performed first.
Solution. (i) It is possible to construct the required area from its component pieces.
34
A∩C B ∪ (A ∩ C) A ∩ (B ∪ (A ∩ C))
Alternatively, the original expression can be simplified first, using the Boolean identities.
A ∩ (B ∪ (A ∩ C)) = (A ∩ B) ∪ (A ∩ A ∩ C) = (A ∩ B) ∪ (0 ∩ C) = (A ∩ B) ∪ 0 = A ∩ B
which gives the same Venn diagram very simply.
(ii)-(iv) In lecture.
(i) (ii)
Solution. (i) Break the area up into bits for which expressions are known.
so one possible expression is (A ∩ B) ∪ (B ∩ C), though there are other equivalent expres-
sions.
(ii) In lecture.
35
Truth tables can also be used to solve Venn diagram problems. We use 1 to indicate
that we are in a set and 0 to mean that we are not.
Example 4.13 Draw Venn diagrams to represent the following sets by first constructing
a truth table for each one.
(i) (A ∩ B) ∪ (A ∩ B) (ii) A ∪ (B ∩ C)
Solution. (i) The 4 regions of the Venn diagram correspond to the 4 lines of the truth table.
(A ∩ B) ∪ (A ∩ B)
(ii) In lecture.
36
5 Guessing or Proving?
5.1 Induction
A common technique in investigative maths is to solve a general problem by first solving
it for some particular, usually small, numbers; then spot a pattern in the results; and
finally generalise this to all numbers. Sadly, the generalisation process is not always as
obvious as it looks.
Example 5.1 (i) Find a simple formula for 1 + 2 + 3 + 4 + · · · + n and hence find
1 + 2 + 3 + 4 + · · · + 100.
(ii) Draw a circle and mark n points on its circumference. Join every point to every other
point with a straight line. How many separate regions is the circle divided into?
Solution. In lecture.
The second example above shows that it is not always safe to say, “It works for 1, 2,
3 and 4 so it must work for all numbers”. We need to find a more rigorous approach to
such problems.
Example 5.2 (i) Prove that 1 + 2 + 3 + 4 + ... + n = 12 n(n + 1) for all positive integers n.
(ii) Using the fact that log(ab) = log a + log b prove that
log(a1 a2 a3 . . . an ) = log a1 + log a2 + log a3 + · · · + log an for all positive integers n.
(iii) In matrix theory, using the fact that (AB)T = B T AT for all square matrices A,
B of the same order, prove that (M n )T = (M T )n for all positive integers n.
37
Solution. (i) Let P (n) be the statement 1 + 2 + 3 + 4 + · · · + n = 12 n(n + 1).
The base step P (1) says 1 = 21 .1.2, which is obviously true.
Let us assume that P (k) is true for some particular integer k,
ie 1+2+3+4+· · ·+k = 21 k(k +1). For the inductive step, we want to prove that P (k +1)
must also be true. P (k + 1) is the statement 1 + 2 + 3 + · · · + (k + 1) = 21 (k + 1)(k + 2).
LHS = 1 + 2 + 3 + · · · + (k + 1)
= (1 + 2 + 3 + · · · + k) + (k + 1)
= 21 k(k + 1) + (k + 1) by the induction hypothesis P (k)
1 1
= 2 k(k + 1) + 2 .2(k + 1)
= 12 (k + 1)(k + 2)
= RHS
so we have proved the inductive step, that P (k + 1) follows from P (k).
Hence 1 + 2 + 3 + 4 + · · · + n = 21 n(n + 1) for all positive integers n by the Principle
of Mathematical Induction.
(ii)-(iii) In lecture.
Example 5.3 Prove that the sum of n terms of the general arithmetic series
Solution. In lecture.
38
Geometric Series. These are series in which successive terms are multiplied by a con-
stant factor, the common ratio. For example,
2 + 6 + 18 + 54 + · · · + 1458 (common ratio 3).
5 + 50 + 500 + 5000 + 50000 (common ratio 10).
8 + 4 + 2 + 1 + 21 + 14 + · · · (common ratio 21 ).
a + ar + ar2 + ar3 + ar4 + · · · (common ratio r).
Example 5.6 A wise man, having solved a particularly tricky problem for the king, was
allowed to choose his own reward. He asked for one grain of rice for the first square of a
chessboard, two for the second, four for the third, eight for the fourth and so on for the
entire board. This didn’t seem much to the king and he gladly agreed. How many grains
of rice would this amount to?
There is a shorthand notation for sums of series, using Σ, the Greek letter sigma
(similar to our S), to stand for ‘sum’. Thus:
9
X
k 3 = 53 + 63 + 73 + 83 + 93
k=5
39
n
X
k = 1 + 2 + 3 + ··· + n
k=1
n
X
k 2 = 12 + 22 + 32 + · · · + n2
k=1
n
X
xk = 1 + x + x2 + x3 + · · · + xn
k=0
n
X
xr = 1 + x + x2 + x3 + · · · + xn
r=0
where the lower and upper labels on Σ indicate the range of values taken by k or r, the
index of summation. Note that the last two examples are exactly the same. The index
of summation is a dummy variable and can be replaced by any letter since it disappears
from the final expression.
It is often useful, particularly in proofs by induction, to note that
n+1
X
ar = a1 + a2 + a3 + · · · + an + an+1
r=1
n
X
= ar + an+1
r=1
Example 5.7 Prove by induction that the sum of the first n odd numbers is n2 .
Solution. Note that the nth odd number is 2n − 1 and let P (n) be the statement
1 + 3 + 5 + · · · + (2n − 1) = n2 .
Base step: P (1) says that 1 = 12 , which is clearly true.
Inductive step: suppose that P (k) is true for some k, ie 1 + 3 + 5 + · · · + (2k − 1) = k 2 .
We must prove that P (k + 1) is true, ie that 1 + 3 + 5 + · · · + (2(k + 1) − 1) = (k + 1)2 .
LHS = 1 + 3 + 5 + · · · + (2(k + 1) − 1)
= [1 + 3 + 5 + · · · + (2k − 1)] + (2k + 1)
= k 2 + (2k + 1) (by the induction hypothesis)
= (k + 1)2
= RHS
Hence the sum of the first n odd numbers is n2 for all positive integers n by the Principle
of Mathematical Induction.
40
5.3 Propositions and proofs
A proposition is a statement which is either true or false. Consider the following propo-
sitions.
(i) There is no largest prime number.
(ii) If A and B are matrices with AB = 0 then either A or B is the zero matrix.
√
(iii) 2 is a rational number.
(iv) If the matrix product AB is diagonal then so are the matrices A and B.
(v) If the product of two integers is even, then at least one of them is even.
(vi) If x2 > 1 then x > 1 where x is a real number.
There are a number of standard types of proof which can be useful when trying to
determine if such propositions are true or false.
Example 5.8 Show that propositions (ii) and (iv) above are false.
!
0 1
Solution. (ii) Take A = B = . Then AB = 0 but neither A nor B is the zero
0 0
matrix.
(iv) In lecture.
The essence of a proof by contradiction is to assume that what you want to prove is not
true and prove that this leads to a contradiction, thus showing that your assumption must
have been wrong. This is sometimes known as reductio ad absurdum, ‘by reducing it to
the absurd’.
Example 5.9 Prove that propositions (i) and (v) above are true and that (iii) is false.
Solution. (v) Let us assume the opposite, ie we can find two odd integers p and q
with pq even. But p can be written 2n + 1 and q can be written 2m + 1 and so pq =
(2n + 1)(2m + 1) = 4mn + 2n + 2m + 1 = 2(2mn + n + m) + 1 which must be odd. This
is a contradiction and so our assumption must have been false, thus proving that (v) is
true.
(i) and (iii) in lecture.
41
5.3.3 Converse
Many propositions are of the form ‘if p then q’, where p and q are more basic propositions
(eg (ii), (iv), (v) and (vi) above). Such implications have a converse, formed by switching
round the if and then parts.
It is very important to note that, whether or not the original implication is true, the
converse may be true or false. There is no guarantee that a proposition and its converse
will be both true or both false.
Example 5.10 Determine whether the following implications are true or false. Give the
converse of each and decide whether the converse is true or false.
(i) If x > 1 then x2 > 1.
(ii) If Mariska is not Dutch then she is German.
(iii) If x = 6 then 2x − 3 = 9.
Solution. (i) The given proposition is true. The converse is “if x2 > 1 then x > 1”. This
is false: we could take −2 as a counterexample.
(ii) Unless we have some more information about Mariska, the given implication is false.
The converse is “if Mariska is German then she is not Dutch”. This is true.
(iii) In lecture.
If we know that the implication ‘if p then q’ is true, then we say that p is sufficient
for q to hold and that q is necessary for p to hold. This fits in with our everyday usage
of necessary and sufficient.
Example 5.11 Identify necessary and sufficient conditions in the following implications.
(i) If it is raining then the pavements are wet.
(ii) If John is the brother of Sarah then Sarah is the sister of John.
Solution. (i) ‘It is raining’ is sufficient but not necessary for the pavements to be wet.
‘The pavements are wet’ is a necessary but not sufficient condition for it to be raining. (I
may just have washed my car.)
(ii) In lecture.
42
5.3.4 Contrapositive
The contrapositive of ‘if p then q’ is ‘if not-q then not-p’. The contrapositive is logically
equivalent to the original implication, ie they are both true or both false. Consideration
of a few implications should easily convince you of this.
The proposition ‘if I lose my key then I shall be locked out’ is true. Its contrapositive
is ‘if I am not locked out then I have not lost my key’ and that is also true.
The proposition ‘if x = 5 then 2x = 7’ is false. Its contrapositive is ‘if 2x 6= 7 then
x 6= 5’ and that is also false.
A proof by contradiction is essentially using this equivalence. In Example 5.9 we
wanted to prove that if pq is even then p or q is even. Instead we proved the contrapositive:
if neither p nor q is even (ie both odd) then pq is not even.
Example 5.12 Give the contrapositive and the converse of each of these implications.
(i) If it snows tonight then I shall go skiing on Saturday.
(ii) Given that x > 10, if x is prime then x is odd.
(iii) If I am Scottish then I am British.
Solution. In lecture.
43
6 Propositional Calculus
Having looked at some of the basic terminology and tools for working with propositions,
we now go on to consider more ways of combining them.
For example:
if p is the proposition ‘the sun is shining’
and q is the proposition ‘the birds are singing’
then p ∧ q denotes ‘the sun is shining and the birds are singing’,
p ∨ q denotes ‘the sun is shining or the birds are singing’, and
p denotes ‘the sun is not shining’.
Earlier we saw that the sets in Venn diagrams could be used to stand for propositions
and that, along with the operations ∩ and ∪, they formed a Boolean algebra. Note the
similarity in symbol and meaning between ∩ and ∧ (AND) and between ∪ and ∨ (OR).
It is therefore not surprising that the set of propositions, together with the signs ∧ and ∨
also form a Boolean algebra. All the laws we had for sets, Venn diagrams and switching
circuits apply to propositions also.
To complete the Boolean algebra, we need to find meanings for 1 and 0. 1 is the
proposition that is always true, called a tautology, and 0 is the proposition that is always
false, called a contradiction. Thus p ∨ p = 1 (eg either the sun is shining or the sun is not
shining - a tautology) and p ∧ p = 0 (eg the sun is shining and the sun is not shining - a
contradiction).
We say that two compound propositions are logically equivalent if they are different
44
ways of saying the same thing, eg p ∨ (p ∧ q) = p ∨ q. In this case the two propositions
will have the same truth table.
It is useful to have a symbol for the compound proposition ‘if p then q’, sometimes
called a conditional proposition. We shall denote this by ‘p → q’, read ‘p implies q’.
Although this looks like a new operation on the set of propositions, we shall see later that
it can in fact be expressed in terms of the existing operations and, or and not.
p q p∧q p q p∨q p p
T T T T T T T F
T F F T F T F T
F T F F T T
F F F F F F
From these three tables we can construct the truth tables for any compound proposition.
45
Example 6.1 Construct the truth tables for (i) (p∧q)∨(p∧q) and (ii) (p∨(p∧q))∧(p∨r).
Solution. (i) 1 2 3 4 5 6 7
p q p p ∧ q q p ∧ q (p ∧ q) ∨ (p ∧ q)
T T F F F F F
T F F F T T T
F T T T F F T
F F T F T F F
Column 3 is the negation of column 1. 4 is the conjunction of 2 and 3. 5 is the negation
of 2. 6 is the conjunction of 1 and 5. Finally 7 is the disjunction of 4 and 6.
(ii) In lecture.
The truth table for the conditional operator → is perhaps not as intuitively obvious as
the ones we have encountered so far. Consider the proposition ‘if the sun shines tomorrow
then I shall go for a walk’. If I know that this proposition is true, then it tells me what
will happen if the sun shines, but it tells me nothing about what will happen if the sun
does not shine: I may or may not go for a walk anyway.
Hence this is equivalent to ‘either the sun does not shine or it shines and I go for a
walk’, which in turn is equivalent to ‘either the sun does not shine or I go for a walk’.
Generalising, we can see that p → q is equivalent to p ∨ q and hence construct the
truth table for →.
p q p p∨q p→q
T T F T T
T F F F F
F T T T T
F F T T T
The last two columns must be exactly the same since we have seen that the propositions
are logically equivalent. So p → q is false only when p is true and q is false, ie only when
a true proposition implies a false one. If p is false, this does not say anything about q and
so the implication is bound to be true.
Example 6.2 (i) Show by constructing truth tables that (p → q) ≡ (q → p). (The sign
≡ means ‘is logically equivalent to’.)
(ii) Show that (p ↔ q) ≡ ((p ∧ q) ∨ (p ∧ q)).
Solution. (i) p q p → q p q q p q→p
T T T T T F F T
T F F T F T F F
F T T F T F T T
F F T F F T T T
46
This shows that a conditional statement and its contrapositive have the same truth table
and so are logically equivalent. Alternatively, we could prove this by using Boolean algebra
equivalences:
q → p = q ∨ p = q ∨ p = p ∨ q = p → q.
(ii) In lecture.
47
From (3), r is false so r must be true. From (1), since r is true c must be true. But from
(2) c is true so c must be false. This is a contradiction and so our assumption that the
argument is not valid must have been wrong. Hence the argument is valid.
p → q, q∨r ; ∴ p→r
Solution. In lecture. Notice that in this example we are not told what the propositions
are. The point is that the validity of the argument is independent of the meaning of p, q
and r.
The negation of ‘all people wear jeans’ is ‘some people do not wear jeans’, or even ‘at
least one person does not wear jeans’. It is not ‘no people wear jeans’.
The negation of ‘some people wear jeans’ is ‘no people wear jeans’.
In general, the negation of (∀x)(p) is (∃x)(p) and the negation of (∃x)(p) is (∀x)(p),
ie interchange ∀ and ∃ and negate whatever follows.
Example 6.4 Consider whether the following statements are true or false and write down
the negation of each one.
(i) (∀n ≥ 3)(n2 ≥ 50) (ii) (∃x > 3)(x2 < 20)
(iii) (∀n ∈ N)((n2 is divisible by 4)→ (n is divisible by 4)).
Solution. (i) (∀n ≥ 3)(n2 ≥ 50) is false. Take 3 as a counterexample. The negation is
(∃n ≥ 3)(n2 < 50) and, of course, this is true.
(ii) and (iii) In lecture.
48
6.4 Summing up
We have now seen 3 examples of Boolean algebra: switching circuits, sets (illustrated
by Venn diagrams) and propositional logic. We have also seen 3 ways of representing
problems: pictorially, by algebra and by truth tables. We even saw earlier that some
simple logic problems can be represented by Venn diagrams.
Some people find one of these ways easier as an aid to thinking and others prefer one
of the other methods. Unless a question specifies which method is required, it is up to
you to use the method that comes most easily to you.
49