140
MA113: LOGIC AND DISCRETE MATHEMATICS W. R. Johnstone AUTUMN: 2004

Logic and Discrete Mathematics

Embed Size (px)

Citation preview

Page 1: Logic and Discrete Mathematics

MA113:

LOGIC AND DISCRETE MATHEMATICS

W. R. Johnstone

AUTUMN: 2004

Page 2: Logic and Discrete Mathematics

REFERENCES:

[1] Introductory Logic and Sets for Computer Scientists: N. Nissanke: Addi-son Wesley Longman: 004.015113

[2] Logic (Schaum’s Outline Series): J. Nolt and D. Rohatyn: FOLIO-160-NOL

[3] Set Theory and Related Topics (Schaum’s Outline Series): S. Lipschutz:FOLIO-511.322-LIP

[4] Discrete Mathematics: (Schaum’s Outline Series): S. Lipschutz and M. L.Lipson: FOLIO-510-LIP

[5] Discrete Mathematics with Applications: S. S. Epp: 510-EPP

[6] Introduction to Discrete Mathematics and Formal System Specification:D. C. Ince: Oxford: 004.0151-INC

[7] The Z Notation: J. M. Spivey: Prentice-Hall: 005.133-Z/SPI

[8] Sets, Logic and Axiomatic Theories: R. R. Stoll: Freeman: 517.1

[9] Set Theory and Logic: R. R. Stoll: 511.322-STO

[10] The Essence of Logic: J. J. Kelly: Prentice Hall: 511.3-KEL

[11] Introduction to Symbolic Logic: A. H. Basson: 511.3-BAS

[12] Introduction to Symbolic Logic: S. K. Langer: 511.3-LAN

[13] Logic and its Applications: E. Burke: 511.3-BUR

[14] Mathematical Logic for Computer Science: M. Ben-Ari: 511.3-BEN

[15] Modern Logic : a text on Elementary Symbolic Logic: G. Forbes: 511.3-FOR

[16] Symbolic Logic: I. M. Copi: 160-COP

[17] Symbolic Logic: R. H. Thomason: 511.3-THO

[18] Elementary Set Theory: K-T. Leung and D. L-C Chen: 511.322-LEU

[19] Set Theory (Schaum’s Outline Series): S. Lipschutz: FOLIO–517.1-LIP

Page 3: Logic and Discrete Mathematics

Contents

1 PROPOSITIONAL LOGIC 11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Propositions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Connectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 The connective ¬ . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.5 The Connective ∧ . . . . . . . . . . . . . . . . . . . . . . . . . . 31.6 The Connective ∨ . . . . . . . . . . . . . . . . . . . . . . . . . . 31.7 The Connective =⇒ . . . . . . . . . . . . . . . . . . . . . . . . . 31.8 The Connective ⇐⇒ . . . . . . . . . . . . . . . . . . . . . . . . . 41.9 Truth Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.10 Brackets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.11 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.12 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.13 Applications to Computer Science . . . . . . . . . . . . . . . . . 81.14 Truth Tables in General . . . . . . . . . . . . . . . . . . . . . . . 91.15 Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.16 Logical Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . 101.17 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.18 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111.19 Solution to Exercise 1.15 . . . . . . . . . . . . . . . . . . . . . . . 121.20 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.21 Tautologies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.22 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.23 Contradictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131.24 Definition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.25 The Propositions True and False . . . . . . . . . . . . . . . . . . 141.26 Logical Laws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.27 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 161.28 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 171.29 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 181.30 Inference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181.31 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 211.32 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 221.33 The Method of Formal Proof . . . . . . . . . . . . . . . . . . . . 221.34 Inference Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231.35 Formal Proofs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251.36 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 261.37 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

i

Page 4: Logic and Discrete Mathematics

1.38 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 271.39 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 281.40 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 281.41 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

2 PREDICATE LOGIC 312.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.2 Predicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.3 Infix Notation for Binary Predicates . . . . . . . . . . . . . . . . 332.4 The Binary Predicates <, ≤, >, ≥ and = . . . . . . . . . . . . . 332.5 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.6 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.7 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352.8 Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.9 Restricted Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . 372.10 The Scope of a Quantifier . . . . . . . . . . . . . . . . . . . . . . 402.11 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.12 Multiple Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . 432.13 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 452.14 Variables and Constants . . . . . . . . . . . . . . . . . . . . . . . 462.15 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

3 PROOF BY INDUCTION 523.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 523.2 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 533.3 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 543.4 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 553.5 WARNING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563.6 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 573.7 Generalizations of Proof by Induction . . . . . . . . . . . . . . . 583.8 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

4 BASIC SET THEORY 604.1 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604.2 The Universal Set . . . . . . . . . . . . . . . . . . . . . . . . . . 624.3 Subsets of a Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624.4 Vacuous Truth . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634.5 Set Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634.6 Venn Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . 654.7 Disjoint Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 704.8 Cardinality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714.9 Sets of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714.10 The Power Set of a Set . . . . . . . . . . . . . . . . . . . . . . . . 724.11 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 724.12 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 734.13 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 744.14 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

ii

Page 5: Logic and Discrete Mathematics

5 RELATIONS 785.1 Ordered Pairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 785.2 Equality of Ordered Pairs . . . . . . . . . . . . . . . . . . . . . . 785.3 Cartesian Product of Sets . . . . . . . . . . . . . . . . . . . . . . 795.4 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 795.5 Relations on a Set . . . . . . . . . . . . . . . . . . . . . . . . . . 805.6 Domain and Range of a Relation . . . . . . . . . . . . . . . . . . 815.7 The Inverse of a Relation . . . . . . . . . . . . . . . . . . . . . . 825.8 Relational Image . . . . . . . . . . . . . . . . . . . . . . . . . . . 835.9 Restrictions of Relations . . . . . . . . . . . . . . . . . . . . . . . 845.10 Set Operations on Relations . . . . . . . . . . . . . . . . . . . . . 855.11 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 855.12 Relational Overriding . . . . . . . . . . . . . . . . . . . . . . . . 875.13 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 895.14 Composition of Relations . . . . . . . . . . . . . . . . . . . . . . 895.15 The Directed Graph of a Relation on a Set . . . . . . . . . . . . 925.16 The Relation R2 . . . . . . . . . . . . . . . . . . . . . . . . . . . 935.17 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 935.18 The Relation R3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 955.19 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 955.20 The Relations Rn for a natural number n . . . . . . . . . . . . . 965.21 Non-Mathematical Example . . . . . . . . . . . . . . . . . . . . . 985.22 Properties of Relations . . . . . . . . . . . . . . . . . . . . . . . . 995.23 Partitions of a Set . . . . . . . . . . . . . . . . . . . . . . . . . . 1035.24 Equivalence Relations . . . . . . . . . . . . . . . . . . . . . . . . 1045.25 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

6 FUNCTIONS 1096.1 Total and Partial Functions . . . . . . . . . . . . . . . . . . . . . 1096.2 Injective Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 1116.3 Surjective Functions . . . . . . . . . . . . . . . . . . . . . . . . . 1146.4 Bijective Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 1166.5 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 1186.6 Functions as Operators or Procedures . . . . . . . . . . . . . . . 1196.7 Relational Images of Functions . . . . . . . . . . . . . . . . . . . 1196.8 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 1206.9 Functions Defined by Formulae . . . . . . . . . . . . . . . . . . . 1236.10 Composition of Functions . . . . . . . . . . . . . . . . . . . . . . 1236.11 Number Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1256.12 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1266.13 Operations on Sequences . . . . . . . . . . . . . . . . . . . . . . . 1276.14 Functional Overriding . . . . . . . . . . . . . . . . . . . . . . . . 1286.15 Worked Example . . . . . . . . . . . . . . . . . . . . . . . . . . . 1306.16 Bags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1316.17 Operations on Bags . . . . . . . . . . . . . . . . . . . . . . . . . . 133

iii

Page 6: Logic and Discrete Mathematics

Chapter 1

PROPOSITIONAL LOGIC

1.1 Introduction

In Mathematics and Computer Science we need to express statements in a veryprecise and unambiguous way, leaving no doubt as to what is meant. Thisrequires a form of language which is more rigid and structured than that usedin everyday life. In this chapter we will begin the development of such a languagefrom quite a basic level.

We will first consider various ways of constructing statements. We start withfairly simple statements such as:

A: It is raining,

B: The sun is shining;

and create such ‘compound’ statements as:

[1] “A or B”,i.e. it is raining or the sun is shining,

[2] “A and B”,i.e. it is raining and the sun is shining,

[3] “not A”,it is not raining,

[4] “if A then not B”,if it is raining then the sun is not shining.

Propositional Logic is the study of such processes and related deductive reason-ing using symbols to represent the basic objects of the study.

1.2 Propositions

A proposition or statement is a sentence which asserts something that is eithertrue or false. Such a statement must have a precise and unambiguous meaningso that its truth or falsity can definitely be decided. Thus all propositions havean assigned truth value; T , when the proposition is true, and F , when theproposition is false. The following sentences are propositions:

1

Page 7: Logic and Discrete Mathematics

It is snowing.

It is not cloudy.

2 + 2 = 4.√

2 is an integer.

However the following sentences or phrases are not propositions:

Do you like kippers?

If you pass go, collect £200.

A pot of gold.

A simple statement which links two objects is often called an ‘atomic’ statement.Atomic statements will be represented symbolically by a letter such as ‘A’ orby a letter with a numerical subscript such as ‘A5’. Such a symbol (or symbols)used in this way will be called a propositional letter. An atomic statement itselfhas a symbolic form often of the type ‘a x b’, where ‘a,b’ are phrases whichrepresent the objects and ‘x’ is a phrase which represents the link. For exampleif ‘a x b’ represents the atomic statement ‘five is greater than three’ then ‘a’represents the number ‘five’, ‘b’ represents ‘three’ and ‘x’ represents the linkingphrase ‘is greater than’.

1.3 Connectives

The following symbols, known as connectives, are used to build up more compli-cated propositions from simpler ones. We may start the building process withatomic propositions:

Connective Approximate English Translation Name¬ not Negation∧ and Conjunction∨ or Disjunction

implies=⇒ OR Implication

if . . . thenimplies and is implied by

OR⇐⇒ if and only if Equivalence

ORis equivalent to

The right hand column is headed “approximate English translation” becauseEnglish words are often used loosely and inconsistently. In order to properlydefine the logical connectives in this table, we will have to impart a precise andunambiguous meaning to the equivalent words and phrases.

1.4 The connective ¬From any proposition P we can form a new proposition ¬P (pronounced “notP”). For example, if P is the proposition “The sun is shining” then ¬P is the

2

Page 8: Logic and Discrete Mathematics

proposition “The sun is not shining” (or any form of words that has the samemeaning). ¬P asserts that P is false. Indeed if P is true, then ¬P is false, but,if P is false, then ¬P is true. ¬P is sometimes called the negation of P . Given aproposition P there are usually many ways of expressing the proposition ¬P inwords; we attempt to choose a representation which ‘feels’ right, i.e. one whichis widely regarded as acceptable. For example, if P is the statement “The busis not red”, then the statement “The bus is red” is a more acceptable form for¬P than “The bus is not not red”. Note that a double negative is often usedincorrectly in colloquial English. For example if P is the proposition “Trafficlights are never blue”, then P is sometimes incorrectly expressed as “Trafficlights are not never blue”. This latter sentence is really the negation, ¬P , of P .A double negation is probably used in the belief that the extra ‘not’ emphasizesthe negation.

1.5 The Connective ∧From two propositions A and B we can form a new proposition A ∧ B (pro-nounced “A and B”). For example, if A is the proposition “2 + 2 = 4” and Bis the proposition “

√2 is an integer”, then A ∧B is the proposition “2 + 2 = 4

and√

2 is an integer”. A ∧B is true when A and B are both true, and is falseotherwise. Thus A ∧B asserts that A and B are both true.

1.6 The Connective ∨From two propositions A and B we can form a proposition A ∨B (pronounced“A or B”). For example, if A and B are the propositions stated in the previoussection, then A ∨B is the proposition “2 + 2 = 4 or

√2 is an integer”. The use

of the word ‘or’ in this context must be made more precise than the ordinaryuse of the word in the English language. In language it may be used in both aninclusive and an exclusive sense. In our context we use it in the inclusive sense.Thus A ∨ B asserts that one or both of the statements A,B are true. It doesNOT assert that one and only one of these statements are true (the exclusivecase)1. Thus A ∨ B is false only when both A and B are false; in all the othercases A∨B is true. The symbol ∨ has the meaning conveyed by “and/or” whichis sometimes used in written English.

1.7 The Connective =⇒From two propositions A and B we can form a new proposition A =⇒ B (pro-nounced “A implies B”). The meaning of A =⇒ B is roughly that of “if A thenB”. Thus A =⇒ B is a proposition which asserts that if A is true then B isalso true. If on the other hand A is false then B could be either true or false.Thus A =⇒ B asserts that either A is false or B is true (or both); i.e. (¬A)∨Bis true. We may therefore define the connective =⇒ by saying that A =⇒ Bmeans the same thing as (¬A) ∨ B. Note that A does not have to be true for

1In ordinary language I may assert that “I shall have a kipper for lunch or I shall have apork pie for lunch”, with ‘or’ used in an exclusive sense (to mean that “I shall have either akipper or a pork pie, but NOT both, for lunch”).

3

Page 9: Logic and Discrete Mathematics

A =⇒ B to be true. The only way for A =⇒ B to be false is for A to be trueand B to be false. Thus the following are true statements:

[1] 2 + 2 = 4 =⇒ 22 = 4;

[2] 2 + 3 = 4 =⇒ 22 = 4;

[3] 3 + 2 = 4 =⇒ 22 = 3.

whilst the following statement is false:

2 + 2 = 4 =⇒ 22 = 3.

1.8 The Connective ⇐⇒From two propositions A and B we may form a new Proposition A ⇐⇒ B(pronounced “A implies B and is implied by B” or “A if and only if B” or “Ais equivalent to B”). The proposition A ⇐⇒ B asserts that both A =⇒ B andB =⇒ A are true propositions. It is easy to verify that A ⇐⇒ B asserts thateither both A and B are true or both are false. Thus the propositions:

2 + 2 = 4 ⇐⇒ 22 = 4;2 + 3 = 4 ⇐⇒ 22 = 3;

are both true, whereas the propositions:

2 + 2 = 4 ⇐⇒ 22 = 3;2 + 3 = 4 ⇐⇒ 22 = 4;

are both false.

1.9 Truth Tables

If a proposition is true, we say that it has “truth value” T , whereas, if theproposition is false, we say that it has truth value F . Thus every propositionhas a truth value. For example “2 + 2 = 4” has truth value T and “22 = 3” hastruth value F .

We can assign a “truth table” to any formal compound statement whichinvolves only symbols for “atomic” statements and the symbols which representconnectives. The table gives the resultant truth value for the compound state-ment for every possible truth value assignments to the atomic statements. Thusthe truth table for the proposition ¬A is:

A ¬AT FF T

The table indicates that ¬A has truth value F when A has truth value T and¬A has truth value T when A has truth value F .

Let us consider the truth table for the proposition A ∧ B. There are fourdifferent ways to assign truth values to A and B. A ∧ B is only true in one ofthese four cases; namely when A and B are both true. Thus the truth table forA ∧B is:

4

Page 10: Logic and Discrete Mathematics

A B A ∧BT T TT F FF T FF F F

Recall that the proposition A ∨ B is true when one or both A,B are true.Thus A ∨ B has the truth value F only when both A and B have truth valueF . Thus the truth table of A ∨B is:

A B A ∨BT T TT F TF T TF F F

Again recall that A =⇒ B is false only when A is true and B is false. ThusA =⇒ B has truth value T in all cases except when A has truth value T and Bhas truth value F in which case it has truth value F . Thus the truth table forA =⇒ B has truth table:

A B A =⇒ BT T TT F FF T TF F T

Finally recall that A ⇐⇒ B is true only when A and B are both true orboth false. It follows that A ⇐⇒ B has truth table:

A B A ⇐⇒ BT T TT F FF T FF F T

1.10 Brackets

Given atomic statements A,B and C, can we assign a meaning to the ‘sentence’A ∨ B ∧ C? We may pronounce this sentence as “A or B and C”. Howeverthere appears to be some ambiguity about what is meant here. The ambiguitybecomes somewhat clearer if we use punctuation: “A or B, and C”, or “A,or B and C”. The ambiguity arises from the order in which we apply theconnectives to form the compound statement. To clarify the order in which theconnectives are applied we will use brackets2. Thus we may write “(A∨B)∧C”or “A ∨ (B ∧ C)”. For example (A ∨ B) ∧ C is formed by first applying theconnective ∨ to A and B and then applying the connective ∧ to A ∨B and C.The proposition A∨ (B ∧C) is obtained in the same way by reversing the orderin which these connectives are applied. To emphasize the distinction betweenthe statements let us consider their truth values. Suppose that A and B are

2Brackets are used in this way in arithmetic and algebra. Thus for example 3 + (2 × 4)means 3 + 8, which equals 11, whereas (3 + 2)× 4 means 5× 4, which equals 20

5

Page 11: Logic and Discrete Mathematics

true and C is false. Then (A∨B)∧C is clearly false, since C is false. HoweverA ∨ (B ∧ C) is clearly true, since A is true. Thus the statements cannot beconsidered the same since they have different truth values when A and B aretrue and C is false. To recap, with proper use of brackets, compound statementscan be made logically precise (i.e. without any ambiguity).

Similarly ¬(A ∧ B) is different from (¬A) ∧ B. When A and B are false,¬(A ∧B) is true whereas (¬A) ∧B is false.

The use of brackets can become rather cumbersome when dealing with propo-sitions which involve very many connectives. To simplify the expression of suchstatements we will employ a convention concerning an order of “precedence” ofconnectives3. We arrange connectives in the following order of precedence: ¬ ∧∨ =⇒ ⇐⇒. Thus for example we apply the connective ¬ before ∧ and ∨ before⇐⇒. The following examples illustrate the use of the convention:

[1] A ∧B ∨ C means (A ∧B) ∨ C;

[2] ¬A ∨B means (¬A) ∨B;

[3] ¬A∨B =⇒ C∧D∨E means ((¬A)∨B) =⇒ ((C∧D)∨E). The connectivesare performed in their order of precedence. Thus we first apply ¬ to Ato obtain ¬A. The next connective to apply is ∧ to obtain the statementC ∧D. Next we apply the connective ∨. There are two instances of thisconnective in the proposition. Thus we form the two statements (¬A)∨Band (C ∧ D) ∨ E. Finally we apply the connective =⇒ to complete theproposition. Note that at each stage in this process brackets are usedto bound each of the two statements which are joined by the connectiveused. We need not use brackets to bound the final proposition. Eachopening bracket, (, must be paired with a closing bracket, ), so that theyboth bound a complete syntactically correct statement. [It may help inreading a complicated proposition with many brackets if we use a countingprocedure. We count the number of opening brackets encountered whichhave not been paired off with the associated closing bracket. We willrefer to this number as the ‘level’. For example we begin at level 0 and onencountering the first opening bracket we are at level 1. If in parsing alongan expression we encounter an opening bracket which begins level n, say,then its associated closing bracket is the first closing bracket at the samelevel, n, which is reached as we continue to parse along the expression.]

[4] A∧ (B ∨C =⇒ D)∨E ⇐⇒ G means ((A∧ ((B ∨C) =⇒ D))∨E) ⇐⇒ G.Note that the convention on precedence will not allow us to remove thebrackets binding the statement B ∨ C =⇒ D. The proposition A ∧ B ∨C =⇒ D∨E ⇐⇒ G means (((A∧B)∨C) =⇒ (D∨E)) ⇐⇒ G, which is notthe same as the proposition ((A∧((B∨C) =⇒ D))∨E) ⇐⇒ G. The ruleson precedence will perhaps allow the removal of many but not all bracketswithout changing the meaning of a proposition. Also we will sometimesleave removable brackets in place if it makes it easier to interpret theproposition.

3A similar convention is used to order the arithmetic operations. For example we write3 + 2× 4 to mean 3 + (2× 4). We say that multiplication (×) takes precedence over addition(+); that is multiplication is performed before addition.

6

Page 12: Logic and Discrete Mathematics

1.11 Exercise

Given statements A and B. Using only the connectives ¬ ∧ and ∨ is it possibleto construct from A and B a proposition P with truth table:

A B PT T FT F TF T FF F T

Given any such truth table (there are 16 different tables), is it possible to con-struct a proposition P with that truth table?

1.12 Worked Example

Translate the following English sentences into propositional logic, using theletters A for “the sun shines”, B for “the game of football takes place”, C for“the game of hockey takes place” and D for “it is raining”.

[1] If the sun shines then the game of football will take place.

[2] The games of football and hockey will both take place if the sun shines.

[3] Either the game of football or the game of hockey but not both will takeplace.

[4] If the sun does not shine then the game of football or the game of hockeywill be cancelled.

[5] If the game of hockey is cancelled then the decision on whether to playthe game of football will depend on whether it is raining.

Solution. As this illustrates, spoken and written English uses many forms ofwords, and one must think carefully what they mean when translating them intothe precise language of propositional logic. Sometimes English words might beso ambiguous that their intended meaning is uncertain, and consequently onecan only offer two or more possible translations. If this arose in practice, onewould presumably ask the person concerned to clarify what is actually meant.Let us now attempt to translate the above sentences.

[1] This says that “if A then B” or (in other words) “A implies B”. Thus, inpropositional logic, it is the proposition A =⇒ B.

[2] Do not be deceived by the word order in this sentence. The statement isjust another way of saying “If the sun shines then the games of football andhockey will both take place” or more clumsily “If the sun shines then thegame of football will take place and the game of hockey will take place”.It follows that the translation is A =⇒ (B ∧ C), or, using the conventionon ordering, A =⇒ B ∧ C.

7

Page 13: Logic and Discrete Mathematics

[3] This might require some thought. The words “but not” is effectively thesame as “and not”. The word “but” is used to contrast the two connectingstatements and means the same as “on the other hand”. It is used in thesame conjunctive sense as the word “and” and not in the disjunctive senseof the word “or”. Thus the given statement may expressed in the form“Either the game of football takes place or the game of hockey takes placeand the games of football and hockey do not both take place”. Thistranslates to (B ∨ C) ∧ (¬(B ∧ C)). Note that the statement “the gamesof football and hockey do not both take place” is the negation of thestatement “the games of football and hockey both take place”. The givenstatement may also be translated in other ways. The statement may beexpressed in the form “the game of football takes place but not the gameof hockey, or the game hockey takes place but not the game of football”.this statement translates to (B∧¬C)∨(C∧¬B). The given statement mayalso be expressed in the form “precisely one and only one of the games offootball and hockey takes place”. This means that “the game of footballtakes place if and only if the game of hockey does not take place”. Thusthe statement also translates to B ⇐⇒ ¬C. Yet another translation (bysymmetry) is ¬B ⇐⇒ C. Note that all these translations have the sametruth table. This example illustrates the use of the exclusive or in English.

[4] It is not clear in this context whether the word “or” is used in the inclusiveor exclusive sense. When “or” is used in the exclusive sense, then thestatement may be expressed as “if the sun does not shine then one of thegames of football and hockey take place and the other does not”. Thistranslates to ¬A =⇒ (B ∧ ¬C) ∨ (C ∧ ¬B). As for the previous examplethere are other translations. When ‘or’ is used in the inclusive sense theanalysis is much simpler. A translation is clearly ¬A =⇒ (¬B ∨ ¬C).Another translation might be ¬A =⇒ ¬(B ∧ C). Yet another translationwhich requires more thought is (B∧C) =⇒ A. The last two are not reallydirect translations since they involve some logical reasoning.

[5] Again it is not absolutely clear what is meant by “the decision on whetherto play the game of football will depend on whether it is raining”. Presum-ably it means “the game of football will take place if and only if it is notraining”, i.e. B ⇐⇒ ¬D. [It is possible, but not very likely, that the state-ment means “the game of football will take place if and only if it is rain-ing”.] Therefore the given statement translates to ¬C =⇒ (B ⇐⇒ ¬D).

1.13 Applications to Computer Science

Computer programs in whatever language require a precise structure. Just as aproposition in logic must have an unambiguous meaning, lines in a program musthave an unambiguous meaning according to precise formal rules. A commonstructure in most computer languages is a statement of the form “if A then B”.Indeed a computer is an ideal machine for applying the rules of logic. A truestatement can be given the value “1” and a false statement the value “0”. Therules and structures of logic can be translated into an algebra, called BooleanAlgebra, with 0 and 1 as the only “numbers”. The computer is able to makeuse of this algebra to decide upon the truth value of a proposition.

8

Page 14: Logic and Discrete Mathematics

Also Formal Logic is a useful tool in the development of computer programs.For example, suppose that a computer database contains a list of certain peopleand their telephone numbers. We may require a short program to inform usof the telephone number of a particular person which we input. We may alsowant the computer to inform us if the person is not stored in the database. Toconstruct the program we must first consider the logistics of it. What is theprecise logical requirement of the program? We first input a person’s name, sayJohn Smith. The computer “reads” the name and compares it to the namesin the database. If the name is found it outputs the corresponding telephonenumber. If the name is not found it outputs an appropriate message, say “Thisperson’s telephone number is not known”. Let us construct the propositionthat the program is asserting. Let A be the statement “We input John Smith’sname”, let B be the statement “John Smith’s name is in the database”, let Cbe the statement “The output is John Smith’s telephone number” and let Dbe the statement “The output is ‘not known’”. The essential feature of theprogram is that on receiving an input the computer will give an output. Thiscan be expressed in the form “If P then Q”; i.e. P =⇒ Q. It is clear that inthis context P = A; i.e. P is the statement A. There are two alternatives forthe output. If B then C. On the other hand if ¬B then D. Thus Q must be thestatement (B =⇒ C) ∧ (¬B =⇒ D). Thus the program asserts the propositionA =⇒ ((B =⇒ C)∧(¬B =⇒ D)). This particular program is very simple and sothe above analysis may seem unnecessarily pedantic. However there are manyprograms that are much more complicated and an analysis of the type usedhere is extremely useful in developing good programming techniques. Indeedthe material in this course forms a foundation for Formal Methods in ComputerScience [See J. M. Spivey - The Z Notation (A Reference Manual) - PrenticeHall.].

1.14 Truth Tables in General

Using the truth tables for the connectives, we can construct truth tables forcompound statements. For example a truth table for the proposition P whichasserts (A =⇒ C) =⇒ ((A ∨ B) ∧ C) would tell us the truth value of thisproposition when we know the truth value of A, B and C. The truth value ofthe proposition can be determined in stages by finding the truth values of thestatements A =⇒ C, A∨B and (A∨B)∧C before finally using the truth tablefor =⇒. The whole process may be tabulated as follows:

A B C A =⇒ C A ∨B (A ∨B) ∧ C PT T T T T T TT T F F T F TT F T T T T TT F F F T F TF T T T T T TF T F T T F FF F T T F F FF F F T F F F

In the first three columns we list all the 8 possible truth values for A, B andC. We use the truth table for =⇒ and the truth values in columns 1 and 3 to

9

Page 15: Logic and Discrete Mathematics

enter in column 4 the truth values for A =⇒ C. We use the table for ∨ andthe truth values in columns 1 and 2 to enter in column 5 the truth values forA∨B. We use the table for ∧ and the truth values in columns 3 and 5 to enterin column 6 the truth values of (A ∨B) ∧ C. Finally we enter the truth valuesfor the whole proposition P in column 7 using the table for =⇒ and the truthvalues in columns 4 and 6.

Note that we can economize in the filling in of the table with truth values.For example, if A =⇒ C is false, then P is true whatever the truth value of(A ∨ B) ∧ C. In this case we do not need to enter truth values for A ∨ B and(A∨B)∧C. Similarly, if C is false, then (A∨B)∧C is necessarily false. Thusthe truth table may be constructed as follows:

A B C A =⇒ C A ∨B (A ∨B) ∧ C PT T T T T T TT T F F TT F T T T T TT F F F TF T T T T T TF T F T F FF F T T F F FF F F T F F

1.15 Exercise

Work out truth tables for:

[1] ¬(A =⇒ B) ∨ (A ∧B);

[2] (A =⇒ C) ∧ (C =⇒ C ∧B).

Attempt this for yourselves and then compare your answer with the one givenlater in section 1.19.

1.16 Logical Equivalence

In ordinary English, there may be two or more different ways of saying the samething. The same is true of the propositional logic. For example recall that insection 1.12 the statement “Either the game of football or the game of hockeybut not both will take place” had the three translations (B ∨ C) ∧ ¬(B ∧ C),(B∧¬C)∨(C∧¬B) and B ⇐⇒ ¬C. Indeed these propositions all have the sametruth values whatever the truth values of B and C. This fact can be confirmedfrom the following truth tables:

B C B ∨ C B ∧ C ¬(B ∧ C) (B ∨ C) ∧ ¬(B ∧ C)T T T T F FT F T F T TF T T F T TF F F F T F

10

Page 16: Logic and Discrete Mathematics

B C ¬C B ∧ ¬C ¬B C ∧ ¬B (B ∧ ¬C) ∨ (C ∧ ¬B)T T F F F F FT F T T F F TF T F F T T TF F T F T F F

B C ¬C B ⇐⇒ ¬CT T F FT F T TF T F TF F T F

Since these three truth tables have the same truth values in the last column,the propositions (B ∨C)∧¬(B ∧C), (B ∧¬C)∨ (C ∧¬B) and B ⇐⇒ ¬C havethe same truth value in every possible case. We express this by saying that thethree propositions are logically equivalent.

1.17 Definition

Two propositions are said to be logically equivalent if they have the same truthvalues for each possible assignment of truth values to the proposition letterswhich occur in them. If proposition A is logically equivalent to propositionB, we write A WV B. WV is not a logical connective in the sense of theother connectives, since it is to be used only when the propositions are logicallyequivalent. It’s usage is incorrect if the propositions are not logically equivalent.It is used mainly in demonstrations or ‘proofs’ that two given statements arelogically equivalent. The sentence A WV B is not a statement in PropositionalLogic.

For example the proposition letters occurring in the propositions (B ∨C) ∧¬(B∧C) and B ⇐⇒ ¬C are B and C. Since, for every assignment of truth valuesto B and C, the two propositions have the same truth value, (B∨C)∧¬(B∧C)and B ⇐⇒ ¬C are logically equivalent. In this case we are justified in writing(B ∨ C) ∧ ¬(B ∧ C) WV B ⇐⇒ ¬C. Note that in such sentences we do notneed to delimit with brackets each of the two propositions which are connectedby WV. We may assume that WV has the least order of priority amongst allthe connectives.

1.18 Example

Prove that two of the three propositions:

A =⇒ B ∨ ¬C;A ⇐⇒ (¬A =⇒ B ∨ C);¬(A ∧ C) ∨B;

are logically equivalent.

Solution. The truth tables for these propositions are:

11

Page 17: Logic and Discrete Mathematics

A B C ¬C B ∨ ¬C A =⇒ B ∨ ¬CT T T T TT T F T TT F T F F FT F F T T TF T T TF T F TF F T TF F F T

A B C ¬A B ∨ C ¬A =⇒ B ∨ C A ⇐⇒ (¬A =⇒ B ∨ C)T T T F T TT T F F T TT F T F T TT F F F T TF T T T T T FF T F T T T FF F T T T T FF F F T F F T

A B C A ∧ C ¬(A ∧ C) ¬(A ∧ C) ∨BT T T TT T F TT F T T F FT F F F T TF T T TF T F TF F T F T TF F F F T T

We conclude that the propositions A =⇒ B∨¬C and ¬(A∧C)∨B are logicallyequivalent, because their truth tables have the same arrangement of truth valuesin the last column. Note that we have omitted entries in these truth tables whichare not needed in the calculation of the truth value in the last column.

1.19 Solution to Exercise 1.15

[1] The truth table is:

A B A ∧B A =⇒ B ¬(A =⇒ B) ¬(A =⇒ B) ∨ (A ∧B)T T T TT F F F T TF T F T F FF F F T F F

[2] Note that C =⇒ C ∧ B means C =⇒ (C ∧ B). Therefore denoting theproposition (A =⇒ C) ∧ (C =⇒ C ∧B) by P we require the truth table:

12

Page 18: Logic and Discrete Mathematics

A B C A =⇒ C C ∧B C =⇒ C ∧B PT T T T T T TT T F F FT F T T F F FT F F F FF T T T T T TF T F T T TF F T T F F FF F F T T T

1.20 Definition

A tautology is a proposition which is always true whatever truth values areassigned to the proposition letters which occur in it.

1.21 Tautologies

One might regard a tautology as a proposition which is self-evidently true justby analysing its form. For example A∨¬A is a tautology; it asserts that eitherA is true or A is false and this is clearly true of any statement, by definition.Also A∧B =⇒ A is a tautology. This proposition can only be false when A∧Bis true and A is false. However A∧B cannot be true when A is false. Thus theproposition must always be true.

A more complicated tautology is the proposition A∧B =⇒ (C =⇒ A). Thetruth table for this proposition is:

A B C A ∧B C =⇒ A A ∧B =⇒ (C =⇒ A)T T T T T TT T F T T TT F T F TT F F F TF T T F TF T F F TF F T F TF F F F T

Since all the entries in the last column are T , the proposition is a tautology. Notethat, when A∧B is false, the proposition A∧B =⇒ (C =⇒ A) is automaticallytrue whatever the truth value of C =⇒ A, which therefore need not be enteredinto the table.

1.22 Definition

A contradiction is a proposition which is always false, regardless of the truthvalues assigned to the proposition letters which occur in it.

1.23 Contradictions

From the truth table for the connective ∧ we obtain the truth table for A∧¬A:

13

Page 19: Logic and Discrete Mathematics

A ¬A A ∧ ¬AT F FF T F

Hence, by definition, A ∧ ¬A is a contradiction. Note that this proposition is acontradiction regardless of what A stands for.

To decide whether a given proposition is a contradiction it suffices to buildits truth table. If the last column consists entirely of the truth value F , thenthe proposition must be a contradiction. For example the truth table for B ∧¬(A =⇒ B) is:

A B A =⇒ B ¬(A =⇒ B) B ∧ ¬(A =⇒ B)T T T F FT F FF T T F FF F F

Therefore, since the truth value in the final column of this table is always F ,the proposition B ∧ ¬(A =⇒ B) is a contradiction.

1.24 Definition

A proposition is said to be a contingent proposition if it is neither a tautologynor a contradiction. Such a proposition is contingent on the truth values of thepropositional letters which occur in it.

1.25 The Propositions True and False

The word True, when printed in italics, denotes the fixed, but unspecified,proposition which is always true. If you are unhappy with this definition, youmight fix some specified tautology, say A∨¬A, or some true statement, say “0 =0” and denote it by True. Similarly let False denote a fixed, but unspecified,proposition which is always false.

1.26 Logical Laws

There are a number of important rules, known as logical laws, which list certainpairs of propositions that are logically equivalent. To be precise, the followingrules hold for any choice of statements A, B and C:

Commutative Laws

(I) A ∧B WV B ∧A.

(II) A ∨B WV B ∨A.

(III) A ⇐⇒ B WV B ⇐⇒ A.

Associative Laws

(IV) (A ∧B) ∧ C WV A ∧ (B ∧ C).

14

Page 20: Logic and Discrete Mathematics

(V) (A ∨B) ∨ C WV A ∨ (B ∨ C).

Distributive Laws

(VI) A ∧ (B ∨ C) WV (A ∧B) ∨ (A ∧ C).

(VII) A ∨ (B ∧ C) WV (A ∨B) ∧ (A ∨ C).

De Morgan’s Laws

(VIII) ¬(A ∧B) WV ¬A ∨ ¬B.

(IX) ¬(A ∨B) WV ¬A ∧ ¬B.

Law of Negation

(X) ¬¬A WV A.

Law of Implication

(XI) A =⇒ B WV ¬A ∨B.

Contrapositive Law

(XII) A =⇒ B WV ¬B =⇒ ¬A.

Law of Excluded Middle

(XIII) A ∨ ¬A WV True.

Law of Contradiction

(XIV) A ∧ ¬A WV False.

Law of Equivalence

(XV) A ⇐⇒ B WV (A =⇒ B) ∧ (B =⇒ A).

Laws of Idempotence

(XVI) A ∧A WV A.

(XVII) A ∨A WV A.

Laws of Simplification

(XVIII) A ∧ True WV A.

(XIX) A ∧ False WV False.

(XX) A ∨ True WV True.

(XXI) A ∨ False WV A.

(XXII) A ∧ (A ∨B) WV A.

(XXIII) A ∨ (A ∧B) WV A.

15

Page 21: Logic and Discrete Mathematics

Most of these laws are self evident. Some may require a little more thought.For instance, A ∧ (B ∨ C) asserts that A and at least one of B and C aretrue. This means that A, B constitute a pair of true statements and/or A, Cconstitute a pair of true statements. In other words A∧B is true and/or A∧Cis true; i.e. (A∧B)∨ (A∧C) is true. Thus A∧ (B∨C) and A∧B)∨ (A∧C) aretwo different ways of saying the same thing and hence are logically equivalent.Of course one can construct truth tables to justify these laws. It is a goodlearning exercise to carefully verify each of the above logical laws using one orboth of the methods just considered.

Rather than using truth tables to demonstrate the logical equivalence of twopropositions, we may apply the logical laws directly. The use of the laws mayalso be much more economical. For example, applying rule (IX) with A takento be P =⇒ Q and B to be R∧S, ¬((P =⇒ Q)∨ (R∧S)) is logically equivalentto ¬(P =⇒ Q) ∧ ¬(R ∧ S). Thus we may write:

¬((P =⇒ Q) ∨ (R ∧ S)) WV ¬(P =⇒ Q) ∧ ¬(R ∧ S) (De Morgan)

Note that the label ‘De Morgan’ means that one of De Morgan’s laws, namelylaw (IX), has been applied. Similarly we may write:

¬((P =⇒ Q) ∧ (R =⇒ S)) WV ¬((P =⇒ Q) ∧ (¬R ∨ S)) (implication)

Here the label ‘implication’ signifies that the Law of Implication, rule (XI), hasbeen applied. We often verify that two propositions are logically equivalent by asuccession of steps like the above, applying one of the logical laws at each step.The following worked examples illustrate the general technique.

1.27 Worked Example

Use logical laws to show that A =⇒ B ∨ ¬C and ¬(A ∧ C) ∨ B are logicallyequivalent.

Solution.

A =⇒ B ∨ ¬C WV ¬A ∨ (B ∨ ¬C) (implication)WV ¬A ∨ (¬C ∨B) (commutativity)WV (¬A ∨ ¬C) ∨B (associativity)WV ¬(A ∧ C) ∨B (De Morgan)

Remark. Since the law of implication is the main logical law which expressesthe connective =⇒ in terms of the other connectives, it seems natural to use itto transform A =⇒ B∨¬C into something a bit more like ¬(A∧C)∨B. Indeedwe obtain A =⇒ B∨¬C WV ¬A∨(B∨¬C). Similarly it is clear that, using oneof De Morgan’s laws, ¬(A∧C)∨B can be expressed in terms of the statements¬A, B and ¬C. The remaining steps in the argument are a trivial consequenceof this observation. This method of working on both propositions (not justone of them) to formulate a succession of steps which link them together, is avery important technique for this type of problem. The context in which thelabels ‘associativity’ and ‘commutativity’ are used should clarify which of theAssociative or Commutative Laws are being applied.

16

Page 22: Logic and Discrete Mathematics

1.28 Worked Example

Use logical laws to show that A =⇒ (B =⇒ C) is logically equivalent to (A =⇒B) =⇒ (A =⇒ C).

Solution. This is perhaps somewhat harder than the previous example. How-ever the first step is again to remove the connective =⇒ from both statementsand then to formulate a strategy to link the resulting statements. The follow-ing argument is just one way to proceed (Note that there may be alternativearguments):

(A =⇒ B) =⇒ (A =⇒ C) WV ¬(A =⇒ B) ∨ (A =⇒ C) (implication)WV ¬(¬A ∨B) ∨ (¬A ∨ C) (implication)WV (¬(¬A ∨B) ∨ ¬A) ∨ C (associativity)WV ((¬¬A ∧ ¬B) ∨ ¬A) ∨ C (De Morgan)WV (¬A ∨ (¬¬A ∧ ¬B)) ∨ C (commutativity)WV ((¬A ∨ ¬¬A) ∧ (¬A ∨ ¬B)) ∨ C

(distributivity)

WV (True ∧ (¬A ∨ ¬B)) ∨ C (excluded middle)WV ((¬A ∨ ¬B) ∧ True) ∨ C (commutativity)WV (¬A ∨ ¬B) ∨ C (simplification)WV ¬A ∨ (¬B ∨ C) (associativity)WV ¬A ∨ (B =⇒ C) (implication)WV A =⇒ (B =⇒ C) (implication)

Remark. Sometimes it is a little easier to change the order of the two propo-sitions. In this case the argument starts with the statement (A =⇒ B) =⇒(A =⇒ C), since this statement appears more complicated than the other state-ment. The labels in brackets after each step indicates the type of law used tojustify the step, and hence we call these labels justifications. Note that we mustapply the logical laws as stated and not make up our own laws or extensions togiven laws. For instance in the above argument we cannot apply the appropriateLaw of Simplification (rule (XVIII)) to the statement (True ∧ (¬A ∨ ¬B)) ∨ Cdirectly, without first using commutativity to put the statement True in theright position. Otherwise we must add to the logical laws the additional casesneeded. The consequent increase in the number of such laws is both large andunnecessary. A more interesting idea is to decide on as few laws as is necessaryto demonstrate all logical equivalences.

17

Page 23: Logic and Discrete Mathematics

1.29 Worked Example

Fill in the justifications for each step in the following argument:

(A =⇒ C) ∧ (B =⇒ C) WV (¬A ∨ C) ∧ (¬B ∨ C)WV (C ∨ ¬A) ∧ (C ∨ ¬B)WV C ∨ (¬A ∧ ¬B)WV C ∨ ¬(A ∨B)WV ¬(A ∨B) ∨ C

WV (A ∨B) =⇒ C

WV (A ∨B) =⇒ ¬¬C

Solution.

(A =⇒ C) ∧ (B =⇒ C) WV (¬A ∨ C) ∧ (¬B ∨ C) (implication)WV (C ∨ ¬A) ∧ (C ∨ ¬B) (commutativity)WV C ∨ (¬A ∧ ¬B) (distributivity)WV C ∨ ¬(A ∨B) (De Morgan)WV ¬(A ∨B) ∨ C (commutativity)WV (A ∨B) =⇒ C (implication)WV (A ∨B) =⇒ ¬¬C (negation)

1.30 Inference

Often one or more statements will enable us, using the rules of logic, to deduceor infer another statement. This process of logical deduction will be calledinference. Suppose, for example, that I am sitting in a room with my friendGeorge, who has a degree in Meteorology. With authority he confidently asserts:

(a) “If it is raining and the sun is shining, then there is a rainbow in the sky”.

At this precise moment, Joe enters the door, dripping wet, and says:

(b) “It is raining”.

At exactly the same moment, Charlie, who has been looking out of a window,enters the room and says:

(c) “The sun is shining”.

From these three statements, I can confidently deduce the statement:

(d) “There is a rainbow in the sky”.

In other words, if the propositions (a), (b) and (c) are all true, then the propo-sition (d) must be true.

Of course, this does not mean that the propositions (a), (b) and (c) arenecessarily true. George’s meteorology may really be quite weak, and he mayhave overlooked circumstances in which the sun and rain combined could failto produce a rainbow. Perhaps Joe and/or Charlie is lying or mistaken. But,

18

Page 24: Logic and Discrete Mathematics

if George, Joe and Charlie are telling the truth, then it may be deduced thatthe proposition (d) is true. In other words, if we assume the propositions (a),(b) and (c), then proposition (d) follows logically from them. We say that theproposition (d) can be inferred from the propositions (a),(b) and (c). We callthe propositions (a), (b) and (c) the premises and (d) the conclusion of theargument.

Suppose that R denotes the proposition “It is raining”, S denotes “The sunis shining” and Q denotes “There is a rainbow in the sky”. Then the proposition(a) may be represented by R∧S =⇒ Q, (b) by R, (c) by S and (d) by Q. So theargument may be expressed in the form: Q can be inferred from R ∧ S =⇒ Q,R and S. Symbolically we express this as follows:

R ∧ S =⇒ QRS

∴ Q

We shall say that this is a valid argument. If the conclusion cannot be inferredfrom the premises, then the argument is invalid. For example the followingargument is invalid:

“If Jane oversleeps, she will miss the lecture. If Jane misses thelecture, she will fail the examination. Therefore Jane will fail theexamination.”

A little thought should convince you that this is not a valid argument. Symbol-ically it may be represented by:

O =⇒ MM =⇒ E

∴ E

where O stands for “Jane oversleeps”, M stands for “Jane misses the lecture”and E stands for “Jane fails the examination”. We can demonstrate that thisargument is invalid from the truth table:

O M E O =⇒ M M =⇒ E

T T T T TT T F T FT F T F TT F F F T

F T T T TF T F T F

F F T T T

F F F T T

Rows 1, 5, 7, 8 cover all possible cases for the truth values of O, M and E inwhich the premises O =⇒ M and M =⇒ E are true. However the last row inthe table shows that the premises can both be true when the conclusion E isfalse. That is the premises are true when Jane does not oversleep, attends thelecture and passes the examination. This is clearly evident in this example by asimple and direct observation of the given propositions, but in general the useof a truth table is a good method to fully analyse an argument.

19

Page 25: Logic and Discrete Mathematics

Let us use the method to test the argument:

A ∨BA =⇒ C

C =⇒ ¬A∴ (B ∨ C) ∧ ¬A

In this example it is not easy by just looking at the statements to decide whetherthe argument is valid. The use of a truth table will make the problem muchsimpler:

A B C A ∨B A =⇒ C ¬A C =⇒ ¬A B ∨ C (B ∨ C) ∧ ¬AT T T T T F FT T F T F F TT F T T T F FT F F T F F T

F T T T T T T T T

F T F T T T T T TF F T F T T TF F F F T T T

Note that we first work out the truth values of the premises. Only for thosecases in which these truth values are T do we determine the truth value of theconclusion. As the boxed entries indicate these cases only occur in the rows 5and 6. For these cases the truth value of the conclusion is seen to be T . Itfollows that the conclusion is always true when the premises are true. Thismeans that the argument is valid. Thus (B ∨C)∧¬A can be inferred from thepropositions A ∨B, A =⇒ C and C =⇒ ¬A.

Now consider the argument:

A ⇐⇒ B¬A ∨ ¬C¬B ∨ ¬C

∴ A =⇒ B ∧ C

The validity of the argument can be decided from the truth table:

A B C A ⇔ B ¬A ¬C ¬A ∨ ¬C ¬B ¬B ∨ ¬C B ∧ C A ⇒ B ∧ CT T T T F F F F F

T T F T F T T F T F FT F T F F F F T TT F F F F T T T TF T T F T F T F FF T F F T T T F T

F F T T T F T T T F T

F F F T T T T T T F T

From the table we see that the three premises are all true in the cases givenin rows 2, 7 and 8. However the conclusion of the argument is false in one ofthese cases, namely that given in row 2. Hence A =⇒ B ∧ C can be false evenwhen A ⇐⇒ B, ¬A ∨ ¬C and ¬B ∨ ¬C are all true. Therefore the propositionA =⇒ B ∧ C cannot be inferred from the propositions A ⇐⇒ B, ¬A ∨ ¬C and¬B ∨ ¬C. In other words the argument is invalid.

20

Page 26: Logic and Discrete Mathematics

There are other ways to demonstrate that the argument is invalid. We need acase in which the premises are true, but the conclusion is false. For A =⇒ B∧Cto be false, we require A to be true but B ∧ C to be false. B ∧ C is false whenat least one of B and C is false. Since A is true, ¬A is false. Hence for ¬A∨¬Cto be true, we require ¬C to be true, i.e. C to be false. In this case ¬B ∨¬C istrue. Now, since A ⇐⇒ B is true and A is true, B must also be true. Thus, inthe case that A and B are true and C is false, the premises are all true, but theconclusion is false. This case demonstrates that the argument is invalid. Notethat we could have stopped the process of constructing the truth table once row2 had been completed, since this row by itself would have shown immediatelythat the argument is invalid.

1.31 Worked Example

An economist says:

“If the money supply increases, then prices will rise. Increased priceswill cause increased unemployment. On the other hand, if inflationis curbed, then unemployment will be kept in check. Therefore,restricting the money supply will keep unemployment down.”

Is this argument valid?

Solution. We must first clarify what the argument means. The statementsthat occur before the word “Therefore”, are the premises and the propositionfollowing “Therefore” is the conclusion. We are not asked to decide whetherthe premises are true, but whether they infer the conclusion. We first needto express the premises symbolically. Let us denote by M the statement “themoney supply rises”, by P the statement “prices rise” and by U the statement“unemployment rises”. Since “inflation is curbed” means “prices do not rise”, itis represented by ¬P . Since “unemployment is kept in check” or “unemploymentis kept down” means “unemployment does not rise”, it is represented by ¬U .Therefore in symbols the economists argument is:

M =⇒ PP =⇒ U¬P =⇒ ¬U

∴ ¬M =⇒ ¬U

Suppose the premises are all true. Can the conclusion be false? If so, then ¬Mmust be true and ¬U false. Thus M must be false and U true. Then M =⇒ Pand P =⇒ U are true as stated. Since ¬P =⇒ ¬U is true and ¬U is false, itfollows that ¬P cannot be true. Therefore ¬P is false and P is true. Hence inthe case that both P and U are true and M false the premises are all true, butthe conclusion is false. Therefore the argument is invalid.

The economist may or may not understand economics, but he/she certainlydoes not understand logic! As an exercise demonstrate that the argument isinvalid by constructing a truth table.

21

Page 27: Logic and Discrete Mathematics

1.32 Worked Example

Translate the following argument into propositional logic, and determine whetherit is valid:

“If the money supply increases, then prices will rise. Increased priceswill cause increased unemployment. On the other hand, if inflationis curbed, then unemployment will be kept in check. Therefore, ifunemployment is kept down, then the money supply must have beenrestricted.”

Solution. The premises are, of course, identical to those in the previous example.Only the conclusion changes. Using the same notation, the conclusion may berepresented by ¬U =⇒ ¬M . Thus the argument maybe expressed symbolicallyin the form:

M =⇒ PP =⇒ U¬P =⇒ ¬U

∴ ¬U =⇒ ¬M

To test the validity of this argument, we compile the following truth table:

M P U M ⇒ P P ⇒ U ¬P ¬U ¬P ⇒ ¬U ¬M ¬U ⇒ ¬M

T T T T T F F T F TT T F T F F T TT F T F T T F FT F F F T T T T

F T T T T F F T T TF T F T F F T TF F T T T T F F

F F F T T T T T T T

From the boxed entries, we see that rows 1, 5 and 8 represent the cases whereall the premises are true. In each of these cases, the conclusion is also true, asseen from the last column. Therefore the argument is valid.

1.33 The Method of Formal Proof

To demonstrate that two propositions are logically equivalent we had a choiceof two methods, viz:

(i) using truth tables.

(ii) applying the logical laws to obtain a sequence of propositions starting withone of the given propositions and ending with the other; each propositionin the sequence being logically equivalent to the preceding proposition onthe application of a single law.

We have a similar choice of methods to show that an argument is valid. Wehave already used truth tables to do this. In the next few sections we developa method using the logical laws and additional rules of “inference”, called aformal proof.

22

Page 28: Logic and Discrete Mathematics

1.34 Inference Rules

The following rules hold for any choice of propositions A, B and C:

(XXIV) (∧E or “Simplification”) From A ∧B we can infer A.

(XXV) (∨E or “Disjunctive Syllogism”) From A∨B and ¬A we can infer B.

(XXVI) (“Modus Ponens”) From A and A =⇒ B we can infer B.

(XXVII) (“Modus Tollens”) From A =⇒ B and ¬B we can infer ¬A.

(XXVIII) (¬E or “Contradiction”) From A and ¬A we can infer B.

(XXIX) (∧I or “Conjunction”) From A and B we can infer A ∧B.

(XXX) (∨I or “Addition”) From A we can infer A ∨B.

(XXXI) (⇐⇒ I or “Transitivity of Equivalence”) From A ⇐⇒ B and B ⇐⇒ Cwe can infer A ⇐⇒ C.

(XXXII) (⇐⇒ E or “Law of Equivalence”)

(i) From A ⇐⇒ B we can infer A =⇒ B.

(ii) From A ⇐⇒ B we can infer B =⇒ A.

(XXXIII) (“The Deduction Theorem”) If B can be inferred from propositionsA1, A2, . . . , An and the proposition A, then A =⇒ B can be inferredfrom propositions A1, A2, . . . , An.

(XXXIV) (“Reductio ad Absurdum”) If the proposition False can be inferredfrom propositions A1, A2, . . . , An and the proposition ¬B, then B canbe inferred from the propositions A1, A2, . . . , An.

These rules except for the last two may be expressed by saying that certainarguments are valid. We list these as follows:

(XXIV) A ∧B∴ A

(XXV) A ∨B¬A∴ B

(XXVI) AA =⇒ B

∴ B

(XXVII) A =⇒ B¬B

∴ ¬A

(XXVIII) A¬A∴ B

23

Page 29: Logic and Discrete Mathematics

(XXIX) AB

∴ A ∧B

(XXX) A∴ A ∨B

(XXXI) A ⇐⇒ BB ⇐⇒ C

∴ A ⇐⇒ C

(XXXII) (i) A ⇐⇒ B∴ A =⇒ B

(ii) A ⇐⇒ B∴ B =⇒ A

These rules may be demonstrated as usual from truth tables. The DeductionTheorem and the rule of Reductio ad Absurdum are different. We use a truthtable in a different way. For example, the Deduction Theorem asserts that ina truth table with atomic statements A1, A2, . . . , An and A whenever the tableis constructed with truth values so that when A1, A2, . . . , An and A have valueT then B has also value T then for cases when A1, A2, . . . , An have value TA =⇒ B has also value T :

A1 A2 . . . An A B A =⇒ BT T . . . T T T TT T . . . T F T...

......

......

...

We have listed the only two rows of importance to the theorem. Note that inrow 2 the truth value of B is not needed, since A =⇒ B is necessarily truewhenever A is false.

To explain Reductio ad Absurdum we recall that the proposition False isalways false. Therefore if the argument:

A1

A2

...An

¬B∴ False

is valid, i.e. the conclusion has truth value T whenever the premises have valueT , it follows that the premises cannot all have value T . In particular ¬B must befalse, i.e. B is true, whenever A1, A2, . . . , An are true. Thus B can be inferredfrom A1, A2, . . . , An. Another way of interpreting this is say that the validity ofthe above argument means that the truth of A1, A2, . . . , An and ¬B would leadus to conclude that the proposition False is true, which is absurd. This is whythe rule is known by the (Latin) name meaning “reduction to the absurd”.

In the names for the rules the letter E stands for “elimination” and theletter I stands for “introduction”. For example the rule named ∧E involves theelimination of ∧ and the rule named ∨I involves introducing the connective ∨.

24

Page 30: Logic and Discrete Mathematics

1.35 Formal Proofs

In this section we consider the construction of a formal proof of an argument.Suppose that we wish to prove that the following argument is valid:

AA ∨B =⇒ C ∨D

¬C∴ D ∨G

The first few steps of the proof involves just listing the premises:

(1) A

(2) A ∨B =⇒ C ∨D

(3) ¬C

From these assumptions we must deduce the conclusion that D ∨ G is true.Because G has not been introduced in the premises, it appears that we mustobtain the truth of D and then apply ∨I. To obtain D we could perhapsfirst deduce C ∨D. We may work backwards in this way to find a connectionbetween the conclusion and the premises. In a forward direction observe thatthe proposition:

(4) A ∨B

can be inferred from A using the inference rule ∨I. Next, from A ∨ B and thepremise A ∨B =⇒ C ∨D we may deduce that:

(5) C ∨D

is true (rule “Modus Ponens”). By rule ∨E it follows that:

(6) D

is true. Then by ∨I:

(7) D ∨G

is true. Such a sequence of reasoning can be set down in the compact form:

(1) A

(2) A ∨B =⇒ C ∨D

(3) ¬C

(4) A ∨B

(5) C ∨D

(6) D

(7) D ∨G

However it may not be clear how we arrived at each step in this proof. It istherefore useful to add the justification for each step in the proof; thus:

25

Page 31: Logic and Discrete Mathematics

(1) A (premise)(2) A ∨B =⇒ C ∨D (premise)(3) ¬C (premise)(4) A ∨B (1, ∨I)(5) C ∨D (2,4, modus ponens)(6) D (3,5, ∨E)(7) D ∨G (6, ∨I)

Within a proof we may add steps which replace a given proposition with alogically equivalent one using one of the logical laws. Consider for example theargument:

A =⇒ BC =⇒ BA ∨ C∴ B

The proof that the argument is valid may proceed as follows:

(1) A =⇒ B (premise)(2) C =⇒ C (premise)(3) A ∨ C (premise)(4) ¬A ∨B (1, implication)(5) B ∨ ¬A (4, commutativity)(6) ¬C ∨B (2, implication)(7) B ∨ ¬C (6, commutativity)(8) (B ∨ ¬A) ∧ (B ∨ ¬C) (5,7, ∧I)(9) B ∨ (¬A ∧ ¬C) (8, distributivity)(10) B ∨ ¬(A ∨ C) (9, De Morgan)(11) ¬(A ∨ C) ∨B (10, commutativity)(12) (A ∨ C) =⇒ B (11, implication)(13) B (3,12, modus ponens)

In this proof the steps (1),(2),(3) just list the premises, steps (8) and (12) involverules of inference and the remaining steps apply logical laws.

1.36 Worked Example

Add the justifications to the following formal proof that the argument:

A ∨B =⇒ CA ∨D¬C∴ D

is valid:

(1) A ∨B =⇒ C

(2) A ∨D

(3) ¬C

(4) ¬(A ∨B)

26

Page 32: Logic and Discrete Mathematics

(5) ¬A ∧ ¬B

(6) ¬A

(7) D

Solution.

(1) A ∨B =⇒ C (premise)(2) A ∨D (premise)(3) ¬C (premise)(4) ¬(A ∨B) (1,3, modus tollens)(5) ¬A ∧ ¬B (4, De Morgan)(6) ¬A (5, ∧E)(7) D (2,6, ∨E)

1.37 Worked Example

Give a formal proof that the argument:

B ∨A =⇒ CD ∨A¬C∴ D

is valid.Remark. Using a truth table is NOT a way of giving a formal proof. A formalproof is method based only on the logical laws and the rules of inference. Notethat the solution to the previous example does not provide a solution to thepresent example even if we change the order of the letters. We cannot infer ¬Afrom ¬B∧¬A by means of ∧E. Before we can use ∧E we must change the orderof the letters so that we can apply ∧E to ¬A∧¬B to deduce ¬A. Similarly wemust change D ∨ A to A ∨D before applying ∨E to obtain D. Thus we makethe following modification to the previous solution:Solution.

(1) B ∨A =⇒ C (premise)(2) D ∨A (premise)(3) ¬C (premise)(4) ¬(B ∨A) (1,3, modus tollens)(5) ¬B ∧ ¬A (4, De Morgan)(6) ¬A ∧ ¬B (5, commutativity)(7) ¬A (6, ∧E)(8) A ∨D (2, commutativity)(9) D (7,8, ∨E)

1.38 Worked Example

Give a formal proof that the argument:

(A =⇒ B) ∧ (C =⇒ D)A ∧ C

∴ B ∧D

27

Page 33: Logic and Discrete Mathematics

Remark. By applying ∧E to (A =⇒ B) ∧ (C =⇒ D) and to A ∧ C we caninfer A =⇒ B and A. Hence by modus ponens we can infer B. However wecannot use the same method directly to infer D. Again we first have to applycommutativity to the premises before applying this method.

Solution.

(1) (A =⇒ B) ∧ (C =⇒ D) (premise)(2) A ∧ C (premise)(3) A =⇒ B (1, ∧E)(4) A (2, ∧E)(5) B (3,4, modus ponens)(6) (C =⇒ D) ∧ (A =⇒ B) (1, commutativity)(7) C =⇒ D (6, ∧E)(8) C ∧A (2, commutativity)(9) C (8, ∧E)(10) D (7,9, modus ponens)(11) B ∧D (5,10, ∧I)

1.39 Worked Example

Give a formal proof that the argument:

A ⇐⇒ B¬B

∴ ¬A

Solution.

(1) A ⇐⇒ B (premise)(2) ¬B (premise)(3) A =⇒ B (1, ⇐⇒ E)(4) ¬A (2,3, modus tollens)

Remark. To tackle this problem we obviously need a rule or law which involves⇐⇒. Clearly the rule of inference ⇐⇒ E is the most appropriate here. Notethat the logical Law of Equivalence may be applied, but its usage is merely togive a formal proof of ⇐⇒ E:

(1) A ⇐⇒ B (premise)(2) (A =⇒ B) ∧ (B =⇒ A) (1, equivalence)(3) A =⇒ B (2, ∧E)

1.40 Worked Example

Give a formal proof that the argument:

P =⇒ QQ =⇒ RR =⇒ S

∴ P =⇒ S

is valid.

28

Page 34: Logic and Discrete Mathematics

Remark. This is an example in which we make use of the Deduction Theorem.To deduce P =⇒ Q we must show that the given premises together with thepremise P infer the proposition S. Then by the Deduction Theorem it followsthat the given premises infer P =⇒ S as required. In other words, if theargument:

P =⇒ QQ =⇒ RR =⇒ S

P∴ S

is valid, then the given argument is valid.

Solution.

(1) P =⇒ Q (premise)(2) Q =⇒ R (premise)(3) R =⇒ S (premise)(4) P (premise)(5) Q (1,4, modus ponens)(6) R (2,5, modus ponens)(7) S (3,6, modus ponens)(8) P =⇒ S (Deduction Theorem)

The Deduction Theorem need not be applied at the end of an argument. Anycontinuing argument CANNOT use any of the intermediate propositions used inthe application of the Deduction Theorem. For instance, if the above argumentwere to continue after line (8), we can no longer use any of the propositionsin lines (4)-(7), since these were used only in the application of the DeductionTheorem. We indicate that these lines form a separate transient argument byputting them between horizontal lines. We must emphasize that no part ofthis argument may be used in the main argument. Note that any such transientargument may use any proposition or premise that occurs before that argument.

1.41 Worked Example

Give a formal proof that the argument:

¬P =⇒ R¬Q =⇒ ¬R

∴ P ∨Q

Remark. This is an example which uses Reductio ad Absurdum. To show thatthe given premises infer P ∨ Q, we may show that the premise together withthe proposition ¬(P ∨Q) infer the proposition False and then apply Reductioad Absurdum. In other words if the argument:

¬P =⇒ R¬Q =⇒ ¬R¬(P ∨Q)∴ False

29

Page 35: Logic and Discrete Mathematics

is valid then the given argument is also valid. The format is as in the previousexample; we use a transient argument to apply Reductio ad Absurdum.

Solution.

(1) ¬P =⇒ R (premise)(2) ¬Q =⇒ ¬R (premise)(3) ¬(P ∨Q) (premise)(4) ¬P ∧ ¬Q (3, De Morgan)(5) ¬P (4, ∧E)(6) R (1,5, modus ponens)(7) ¬Q ∧ ¬P (4, commutativity)(8) ¬Q (7, ∧E)(9) ¬R (2,8, modus ponens)(10) False (6,9, ¬E)(11) P ∨Q (Reductio ad Absurdum)

Note that in line (10) the proposition False is inferred from propositions R and¬R by rule ¬E. Indeed by this rule any proposition whatever may be inferredfrom R and ¬R. To apply Reductio ad Absurdum we need to introduce Falseinto the argument. There are but a few ways to do this. One way is to use therule ¬E as in the above argument. Using this rule we must infer a statementand its negation (for instance in the above argument R and ¬R). Another wayis to use the Law of Contradiction. To use this law we need a proposition of theform A∧¬A. For instance in the above argument lines (6) and (9) infer R∧¬Rusing ∧I. However this makes the proof a little longer. This approach wouldbe more appropriate if it were simpler to infer R ∧ ¬R directly rather than toinfer R and ¬R separately.

30

Page 36: Logic and Discrete Mathematics

Chapter 2

PREDICATE LOGIC

2.1 Introduction

In Propositional Logic we translate English sentences into symbolic propositionslike A ∨ B =⇒ ¬C, written in a precise mathematical language which avoidsthe ambiguities of ordinary English. In “Predicate Logic” we carry the pro-cess further. We attempt to extend the mathematical language so that muchmore of the structure of English sentences may be considered. For example inPropositional Logic the sentence:

“If all dogs are mammals and Rover is a dog, then Rover is a mam-mal.”

may be translated into the symbolic form A∧B =⇒ C, where A stands for “alldogs are mammals”, B stands for “Rover is a dog” and C stands for “Rover isa mammal”. This proposition does not appear self evidently true, although theoriginal English sentence does appear to have this feature. The problem lies inthe translation. Some of the logical essence of the sentence has been lost in thetranslation. We will now look at ways to solve this problem.

2.2 Predicates

Many English sentences state facts about some object, animate or inanimate. Forexample the sentence “Rover is a dog” states a fact about the object “Rover”.The name “Rover” is used here for a particular (unique) dog. Most other dogsalso have names such as Pluto or Fido. There is a common feature to thesentences “Rover is a dog”, “Pluto is a dog” and “Fido is a dog”. The propertyof being a dog is common to a very large class of objects. We may express theseideas symbolically. Thus, if r stands for Rover, p for Pluto and f for Fido wemay write D(r), D(p) and D(f) for the sentences “Rover is a dog”, “Pluto isdog” and “Fido is a dog”. D stands for the property of being a dog; i.e. is thetranslation for “is a dog”. More generally, if P stands for some property, thenP (x) represents the assertion “the object x has the property P”. Obviously suchan assertion may be expressed in a more natural way in English. For examplethe English for D(r) is better expressed as “Rover is a dog” than as “Rover hasthe property of being a dog”. However the meaning is the same.

31

Page 37: Logic and Discrete Mathematics

A unary predicate is a symbol or expression which represents a fact aboutor property of some unspecified object. We apply a unary predicate to anobject to obtain a statement. Thus applying the predicate D to the object r weobtain the statement “Rover is a dog”. Similarly, if M denotes the predicate“is a mammal”, then M(r) is the statement “Rover is a mammal”. When apredicate is applied to an object we say the it governs that object. Thus inthe proposition M(p) the predicate M governs the object p. We may apply allthe methods of Propositional Logic to propositions obtained in this way. Forexample:

¬D(r) means “Rover is not a dog”.D(r) =⇒ M(r) means “if Rover is a dog, then Rover is a mammal”.¬M(r) =⇒ ¬D(r) means “if Rover is not a mammal, then Rover isnot a dog”.D(r) ∧D(p) means “Rover and Pluto are dogs”.

Sometimes an English sentence may state a fact about two objects. Forexample, “John likes Mary” states a fact about two (unique ) objects “John”and “Mary”. Suppose that j represents John and m represents Mary. Let Lrepresent the fact that one person likes another. Thus we write L(j, m) to standfor “John likes Mary”. We call L a binary predicate. A binary predicate is aproperty of two unspecified objects. The property may or may not depend onthe order of objects. L(j, m) is different from L(m, j). However when we say“John and George are brothers”, the order of John and George is irrelevant. IfB represent “is the brother of” and g represent George, then B(j, g) stands for“John is the brother of George”. Although B(g, j) represents “George is thebrother of John”, it means the same thing as B(j, g). If P is a binary predicateand x and y are objects, then we say that P governs x, y in the expressionP (x, y).

Similarly a ternary predicate is a symbol or expression which governs threeunspecified objects. For example, suppose that G represents the fact that aperson giving an object to another person. If j stands for “John”, b standsfor a particular book, “the book”, and m stands for “Mary”, then G(j, b,m)represents the statement “John gives the book to Mary”. In this proposition thepredicate G governs the objects j, b and m. Again it is obvious that the order ofthe objects governed by this predicate is important. If the order changes then sodoes the statement. Although G(b, j,m) appears to be a reasonable statementin Predicate Logic, it does not make sense in English. We will deal with thisdifficulty later when we introduce the notion of ‘types’.

If L, G, j, b ,m have the above meanings, then L(j,m), L(m, j) and G(j, b,m)etc. are propositions of Predicate Logic to which we may apply the methods ofPropositional Logic. For example:

L(j, m)∧G(j, b, m) means “John likes Mary and gives her the book”.[This sentence is perhaps more natural than “John likes Mary andJohn gives the book to Mary”.]L(j, m)∧¬L(m, j) means “John likes Mary, but Mary does not likeJohn”. [Recall that “but” in logical terms really means “and”; itmerely draws attention to the contrast between the two statements.]

Note that a predicate can govern more than three objects. In general we call

32

Page 38: Logic and Discrete Mathematics

a predicate which governs n objects an n-ary predicate. Such predicates are notvery common.

2.3 Infix Notation for Binary Predicates

Let P be a binary predicate and let x and y denote particular objects. IfP governs x and y in a particular proposition we often write xPy instead ofP (x, y). This notation follows the more natural orderings of English. Thuswith the notation j, m,L introduced earlier jLm stands for “John likes Mary”.

2.4 The Binary Predicates <, ≤, >, ≥ and =

Each of these five symbols represent a binary predicate which govern two num-bers. To be exact, if x and y are two numbers, then:

< (x, y) means “x is less than y”.≤ (x, y) means “x is less than or equal to y”.> (x, y) means “x is greater than y”.≥ (x, y) means “x is greater than or equal to y”= (x, y) means “x is equal to y”.

It is usual, however, in mathematics to use the infix notation:

x < y means “x is less than y”.x ≤ y means “x is less than or equal to y”.x > y means “x is greater than y”.x ≥ y means “x is greater than or equal to y”x = y means “x is equal to y”.

2.5 Worked Example

Suppose that S is a unary predicate expressing the fact of having a railwaystation, i.e. S(y) means that the town y has a railway station. Suppose that Vis a binary predicate indicating that a particular person has visited a particulartown, i.e. V (x, y) or xV y means that the person x has visited the town y.Suppose that the following letters denote specified people and towns:

g denotes George l denotes Londonj denotes John r denotes Readingm denotes Mary w denotes Windsor

Translate the following English sentences into predicate logic:

[1] John has not visited Reading.

[2] George has visited Reading and London.

[3] George has visited Reading but not London.

[4] Mary has visited Reading or London or both.

[5] John must have visited Reading if it has a railway station.

33

Page 39: Logic and Discrete Mathematics

[6] Although both Reading and Windsor have railway stations, John has vis-ited neither of these towns.

Also translate the following propositions of predicate logic into English sen-tences:

[7] jV w ∧mV w.

[8] ¬S(r) ∧ ¬S(w).

Solution. [1] If we use infix notation, the proposition “John has visited Read-ing” translates into jV r, and consequently “John has not visited Reading”translates into ¬jV r.

[2] “George has visited Reading and London” means the same thing as “Georgehas visited Reading and George has visited London”. Therefore the re-quired translation into predicate logic is gV r ∧ gV l.

The answer is NOT gV (r∧l). r and l are not statements and hence cannotbe connected with ∧. r ∧ l has no meaning in Predicate Logic. This istrue of all connectives not just ∧. We CANNOT connect two objects withlogical connectives, since they only apply to (well-formed) propositions.

[3] “George has visited Reading but not London” means the same as “Georgehas visited Reading and George has not visited London”. Therefore theproposition translates into gV r ∧ ¬gV l.

[4] This proposition means the same as “Mary has visited Reading and/orMary has visited London”. Therefore it translates into mV r ∨mV l.

[5] This proposition amounts to saying “If Reading has a railway station, thenJohn has visited Reading”. Hence it translates into S(r) =⇒ jV r.

[6] This statement actually means in logical terms that Reading and Windsorhave railway stations and John has not visited either Reading or Windsor.The use of the word “although” merely acts to engender surprise at thefact that John has not visited Reading nor Windsor. Thus the propositiontranslates into S(r) ∧ S(w) ∧ ¬jV r ∧ jV w. Note that we do not need touse brackets in this statement.

[7] jV w∧mV w means “John has visited Windsor and Mary has visited Wind-sor”. This may be written more simply as “John and Mary have visitedWindsor”. Note that we CANNOT express this proposition symbolicallyas (j ∧m)V w, since the connective ∧ cannot be applied to objects.

[8] ¬S(r) ∧ ¬S(w) means “Reading has no railway station and Windsor hasno railway station”. Again this may be simplified to “Neither Reading norWindsor has a railway station”. We may also express this proposition as¬(S(r)∨ S(w)), but NOT as ¬S(r ∨w) [r ∨w is not allowed in PredicateLogic. The connective ∨ can only be applied to propositions.]

34

Page 40: Logic and Discrete Mathematics

2.6 Notation

Predicates will frequently be denoted by italicized words or combinations ofwords. Although this notation lengthens the expressions used in predicate logic,it is perhaps more informative. Thus in place of the predicate D say, whichstands for “is a dog”, we may write dog or perhaps is-a-dog. Similarly, we mayuse words or combinations of words to denote objects. In this case we will usea sans-serif font type. Thus for example Rover may be used to denote “Rover”.For example we may write is-a-dog (Rover) to mean “Rover is a dog”. Similarlywe may write John likes Mary to mean “John likes Mary”. In some cases, likethis example, the symbolic form is exactly the same as the English form apartfrom the different font types used.

2.7 Types

Suppose, for example, that H is a unary predicate expressing the fact of beinghappy. Suppose that j stands for John and m stands for Mary. Then H(j)means “John is happy” and H(m) means “Mary is happy”. In general H(x)means “x is happy”, where x is the name of any person. However, if x denotes aparticular chair, then H(x) would not make sense. Therefore when we considera unary predicate, we usually have in mind some type of object which it isallowed to govern. For instance if P is the set of all people, we might agree thatthe predicate H is only allowed to govern those objects belonging to P . ThenH(x) is only a proposition, i.e. is true or false, when x stands for an object inP . We say that P is the domain or the domain of definition of H. An object ofP is called “an object of type P”. Thus a “type” is just a collection of objects.If x is an object of type P , we write, in symbols, x : P . This is an abbreviationfor “x is of type P”, or, in this particular case, “x is a person”.

A binary predicate governs two objects. In this case, the first object mustbe of a specific type and the second object must be of some, perhaps different,specific type. For example, consider the binary predicate, V , which expressesthe fact that a person has visited a town, so that V (x, y) or xV y means thatthe person x has visited the town y. Thus V (x, y) or xV y only makes sense ifx is the name of a person and y is the name of a town. In other words, if Pdenotes the set of all people and T denotes the set of all towns, we require x tobe of type P and y to be of type T . The expression V (x, y) or xV y only makessense if x : P and y : T . On the other hand, the predicate, L, which expressesthe liking of one person for another, governs two objects of same type P . ThusL(x, y) or xLy only makes sense if x : P and y : P .

In Mathematics, there are particularly important types of objects for whichwe give a standard fixed notation. These are the following special number types:

Z denotes the set of integers (i.e. whole numbers). Thus Z consists of thenumbers:

. . . ,−3,−2,−1, 0, 1, 2, 3, . . .

N denotes the set of “natural numbers”, i.e. the non-negative integers. ThusN consists of the numbers:

0, 1, 2, 3, . . .

35

Page 41: Logic and Discrete Mathematics

N1 denotes the set of all positive integers. Thus N1 consists of the numbers:

1, 2, 3, 4, 5, . . .

Q denotes the set of all rational numbers, i.e. numbers of the form pq , where

p, q are integers with q 6= 0. Thus Q consists of “fractions” such as 12 , 3

4and 2

7 .

R denotes the set of all real numbers, i.e. numbers which have a, possi-bly infinite, decimal representation. Real numbers include both rationalnumbers and irrational numbers such as π,

√2 and e.

Remark. In some textbooks and courses N is defined to be the set of all positiveintegers, i.e. the set N1.

2.8 Quantifiers

In Mathematics, we often make statements involving the words “for all” and“there exists” or words to the same effect. For example we might write:

“for all real numbers x, x < x + 1,”

which means that for every real number x, whatever its value, x is less thanx + 1. Similarly the assertion:

“for all persons x, x likes chocolate”

means that everyone likes chocolate. We use the symbol ∀ to represent thewords “for all”. Similarly we use the symbol ∃ to represent the words “thereexists”. The statement:

“for all persons x, x likes chocolate”

may be represented in Predicate Logic in the symbolic form:

∀x : P • xLc,

where P denotes the set of all people, L denotes the predicate “likes” and cdenotes chocolate. The expression ∀x : P is called a quantifier, more preciselya universal quantifier. We use the symbol • to separate the quantifier from thepredicated statement xLc. In the same way we express the statement “for allreal numbers x, x is less than x + 1” in the symbolic form:

∀x : R • x < x + 1.

Suppose that S expresses the fact that a town has a railway station, andthat V represents the fact that a person has visited a town. Let P denote theset of people and T denote the set of towns. Then the statement “there existsa town with a railway station” may be translated to:

∃x : T • S(x).

Note that in this case the symbol • represents the words “such that” and alsoseparates the quantifier ∃x : T from the predicated statement S(x). The quan-tifier here is called an existential quantifier. Note also that there are many otherways to express this statement in English, for example:

36

Page 42: Logic and Discrete Mathematics

At least one town has a railway station;or, Some town has a railway station.

Similarly the statement “there is at least one town without a railway station”may be translated into:

∃x : T • ¬S(x).

Note that this statement may also be expressed in English in the form:

Not all towns have a railway station.

This version translates into:

¬∀x : T • S(x).

If j denotes John, then the statement “John has visited at least one town”translates into:

∃y : T • jV y.

[In loose English “there exists an object y of type ‘town’ such that John hasvisited y”.]

Suppose that we wish to translate the statement “there is a unique townthat has a railway station” Here the word “unique” has the same meaning asthe words “one and only one”. In this case we use the symbol ∃1. Thus thestatement translates into:

∃1x : T • S(x).

Similarly the proposition “John has visited one and only one town” becomes:

∃1y : T • jV y.

A quantifier involving ∃1 is called a unique quantifier.

2.9 Restricted Quantifiers

Quantifiers such as ∀x : P , ∃y : T and ∃1y : T are known as unrestricted quan-tifiers. Sometimes we wish to restrict the range of possibilities for a quantifiedvariable. Such modified quantifiers are called restricted quantifiers. For exam-ple, suppose that in the quantifier ∀x : N we wish to restrict the possibilitiesof x to those natural numbers less than 12. The modified quantifier is denotedby ∀x : N|x < 12. This quantifier literally means “for all x of type N such thatx < 12” or, in better English, “for all natural numbers x for which x < 12”.The symbol | is short hand for “for which”. The proposition:

∀x : N|x < 12 • x < 20

therefore means “for every natural number x less than 12, x is less than 20”, or“every natural number less than 12 is less than 20”. Similarly the proposition:

∀y : T |jV y • S(y)

means “for every town y which John has visited, y has a railway station”, or“every town which John has visited has a railway station”.

37

Page 43: Logic and Discrete Mathematics

Expressions such as ∀x : N|x < 12 and ∀y : T |jV y are called restricteduniversal quantifiers. In general such quantifiers have the form ∀x : X|Q, whereX denotes a type and Q is a statement about any object x of type X. IndeedQ is a predicated statement involving a predicate which at least governs objectsof type X.

We can avoid using a restricted quantifier by using the connective =⇒ in-stead. A proposition of the general form:

∀x : X|Q • P,

where P is a predicated statement with a predicate which governs at least objectsof type X, is equivalent to the proposition:

∀x : X •Q =⇒ P.

In other words, a proposition of the form “for all x of type X such that Q istrue, P is true” can be replaced by the proposition “for all x of type X, if Q,then P”. Thus, for example:

∀x : N|x < 12 • x < 20

(i.e. “every natural number less than 12 is less than 20”) can be replaced by:

∀x : N| • x < 12 =⇒ x < 20

(i.e. “for every natural number x, if x < 12, then x < 20”) and:

∀y : T |jV y • S(y)

(i.e. “every town which John has visited has a railway station”) can be replacedby:

∀x : T • jV y =⇒ S(y).

(i.e. “for every town y, if John has visited y, then y has a railway station”)We also sometimes use restricted existential quantifiers. For example:

∃x : N|x < 12,

which means “for some object x of type N such that x < 12” or “for somenatural number x less than 12” or “there exists a natural number x less than12 such that . . .”. In particular:

∃x : N|x < 12 • x > 10

means “there exists a natural number x less than 12 such that x < 10” or “thereexists a natural number less than 12 which is greater than 10”. If we use thesymbols, such as T , V j etc., defined previously, then:

∃y : T |jV y

would mean “for some town y which John has visited” and hence:

∃y : T |jV y • S(y)

38

Page 44: Logic and Discrete Mathematics

would mean “there exists a town which John has visited that has a railwaystation”. In general a restricted existential quantifier has the form ∃x : X|Q,where Q is an assertion about x.

We can avoid using a restricted existential quantifier by using the connective∧ instead. For example the statement that there exists a natural number lessthan 12 which is greater than 10 may be expressed in the form: “there exists anatural number which is less than 12 and greater then 10”; i.e.:

∃x : N • x < 12 ∧ x > 10.

Similarly the proposition:∃y : T |jV y • S(y)

may be replaced by:∃y : T • jV y ∧ S(y).

Thus restricted quantifiers may avoided, but often their use may be more con-venient and easier to interpret.

39

Page 45: Logic and Discrete Mathematics

2.10 The Scope of a Quantifier

To illustrate the ideas contained in this section we will use the previous notationssuch as T , V and j. In the proposition ∀x : T • S(x), we say that the scopeof the quantifier ∀x : T is S(x). Similarly the scope of the quantifier ∃x :T in the proposition ∃x : T • ¬S(x) is the assertion ¬S(x). Note that thescope of a quantifier is always an expression concerning the variable declared inthe quantifier. Thus the scopes of the quantifiers in the above statements areassertions about the variable x, which was declared within the quantifier.

There are situations in which the scope of the quantifier is somewhat am-biguous. Thus, for example, how should we interpret the proposition ∀x : T •S(x) =⇒ jV r? It is not clear whether this proposition means ∀x : T • (S(x) =⇒jV r) or (∀x : T • S(x)) =⇒ jV r. In predicate logic, we use the conventionthat the scope of the quantifier consists of everything which comes after the •which immediately follows the quantifier, unless brackets are used to indicateotherwise. A quantifier with its scope forms a complete sentence or assertion,which may be delimited by brackets when part of a compound proposition.Therefore in the statement ∀x : T • S(x) =⇒ jV r, the scope of the quantifier isS(x) =⇒ jV r. If the scope of the quantifier is meant to be just S(x), then weMUST use brackets:

(∀x : T • S(x)) =⇒ jV r.

The brackets are used here to delimit the statement ∀x : T • S(x) which isconnected to the statement jV r with the connective =⇒ to form the wholecompound proposition.

If a quantifier appears between brackets, then its scope is everything whichoccurs after the • which immediately follows the quantifier but is between thenearest pair of brackets which enclose the quantifier. Consider, for example, theproposition:

jV l ∨ (mV r ⇒ (gV w ⇒ ∀x : T • S(x) ∨ (jV x ∧ jV r)) ∧mV l).

In this proposition the pair of brackets nearest to the quantifier delimit thestatement:

gWr =⇒ ∀x : T • S(x) ∨ (jV x ∧ jV r).

Hence the scope of the quantifier is:

S(x) ∨ (jV x ∧ jV r).

Note that the quantifier with its scope forms the statement:

∀x : T • S(x) ∨ (jV x ∧ jV r)

and that it is unnecessary to delimit this statement in the whole propositionwith a pair of brackets, since this omission does not produce an ambiguity. Thesame rules apply to restricted quantifiers. A proposition may contain manyquantifiers, being built up using lots of atomic statements combined with con-nectives and quantifiers. The above rules allow us to determine the scope ofeach quantifier, so that 7by parsing the proposition we may obtain its correctinterpretation.

40

Page 46: Logic and Discrete Mathematics

2.11 Worked Example

Let P be the set of all people. Suppose that sensible, stupid, architect,fishmonger, thief are unary predicates indicating being sensible, being stupid,being an architect, being a fishmonger and being a thief respectively. Thus, forexample, sensible(x) means that the person x is sensible. Suppose that admiresis a binary predicate indicating that one person admires another and supposethat taller-than is a binary predicate indicating that one person is taller thananother. Using John and Sue as symbols for particular people, translate thefollowing English sentences into predicate logic:

(a) Everybody admires John.

(b) Sue admires somebody.

(c) Everyone who admires Sue is stupid.

(d) John admires at least one person who is taller than Sue.

(e) All sensible people admire John.

(f) Every architect is taller than John.

(g) Some fishmonger is shorter than John.

(h) Every fishmonger is a thief.

(i) No architect is a thief.

(j) If all fishmongers are thieves and John is a fishmonger, then John is a thief.

(k) If you are taller than John, then you must be taller than Sue.

(l) John admires everybody and is taller than Sue.

Solution. (a) This proposition may be expressed in the form: “For every personx, x admires John”. Hence its translation into predicate logic is:

∀x : P • x admires John.

(b) In this case the proposition may be expressed in the form: “There exists aperson x such that Sue admires x”. Hence the translation is:

∃x : P • Sue admires x.

(c) There are at least two ways of translating this sentence into predicate logic;either using a restricted quantifier:

∀x : P | x admires Sue • stupid(x);

or instead using an unrestricted quantifier:

∀x : P • x admires Sue =⇒ stupid(x).

41

Page 47: Logic and Discrete Mathematics

(d) In this case we may use a restricted or unrestricted existential quantifier:

∃x : P | x taller-than Sue • John admires x.

or:∃x : P • x taller-than Sue ∧ John admires x.

(e) This sentence may be written: “For every person x such that x is sensible,x admires John”. Possible translations include:

∀x : P | sensible(x) • x admires John;

and:∀x : P • sensible(x) =⇒ x admires John.

(f) We may express this sentence as “For every person x such that x is anarchitect, x is taller than John”. Thus possible translations are:

∀x : P | architect(x) • x taller-than John;

and:∀x : P • architect(x) =⇒ x taller-than John.

(g) This sentence may be expressed as “For some person x such that x is afishmonger, John is taller than x”. Hence possible translations are:

∃x : P | fishmonger(x) • John taller-than x;

and:∃x : P • fishmonger(x) ∧ John taller-than x.

(h) Possible translations are:

∀x : P | fishmonger(x) • thief(x);

and:∀x : P • fishmonger(x) =⇒ thief(x).

(i) Possible answers are:

∀x : P | architect(x) • ¬thief(x);

and:∀x : P • architect(x) =⇒ ¬thief(x).

(j) Because we should now be familiar with the use of both restricted andunrestricted quantifiers, in future we will only write down one of the twopossible cases. A solution in this example is:

(∀x : P | fishmonger(x) • thief(x)) ∧ fishmonger(John) =⇒ thief(John).

(k) A solution is:

∀x : P | x taller-than John • x taller-than Sue.

(l) A solution is:

(∀x : P • John admires x) ∧ John taller-than Sue.

Note that if we interchange the constituent statements in this propositionwe may remove the brackets. Thus an alternative solution with no bracketsis:

John taller-than Sue ∧ ∀x : P • John admires x.

42

Page 48: Logic and Discrete Mathematics

2.12 Multiple Quantifiers

The scope of a quantifier may also involve one or more quantifiers. For examplethe proposition:

∀x : N • ∃y : N • x < y.

The scope of the quantifier ∀x : N is the assertion:

∃y : N • x < y,

which involves the quantifier ∃y : N. Note that the whole proposition is true,since given any natural number x there always exists a natural number y suchthat x < y. However, if we interchange the quantifiers, we obtain the proposi-tion:

∃y : N • ∀x : N • x < y,

which is clearly false; no natural number can be greater than every natural num-ber. It follows that the order of the quantifiers in such propositions are crucialto the meaning of the proposition. However the order does not matter whenwe combine two universal quantifiers or combine two existential quantifiers. Forinstance the two propositions:

∀x : N • ∀y : N • x ≤ y ∨ x > y

and:∀y : N • ∀x : N • x ≤ y ∨ x > y

mean the same thing as do the two propositions:

∃x : N • ∃y : N • x < y ∧ y < 2

and:∃y : N • ∃x : N • x < y ∧ y < 2.

A general proposition of the form:

∀x1 : X • ∀x2 : X • . . . • ∀xn : X •Q(x1, x2, . . . , xn),

where Q(x1, x2, . . . , xn) is an assertion about the variables x1, x2, . . . , xn, maybe translated into English in the simplified form: “For all objects x1, x2, . . . , xn

of type X the assertion Q(x1, x2, . . . , xn) is true”. We may therefore use asimplified notation in predicate logic:

∀x1, x2, . . . , xn : X •Q(x1, x2, . . . , xn).

We may use a similar simplified notation for existential quantifiers:

∃x1, x2, . . . , xn : X •Q(x1, x2, . . . , xn)

instead of the expanded form:

∃x1 : X • ∃x2 : X • . . . • ∃xn : X •Q(x1, x2, . . . , xn).

There are similar abbreviations for mixed types:

∀x1 : X1;x2 : X2; . . . ;xn : Xn •Q(x1, x2, . . . , xn).

43

Page 49: Logic and Discrete Mathematics

and:∃x1 : X1;x2 : X2; . . . ;xn : Xn •Q(x1, x2, . . . , xn).

For example, if P, T, V have the meanings given in previous sections, the propo-sition:

∀x : P • ∀y : T • xV y,

meaning that every person has visited every town, may be abbreviated to:

∀x : P ; y : T • xV y.

Similarly the proposition:

∃x : N • ∃y : N • ∃z : N • x < y ∧ y < z

may be abbreviated to:

∃x, y, z : N • x < y ∧ y < z.

If W is a ternary predicate and W (x, y, n) means that a person x has visited atown y at least n times, then the proposition:

∀x : P • ∀y : T • ∀n : N •W (x, y, n)

can be shortened to:

∀x : P ; y : T ;n : N •W (x, y, n).

If we wish to write down the scope of a quantifier that occurs within amultiple quantifier in a proposition, we need to “replace” all omitted quantifiersnecessary to achieve this. For example the proposition:

∀x, y : N • x ≤ y ∨ x > y.

combines the quantifiers ∀x : N and ∀y : N. To determine the scope of thequantifier ∀x : N we need to replace both the omitted quantifiers; thus:

∀x : N • ∀y : N • x ≤ y ∨ x > y.

Then the scope of the quantifier ∀x : N is:

∀y : N • x ≤ y ∨ x > y.

The scope of the quantifier ∀y : N is x ≤ y ∨ x > y.If you were asked to replace the omitted quantifiers in the proposition:

((∀x : P ; y : T • S(y) ⇒ xV y) ⇒ (∃x, y : R • x < y ∧ y < 1)) ∧ jV r

the answer would be:

((∀x : P • ∀y : T • S(y) =⇒ xV y)=⇒ (∃x : R • ∃y : R • x < y ∧ y < 1)) ∧ jV r.

From this we can see that:

44

Page 50: Logic and Discrete Mathematics

(i) the scope of ∀x : P is:

∀y : T • S(y) =⇒ xV y;

(ii) the scope of ∀y : T is: S(y) =⇒ xV y;

(iii) the scope of ∃x : R is:

∃y : R • x < y ∧ y < 1;

(iv) the scope of ∃y : R is: x < y ∧ y < 1.

2.13 Worked Example

Let T be the set of all towns. Let V be a binary predicate indicating thata particular person has visited a particular town, i.e. V (x, y) or xV y meansthat person x has visited town y. Using this notation and the notation inExample 2.11, translate the following English sentences into predicate logic:

(a) There is a person who has visited every town.

(b) Every town has had at least one visitor.

(c) Everybody admires somebody who is taller than Sue.

(d) Somebody who is shorter than Sue admires everybody who is taller thanSue.

(e) If one person is taller than another then the latter is not taller than theformer.

(f) Somebody has visited at least one town.

Solution. (a) This sentence may be expressed as follows: “There exists a personx such that x has visited every town”. The sentence “x has visited everytown” means “for every town y, x has visited y”. This may be translatedinto predicate logic as:

∀y : T • xV y.

Hence the full sentence translates into:

∃x : P • ∀y : T • xV y.

(b) This sentence may be expressed in the form: “For every town y, y has hadat least one visitor.” The sentence “y has had at least one visitor” means“there exists a person x such that x has visited y”. This translates intopredicate logic as:

∃x : P • xV y.

Thus the full translation is:

∀y : T • ∃x : P • xV y.

(c) In this case the sentence means:

45

Page 51: Logic and Discrete Mathematics

“For every person x, x admires somebody who is taller than Sue”.

The sentence “x admires somebody who is taller than Sue” may be expressedin the form: “There exists a person y who is taller than Sue such that xadmires y”. This translates into predicate logic as:

∃y : P | y taller-than Sue • x admires y.

Therefore the whole sentence translates into:

∀x : P • ∃y : P | y taller-than Sue • x admires y.

(d) This sentence means “For some person x who is shorter than Sue, x admireseverybody who is taller than Sue”, i.e. “There exists a person x such thatSue is taller than x with the property that, for every person y such that yis taller than Sue, x admires y”. This translates into:

∃x : P | Sue taller-than x • ∀y : P | y taller-than Sue • x admires y.

(e) This sentence may be expressed in the form “If a person x is taller than aperson y, then y is not taller than x”. It does not matter which personsx and y refer to. The sentence applies to all persons x and y. Thus thesentence translates into predicate logic as:

∀x, y : P • x taller-than y =⇒ ¬y taller-than x.

Note that the word “all” or any of its equivalents does not actually appearin the sentence. However it is nevertheless implied, since the sentence doesnot refer to specific people. The sentence asserts the truth of the statement“x taller-than y =⇒ ¬y taller-than x” however we choose the people x andy; i.e for all people x and y.

(f) This sentence means: “There exists a person x and a town y such that xhas visited y”; i.e.

∃x : P ; y : T • xV y.

Of course there are other equivalent expanded forms of this statement.

2.14 Variables and Constants

We can distinguish between symbols which represent a particular object andsymbols which represent unspecified objects. Usually unspecified objects arethose which have been declared by a quantifier which just specifies its type andnot a particular object. The symbols which represent these unspecified objectsare called variables. A variable may be replaced by the label of a particularobject of the same type and any associated quantifier removed to obtain aproposition about the particular object. Symbols which represent particularobjects are called constants. For example, in the proposition:

∃x, y : N • x < y ∧ y < 2

the symbols x and y are variables and the symbol 2 is a constant, since it isthe label of just one particular number. To test the truth of this proposition

46

Page 52: Logic and Discrete Mathematics

we must replace the variables x and y by particular numbers and then test thestatement x < y ∧ y < 2 for its truth value. We must try all possible choices of‘values’ of x and y. If for just one particular choice, the statement x < y∧y < 2is true, then our proposition is true. The use of variables in predicate logic isvery similar to the use of variables in algebra. We say that a quantifier is overa variable if the quantifier declares that variable. For example the quantifiers∀x : T , ∃x : R, ∃1x : N and ∀x, y : N are all quantifiers over x. Note that∀x, y : N is also a quantifier over y.

In predicate logic, an occurrence of a variable, x, in an expression is saidto be bound, if it lies within the scope of a quantifier over x. Variables in anexpression which are not bound variables are said to be free variables. Forexample in the expression “∀x : P • xV y” the variable x is a bound variable,since it is declared by the quantifier, ∀x : P , but the variable y is a free variable,since it has not been declared in the expression by any quantifier. We say thatx is bound by the quantifier ∀x : P . Whether a given variable is bound or notdepends on the expression in which it occurs. For example, in the expression:

∃y : T • ∀x : P • xV y

the variable y is now a bound variable. As we have seen above, in the scopeof the quantifier ∃y : T (as an expression in its own right) y is a free variable.Again in the expression:

∃x : N • ∀y : N • z ≤ y ∨ y < x.

all the occurrences of the variables x and y are bound, but z is a free variable.Now consider the proposition:

((∀x : P • ∀y : T • S(y) =⇒ xV y)=⇒ (∃x : R • ∃y : R • x < y ∧ y < 1)) ∧ jV r.

All occurrences of the variables x and y are bound. However the two occurrencesof x before the connective =⇒ are bound by the quantifier ∀x : P , whilst theother occurrences of x are bound by the quantifier ∃x : R. Similarly eachoccurrence of y is bound by one of two different quantifiers; namely ∀y : Tand ∃y : R. Note that there are no free variables in this proposition and thatthere are two constants; namely j and r. Great care must be taken when asymbol is used to denote two essentially different objects in a proposition. Abound variable x has influence extending only to the scope of the quantifierover x; i.e. all occurrences of x in a quantifier over x and its scope are boundby that quantifier and all other occurrences of x are either free or bound by adifferent quantifier. If difficulties arise over the use of a symbol in more thanone ‘context’, then use should be made of other symbols, so that each objectis represented by a symbol unique to that object. Thus the above propositionperhaps may more clearly and unambiguously expressed in the form:

((∀x : P • ∀y : T • S(y) =⇒ xV y)=⇒ (∃u : R • ∃v : R • u < v ∧ v < 1)) ∧ jV r.

We know that, in the context of this proposition, the symbols j and r areconstants, since we are given this fact in advance.

47

Page 53: Logic and Discrete Mathematics

Recall that we considered an expression:

∃x : N • ∀y : N • z ≤ y ∨ y < x.

This expression cannot be a proposition, since we cannot determine whetherit is true or false. The reason is that the expression contains a free variable;namely z. On replacing z with a particular object, the expression becomes aproposition. Certain choices make the proposition true; others make it false. Itis only when we replace the free variable z with a constant that a truth valuecan be determined.

Any expression made up of symbols from the language of predicate logic iscalled a formula. A formula which has a truth value whenever each free variableis assigned a value; i.e. is replaced by a constant is said to be well formed.We will often abbreviate the words ‘well formed formula’ to ‘wff’. For examplethe expression ∀x : N is a formula, which is not a proposition nor well formed.The expression ∃y : N • x < y is a well formed formula, but not a proposition.Finally the expression ∀x : N • ∃y : N •x < y is a proposition; indeed it is a trueproposition.

In creating a well formed formula in predicate logic, we must follow theprecise rules of syntax in the language of predicate logic. The following giveexamples of errors of syntax that might occur:

(i) ∀j : P •jV y, where j stands for “John”. Here j is a constant and quantifierscan only declare variables. The expression ∀x : X only makes syntacticsense, when x is a variable and X stands for a “type”; i.e. a set of objects.

(ii) ∃x : P • x admires John | x admires Sue. The symbol | must immediatelyfollow the quantifier that it is restricting. The scope of the quantifier isx admires John | x admires Sue and this ‘assertion’ does not make syntac-tic sense.

(iii) ∃x : P • x admires John • x admires Sue. A • must immediately follow aquantifier, but the second • does not. The scope of the quantifier ∃x : P isthe expression x admires John•x admires Sue, which does not make sense,since the • in this expression does not immediately follow a quantifier.

(iv) The expression ∀x : P | xV y does not mean the same as ∀x : P • xV y.Indeed it cannot be a well formed formula, since it only denotes a restrictedquantifier without a scope.

The expression ∀x : P •xV y is a wff. The variable y in this formula is a freevariable. We may replace y by l, say, where l stands for “London”. Then theformula becomes the proposition ∀x : P • xV l. This process is called assigningthe value l to y.

The formula ∃y : N • x < y ∧ y < z contains two free variables, x and z. Weclaim that this formula is well formed. If we assign the value 3 to x and thevalue 5 to z, then the resulting formula is a true proposition. On the other handthe assignment of 5 to x and 3 to z yields a false statement. Of course thereis no explicit reason why we should restrict the assignment of values to x andy from within the set N. However there is a problem here concerning whetherthe expression x < y is a wff. This is not strictly a problem within predicatelogic itself, but more one concerning the particular application of predicate

48

Page 54: Logic and Discrete Mathematics

logic to mathematics. We apply the predicate logic to many deductive sciencesincluding mathematics and computer science. In these applications we use thelogic to deduce propositions and formulae about the subject from other knownpropositions and formulae on the subject. Hence, when deciding whether aformula is well formed, in addition to the formal structures of predicate logic wehave also to consider the formal structures of the given science. This means thatfree variables may not be completely free in the sense that we may assign anyvalue whatever to them, but that they may be freely chosen from a particularset; i.e. the type of the variable. Thus in the above formula, the types of x andz may be implicitly regarded as the set N. In this case it is absolutely clear thatthe formula, ∃y : N•x < y∧y < z, is well formed. In most applications the typeof a free variable is usually declared before the variable is used in a formula.

2.15 Worked Example

In the six well formed formulae (i)-(vi) of predicate logic listed below, all vari-ables represent objects belonging to Z (i.e. integers).

(a) For each of the formulae which contains no free variables, state whether itis true or false.

(b) For each of the formulae which contains one or more free variables, give anexample of an assignment of value(s) to the free variable(s) which make theformula true.

(c) For each of the formulae which contains one or more free variables, give anexample of an assignment of value(s) to the free variable(s) which make theformula false.

(i) ∃x : Z • x ≤ 0.

(ii) ∃x : Z • x < y ∧ x > 2.

(iii) ∀x : Z • ∃y : Z • y < x.

(iv) ∀x : Z • ¬(x = y ∧ y = z).

(v) ∃x, y : Z • t < x ∧ x < y ∧ y < z.

(vi) ∀x, y : Z • x > y.

Solution. (i) In this formula there is only one variable; namely x. There aretwo occurrences, both bound by the quantifier ∃x : Z. Hence there areno free variables. The formula is therefore a proposition. Since thereobviously exists at least one number which is less than or equal to 0, theproposition is true.

(ii) In this formula there are two different variables; namely x and y. Thereare three occurrences of x, all bound by the quantifier ∃x : Z. Howevery is not bound by a quantifier and hence is a free variable. The formulais not a proposition and so cannot be assigned a truth value. To assigna value to y to make the formula a true proposition, we need a value ofy so that there exists an integer x such that x < y and x > 2. It follows

49

Page 55: Logic and Discrete Mathematics

that y must be chosen to be greater than or equal to 4. In particular ifwe assign the value 4 to y, then the formula becomes a true proposition.On the other hand, if we assign the value 3, say, to y, then the formulabecomes a false proposition. The full analysis of this formula is that, if yis assigned a value greater than or equal to 4, then the formula is a trueproposition, but, if y is assigned a value less than or equal to 3, then theformula is a false proposition.

(iii) There are two variables, x and y, in this formula. The occurrences of xare bound by the quantifier ∀x : Z and the occurrences of y are bound bythe quantifier ∃y : Z. Hence there are no free variables. The formula isa proposition. The proposition asserts that for any integer x there existsan integer y such that y < x. This is obviously true; for instance we maychoose y to be x− 1.

(iv) In this case there are three variables, x , y and z. Only one of them, x,is bound by the quantifier ∀x : Z. Hence y and z are free variables. Theformula is not a proposition. The formula x = y ∧ x = z asserts that xis both equal to y and z. This can only be true when x = y = z. Thus¬(x = y ∧ x = z) can only be false when x = y = z. Hence, if y 6= z, theformula ¬(x = y ∧ x = z) is always true whatever the value of x. Thus,for example, if we assign the values 0 to y and 1 to z, then the formulabecomes a true proposition. If we assign the same value to both y and z,say the value 0, then x = y∧x = z is true when x = 0 and false otherwise.Hence ¬(x = y ∧ x = z) is false when x = 0 and true otherwise. Thereforethe proposition ∀x : Z •¬(x = y ∧x = z) is false. [Note that a propositioninvolving a universal quantifier ∀x : X is false whenever its scope is falsefor just one value of x.]

(v) In this example there are four variables, t, x, y and z. The variables xand y are bound by the multiple quantifier ∃x, y : Z, since this quantifierexpands to the two quantifiers ∃x : Z and ∃y : Z. Hence there are twofree variables, t and z. The formula is not a proposition and hence cannotbe assigned a truth value. The formula asserts that there exist integersx and y such that t < x, x < y and y < z. This is true if z − t > 2,but false otherwise. For example, if t = 0 and z = 3, then the assertion“t < x, x < y and y < z” is true when x = 1 and y = 2. Thus the formulabecomes a true proposition when t is assigned the value 0 and z is assignedthe value 3. On the other hand if, say, t = 0 and z = 2, then the formulabecomes a false proposition. In this case we cannot assign values to x andy so that the assertion “t < x, x < y and y < z” is true.

(vi) In this example there are no free variables. The only variables are x andy and these are bound by the quantifier ∀x, y : Z. The formula is aproposition which asserts that, for all integers x and y, x is greater thany. This is obviously false.

To recap we have the following answers:

(a) (i) and (iii) contain no free variables and are true.

(vi) contains no free variables and is false.

(b) (ii) is true when y = 4.

50

Page 56: Logic and Discrete Mathematics

(iv) is true when y = 0 and z = 1.

(v) is true when t = 0 and z = 3.

(c) (ii) is false when y = 3.

(iv) is false when y = 0 and z = 0.

(v) is false when t = 0 and z = 2.

When asked a question of this sort you need not give full explanations asin this worked example, but just the final answers as in the ‘recap’ above. Thepreliminary explanations were added here to help you see how the final answersmight be thought out. You must however give actual assignments to the freevariables and not a full analysis such as “(iv) is true when y 6= z and false wheny = z”. The question asks only for examples of an assignment of values to thefree variables.

51

Page 57: Logic and Discrete Mathematics

Chapter 3

PROOF BY INDUCTION

3.1 Introduction

The Principle of Mathematical Induction is based on a property of the systemof natural numbers. This property, called the inductive property, states that, ifS is a set of natural numbers such that:

(i) 0 belongs to S;

(ii) Whenever n belongs to S, n + 1 belongs to S,

then S = N. This property is one of the properties which characterize the set ofnatural numbers, N, and is accepted without proof. In any deductive science wemust start with some basic premises or truths, called axioms which are acceptedwithout proof. All other facts are then deduced from these using the rules oflogic. As we have seen all arguments in logic start with a number of premisesfrom which a certain conclusion is deduced. The axioms are usually propertieswhich seem self evident in the particular subject. Thus the above inductiveproperty of the natural numbers seems to be self evident. If 0 belongs to S,then 1 = 0 + 1 must belong to S, and then 2 = 1 + 1 belongs to S and soon. Therefore every natural number belongs to S. The problem lies with thephrase ”and so on”. In some sense there is an act of faith in the deduction thatevery natural number belongs to S. It is this that we accept as an axiom forthe system of natural numbers. The axiom deals with the phrase ”and so on”by the requirement that ”whenever n is in S, then n + 1 is in S. This is betterexpressed in logical terms as follows:

∀n : N • n ∈ S =⇒ (n + 1) ∈ S.

Using the infix notation the symbol ∈ represents the binary predicate ”is amember of”. Thus n ∈ S means that n is a member of the set S. Thus theinductive principle for the natural numbers asserts the truth of the proposition:

0 ∈ S ∧ (∀n : N • n ∈ S =⇒ n + 1 ∈ S) =⇒ S = N.

We may apply the inductive principle to the following situation. Supposethat for each natural number n we have a proposition, denoted by P (n). In thelanguage of predicate logic we may say that P is a unary predicate with domain

52

Page 58: Logic and Discrete Mathematics

N. Thus the proposition P (n) asserts some fact about the natural number n.Suppose that we wish to prove that P (n) is true for every natural number n.Consider the set S of all natural numbers n for which P (n) is true. Then we wishto show that S = N. This could be achieved by applying the inductive principleto S. Hence we must demonstrate the truth of the following statements:

(i) 0 ∈ S;

(ii) ∀n : N • n ∈ S =⇒ n + 1 ∈ S.

The statement 0 ∈ S is equivalent to the statement ”P (0) is true”. The state-ment:

∀n : N • n ∈ S =⇒ n + 1 ∈ S

is equivalent to the statement:

for all natural numbers n, if P (n) is true, then P (n + 1) is true.

Therefore to prove that P (n) is true for all natural numbers n it suffices to provethat:

[1] P (0) is true;

[2] For all natural numbers n, if P (n) is true, then P (n + 1) is true.

This method of proof is called the Principle of Mathematical Induction or simplyproof by induction. Note that proof by induction requires two steps. The firststep is to show that P (0) is true. The second step, called the inductive step, isto show that, for all natural numbers n, P (n) =⇒ P (n + 1).

3.2 Worked Example

Prove by induction that, for every natural number n:

n∑r=0

r =12n(n + 1)

i.e.0 + 1 + 2 + · · ·+ n =

12n(n + 1).

Solution. For every natural number n, let P (n) be the statement:

n∑r=0

r =12n(n + 1).

First Step: P (0) asserts that:

0∑r=0

r =120(0 + 1).

There is only one term in the sum; namely when r = 0. This term has value0. Hence the sum on the left hand side of the equation is equal to 0. Also120(0 + 1) = 0. Hence P (0) is true.

53

Page 59: Logic and Discrete Mathematics

Inductive Step: Let n be any natural number and assume that P (n) is true.Then:

n∑r=0

r =12n(n + 1).

Therefore:

n+1∑r=0

r =n∑

r=0

r + (n + 1)

=12n(n + 1) + (n + 1)

=12(n + 1)[n + 2]

=12(n + 1)[(n + 1) + 1].

i.e.n+1∑r=0

r =12(n + 1)[(n + 1) + 1].

This is exactly what the statement P (n + 1) asserts. Hence the statementP (n + 1) is true.

It follows by induction that the statement P (n) is true for every naturalnumber n.

The argument in the inductive step has been the result of writing downboth propositions P (n) and P (n + 1) and then comparing them. Note that, ifan denotes, for each natural number, an expression involving n, then from thedefinition of the sum symbol

∑:

n+1∑r=0

ar = a0 + a1 + a2 + . . . + an + an+1

= (a0 + a1 + a2 + . . . + an) + an+1

=n∑

r=0

ar + an+1.

In the inductive step we are given; i.e. may assume; the value for the sum∑nr=0 r. Using the above argument, we may express

∑n+1r=0 r as the sum of∑n

r=0 r and (n + 1), and then using some appropriate algebraic manipulationdetermine the required value of

∑n+1r=0 r.

3.3 Worked Example

Let a0, a1, a2, . . . be an infinite sequence of numbers such that a0 = 4 andan+1 = 2an + 3 for every natural number n. Prove that an = 7 × 2n − 3 forevery natural number n.

Solution. Let P (n) denote the statement an = 7 × 2n − 3. We have to provethat P (n) is true for all natural numbers n

54

Page 60: Logic and Discrete Mathematics

First Step: The statement P (0) asserts that a0 = 7×20−3. Now 7×20−3 =7 − 3 = 4. Hence in reality P (0) asserts that a0 = 4. But the truth of thestatement a0 = 4 is given. Thus P (0) is true.

Inductive Step: We have to show that for every natural number n P (n) =⇒P (n + 1). Therefore let n be a natural number and suppose that P (n) is true.Then an = 7 × 2n − 3. We must show that P (n + 1) is true; i.e. that an+1 =7×2n+1−3. To prove P (n+1), we must find some way to connect the statementP (n + 1) with the statement P (n). In this case the connection is clear. We aregiven that an+1 = 2an + 3. Hence, combining this equation with the equationan = 7× 2n − 3 given above and using some simple manipulations, we have:

an+1 = 2an + 3= 2(7× 2n − 3) + 3= 7× 2× 2n − 6 + 3

= 7× 2n+1 − 3.

Thus we have deduce the statement P (n+1). Since the above argument is validfor all natural numbers n, the inductive step is complete.

It follows, by the Principle of Mathematical Induction, that the propositionP (n) is true for every natural number n. Thus an = 7 × 2n − 3 for all naturalnumbers n.

Note that explanations have been added to the inductive step to help for-mulate a proof. In practice most of this analysis need only be done on a sheetof rough paper. Once the essential ideas of a proof have been worked out, onlythe final version, with a direct line of argument, need be written down.

3.4 Worked Example

Let a0, a1, a2, . . . be an infinite sequence of numbers such that a0 = 8 andan+1 = 3an + 2n2 for every natural number n. Prove by induction that forevery natural number n:

an = 3n+2 − n2 − n− 1.

Solution. For each natural number n, let P (n) be the statement:

an = 3n+2 − n2 − n− 1.

First Step: P (0) asserts that a0 = 30+2−02−0−1. But 30+2−02−0−1 =32 − 1 = 8. We are given that a0 = 8. Hence P (0) is true.

Inductive Step: Let n be a natural number and assume that the statementP (n) is true. Then:

an = 3n+2 − n2 − n− 1.

55

Page 61: Logic and Discrete Mathematics

Then:

an+1 = 3an + 2n2

= 3(3n+2 − n2 − n− 1) + 2n2

= 3× 3n+2 − 3n2 − 3n− 3 + 2n2

= 3n+3 − n2 − 3n− 3

= 3n+3 − (n2 + 2n + 1)− n− 2

= 3(n+1)+2 − (n + 1)2 − (n + 1)− 1

Thus the statement P (n + 1) is true.Therefore by induction the statement P (n) is true for every natural number

n.

The above argument in the inductive step is the result of some rough analysis.This analysis need not be described in the solution. The argument given in thesolution above should be sufficient. The reader need not know how the writerwas able to formulate his proof. All that matters is that the argument used canbe easily understood and is indeed a valid proof. As an aid to understanding howsuch arguments may be constructed, the method by which the above argumentwas formulated is described as follows:

We need first to clarify what needs to be proved. Let us write down thestatement P (n + 1):

an+1 = 3(n+1)+2 − (n + 1)2 − (n + 1)− 1.

To prove this statement we must find suitable connections between it and theassumptions we have made in the inductive step; namely the statement P (n):

an = 3n+2 − n2 − n− 1.

In the question we are given a formula which relates an+1 to an. We may usethis formula to express an+1 in terms of n with the help of the assumption P (n).To complete the process we must then manipulate the resultant expression foran+1 and write it in terms of n + 1. This should yield the statement P (n + 1).These ideas were written down on a sheet of rough paper, thrashed out intosome form of argument, and then a number of revisions made, until a finalversion was arrived at. [Sometimes it helps to work directly on the conclusion.For instance we may take note that (n + 1)2 = n2 + 2n + 1. This observationmay help in the algebraic manipulations that must be performed in the proof.]

3.5 WARNING

A common mistake made by some students is to confuse the statement P (n)which is needed for a proof by induction with an expression that occurs in theproblem. For instance in the first example we denoted by P (n) the statementan = 7 × 2n − 3. P (n) should not be confused with the expression an or7 × 2n − 3. You should NOT write P (n) = an or P (n) = 7 × 2n − 3 or evenP (n) = an = 7 × 2n − 3. P (n) stands for a statement. A statement can betranslated into a full English sentence. The expressions an and 7 × 2n − 3 do

56

Page 62: Logic and Discrete Mathematics

NOT translate into full English sentences. It is meaningless to say that an istrue, or that 7 × 2n − 3 is false. However an equation can be given a truthvalue; an equation can be true or it can be false. For example 12 = 1 is atrue statement, and (−1)2 = −1 is a false statement. That is why in the firstexample we chose P (n) to be the equation an = 7× 2n − 3.

3.6 Worked Example

Prove by induction that, for every natural number n:

n∑r=0

r(r + 1)(r + 2) =14n(n + 1)(n + 2)(n + 3).

Solution. For every natural number n, let P (n) be the statement:

n∑r=0

r(r + 1)(r + 2) =14n(n + 1)(n + 2)(n + 3).

First Step: P (0) asserts that:

0∑r=0

r(r + 1)(r + 2) =140(0 + 1)(0 + 2)(0 + 3).

There is only one term in the sum; namely when r = 0. This term has value 0.The value on the right hand side of the equation is also 0. Hence P (0) is true.

Inductive Step: Let n be any natural number and assume that P (n) is true.Then:

n∑r=0

r(r + 1)(r + 2) =14n(n + 1)(n + 2)(n + 3).

Therefore:n+1∑r=0

r(r + 1)(r + 2) =n∑

r=0

r(r + 1)(r + 2) + (n + 1)[(n + 1) + 1][(n + 1) + 2]

=14n(n + 1)(n + 2)(n + 3) + (n + 1)(n + 2)(n + 3)

=14(n + 1)(n + 2)(n + 3)(n + 4)

=14(n + 1)[(n + 1) + 1][(n + 1) + 2][(n + 1) + 3].

Hence the statement P (n + 1) is true.It follows by induction that the statement P (n) is true for every natural

number n.

Again the argument in the inductive step has been the result of thoughtfulanalysis. The propositions P (n) and P (n+1) were written down and compared.Firstly we know from the property of

∑that:

n+1∑r=0

r(r + 1)(r + 2) =n∑

r=0

r(r + 1)(r + 2) + n + 1[(n + 1) + 1][(n + 1) + 2].

57

Page 63: Logic and Discrete Mathematics

Thus it remains to show by some algebraic manipulation that:

14n(n + 1)(n + 2)(n + 3) + (n + 1)[(n + 1) + 1][(n + 1) + 2]

=14(n + 1)[(n + 1) + 1][(n + 1) + 2][(n + 1) + 3].

Note that P (n) does NOT denote the sum∑n

r=0 r(r + 1)(r + 2), but thecomplete equation

∑nr=0 r(r + 1)(r + 2) = 1

4n(n + 1)(n + 2)(n + 2). If you needsome notation for the sum, use a different symbol, say for example S(n).

3.7 Generalizations of Proof by Induction

Sometimes we need to prove that a proposition P (n) is true not for all naturalnumbers n but say for all natural numbers n greater than or equal to a givennatural number m, which need not be 0. In this case the first step in theargument would deal with the case n = m, rather than the case n = 0; i.e. wewould prove the proposition P (m). The inductive step would involve the proofof P (n) =⇒ P (n + 1) for all n ≥ m. Thus proof by induction in this case takesthe form: If:

(a) P (m) is true;

(b) ∀n : N | n ≥ m • P (n) =⇒ P (n + 1),

then P (n) is true for all natural numbers n greater than or equal to m.This form of induction can be deduced from the inductive property of the

natural numbers with the set S defined to be the set of all natural numbers nsuch that P (n + m) is true.

We mention another generalization, but will not deal with it further. ThePrinciple of Complete Induction states that, given a fixed natural number mand a proposition P (n) for every natural number n greater than or equal to m,if:

(i) P (m) is true;

(ii) ∀n : N | n ≥ m • (∀k : N | m ≤ k ≤ n • P (k)) =⇒ P (n + 1),

then P (n) is true for all natural numbers n greater than or equal to m.The inductive step asserts that, if, for any natural number n greater than

or equal to m, P (k) is true whenever m ≤ k ≤ n, then P (n + 1) is true; i.e.all the propositions P (m), P (m + 1), P (m + 2), . . ., P (n) together imply theproposition P (n + 1). Again this form of induction may be deduced from theinductive property of the natural numbers with in this case the set S defined tobe the set of all natural numbers n such that the propositions P (m), P (m + 1),P (m + 2), . . ., P (m + n) are all true.

3.8 Worked Example

Prove by induction that, for every natural number n ≥ 4:n∑

r=4

1(r − 2)(r − 3)

=n− 3n− 2

.

58

Page 64: Logic and Discrete Mathematics

Note that the general term of the sum is meaningless when r = 2 or r = 3.

Solution. For n ≥ 4, let P (n) be the statement:

n∑r=4

1(r − 2)(r − 3)

=n− 3n− 2

.

First Step: P (4) is the proposition:

4∑r=4

1(r − 2)(r − 3)

=4− 34− 2

.

There is only one term in the sum and this has value 1(4−2)(4−3) = 1

2 . Now4−34−2 = 1

2 . Hence P (4) is true.Inductive Step: Suppose that n is a natural number greater than or equal

to 4 and assume that P (n) is true. Then:

n∑r=4

1(r − 2)(r − 3)

=n− 3n− 2

.

Then:

n+1∑r=4

1(r − 2)(r − 3)

=n∑

r=4

1(r − 2)(r − 3)

+1

[(n + 1)− 2][(n + 1)− 3]

=n− 3n− 2

+1

(n− 1)(n− 2)

=1

(n− 1)(n− 2)[(n− 3)(n− 1) + 1]

=1

(n− 1)(n− 2)[(n2 − 4n + 3) + 1]

=1

(n− 1)(n− 2)(n2 − 4n + 4)

=1

(n− 1)(n− 2)(n− 2)2

=n− 2n− 1

=(n + 1)− 3(n + 1)− 2

.

Hence P (n + 1) is true.It follows by induction that P (n) is true for all natural numbers n ≥ 4.

59

Page 65: Logic and Discrete Mathematics

Chapter 4

BASIC SET THEORY

4.1 Sets

A “set” is a collection of objects. In mathematics, we commonly use a letter orsome other symbol to denote a set. Some sets are so important, being used veryfrequently that we fix once and for all a particular notation for the set. Thus, forexample, we reserve the symbol Z to denote the set of all integers. If S denotesa set and x denotes an object in S, we write x ∈ S and say that x belongs to Sor that x is a member or element of S. If an object x does not belong to the setS we write x 6∈ S. Some symbols for sets are used in a transient way, discardingthem once we have finished with the context in which they occur. For examplein the present context of this paragraph let us assume that:

L denotes the set of all natural numbers less than 10;H denotes the set of all members of the House of Commonsand S denotes the set of all railway stations in England.

As usual Z denotes the set of all integers. Then 5 is a member or element of theset Z. Reading Station belongs to S. We may also write 5 ∈ Z, 12 6∈ L, 2

5 6∈ Z,5 ∈ L and John Major ∈ H.

There are two ways of specifying a set. When the set contains only a finitenumber of elements, we may list them between braces; i.e. ‘curly’ brackets { }.For example the expression {1, 4, 5, 7, 8} denotes the set containing the numbers1, 4, 5, 6, 7 and 8. In such a representation of a set the order in which theelements are listed does not matter. For example the sets {1, 2, 3} and {2, 3, 1}are the same. Also an element of a set need only be listed once; additionallistings of the same element are disregarded. Thus, for example, the expressions{1, 2, 3}, {1, 2, 1, 3} and {1, 1, 1, 2, 2, 3, 3, 3, 3} are different ways of representingthe same set. Obviously the most economical way of representing such sets isto list each element once. Sets represented in this way are said to be defined byextension.

We may also define a set by intension. In this case we specify some predicateP (x) which is true precisely when x is a member of the set:

{x | P (x)}.

60

Page 66: Logic and Discrete Mathematics

This expression represents the set of all objects x for which P (x) is true. Fre-quently sets consist of objects of the same type. Thus:

{x : X | P (x)}

denotes the set of all objects x of type X for which P (x) is true. For examplethe set of all natural numbers x such that x2 < 20 may be denoted by:

{x : N | x2 < 20}.

This set may also be expressed in form:

{x | x ∈ N ∧ x2 < 20},

or even defined by extension; thus {0, 1, 2, 3, 4}. One of the main uses of def-inition by intension is in representing infinite sets; i.e. sets with an infinitenumber of elements. Although all sets may be expressed in this way there is amore sophisticated representation of a set which is of particular use in ComputerScience. This takes the form:

{term • declaration | predicate},

and is referred to as ‘set comprehension’. For example, the set of all squaresless than 20 of natural numbers may be denoted by:

{x2 • x : N | x2 < 20}.

Again the elements of this set may be listed; {0, 1, 4, 9, 16}. Using the morebasic notation, this set may also be denoted by:

{x : N | ∃y : N • x = y2 ∧ x < 20}.

In this case the predicate involves a quantifier. Set comprehension also providesa convenient way of representing the graph of a function as a set. For examplethe graph of the function, sinx, with values of x from 0 to π may be representedas the set:

{(x, sinx) • x : R | 0 ≤ x ≤ π}.

The pair (x, sinx) represents a typical point on the graph; i.e. is the coordinatepair of such a point. Another example of the same kind involves the set of allpairs consisting of candidates for a particular examination and the marks theyhave achieved. Thus, if C denotes the set of candidates for the examination andxAy means that candidate x has achieved the mark y, then the required datais represented by the set:

{(x, y) • x : C; y : N | xAy}.

As another example, suppose that xV y means that the person x has visitedthe town y. Suppose also that j stands for “John” and that T is the set of alltowns. The set of all towns which John has visited is given by:

{y : T | jV y}.

61

Page 67: Logic and Discrete Mathematics

If P denotes the set of all people, the data consisting of all people and the townsthat each person has visited is given by the set:

{(x, y) • x : P ; y : T | xV y}.

Two sets, A and B, are said to be equal and we write A = B, if they containthe same elements. Often the same set may be represented or labeled in morethan one way. In such cases we need the relation of equality to make it clearthat differing specifications of a set give rise to the same collection of objects.Thus, for example, {1, 4, 5, 7, 8} and {4, 8, 5, 1, 7} are different representationsof the same set; i.e.

{1, 4, 5, 7, 8} = {4, 8, 5, 1, 7}.Again we may write:

{x : N | x2 < 20} = {0, 1, 2, 3, 4}.

If two sets, A and B, are not equal, we write A 6= B. In general a linethrough a relational symbol indicates the negation of the relationship. ThusA 6= B asserts that the statement A = B is false.

4.2 The Universal Set

Frequently when we deal with some problem in Set Theory we only considerobjects of some fixed prescribed type, for example natural numbers or realnumbers. Thus, if we are dealing with sets whose elements are of a particulartype X, our sets take the form:

{x : X | P (x)}.

Note that X is a set. In this restricted context and only in this context we callX the universal set. Every set under discussion within this context is a subsetof the universal set X.

4.3 Subsets of a Set

A set A is said to be a subset of a set B if every element of A is an element ofB. For example, {3, 5, 7} is a subset of {1, 3, 4, 5, 7}. Note that N is a subset ofZ, because every natural number is an integer. We use the symbol ⊆ to mean“ is a subset of”. Thus we may write:

{3, 5, 7} ⊆ {1, 3, 4, 5, 7}; N ⊆ Z.

Obviously by definition, every set A is a subset of itself. A subset of A otherthan A is said to be a proper subset of A. The symbol ⊂ is used represent thephrase “is a proper subset of”. Thus S ⊂ A means that S is a proper subset ofA. Observe that:

{3, 5, 7} ⊂ {1, 3, 4, 5, 7}; N ⊂ Z.

If we deal only with objects of a particular type, X, i.e. X is the universal set,then the statement “A is a subset of B” is logically equivalent to the proposition:

∀x : X • x ∈ A =⇒ x ∈ B.

62

Page 68: Logic and Discrete Mathematics

4.4 Vacuous Truth

Given that Rockall is an uninhabited island, the proposition “All inhabitants ofRockall are left-handed” is a true statement. Let P denote the set of all people,let R denote the set of all inhabitants of Rockall and let L denote the set of allleft-handed people. Then the proposition translates into predicate logic as:

∀x : P • x ∈ R =⇒ x ∈ L.

This statement is true, since for every person x the proposition:

x ∈ R =⇒ x ∈ L

is true. The reason for this is that, since there are no inhabitants of Rockall,x ∈ R is false for every person x. Because the set R is empty, we say thatthe proposition “All inhabitants of Rockall are left-handed” is a vacuous truthor is true vacuously; i.e. is true because there are no inhabitants of Rockall;the assertion does not apply to anybody. We say that the set R is empty. Bythe definition of equality of sets two empty sets are equal. Thus there is oneand only one empty set which we denote by ∅. Similarly the statement thatall the rivers on the moon contain fish is a true vacuously (the set of all riverson the moon is empty). Such statements although logically true have no realcontent; they are evidently true within a vacuum. As a consequence of vacuoustruths, it follows that the empty set is a subset of every set. For any set A, theproposition:

∀x : A • x ∈ ∅ =⇒ x ∈ A

is vacuously true. This means by definition that ∅ ⊆ A.

4.5 Set Operations

In the same way that we may combine two numbers to obtain a new numberusing operations such as addition and multiplication, we may compose two setsinto a single set in various ways. Indeed there are many similarities in the‘arithmetic’ of sets and ordinary arithmetic.

The union of two sets A and B is the set of all objects which belong toone or both of the sets A, B. This set is denoted by A ∪ B. For example, ifA = {0, 3, 7, 8} and B = {2, 3, 6, 8, 9}, then A ∪ B = {0, 2, 3, 4, 6, 7, 8, 9}. Ingeneral, we may define:

A ∪B = {x | x ∈ A ∨ x ∈ B}.

Thus x ∈ A ∪B if and only if x ∈ A ∨ x ∈ B; i.e. x ∈ A or x ∈ B.The intersection of two sets A and B is the set of all objects which belong to

both A and B, and is denoted by A ∩B. Thus, for example, if A and B are asdescribed in the previous paragraph, then A ∩ B = {3, 8}. In general, we maydefine:

A ∩B = {x | x ∈ A ∧ x ∈ B}.

Thus x ∈ A ∩B if and only if x ∩A ∧ x ∈ B; i.e. x ∈ A and x ∈ B.Since the operation of “union” may be applied to any two sets, given three

sets A, B and C, we may obtain the sets (A∪B)∪C and A∪ (B ∪C). Because

63

Page 69: Logic and Discrete Mathematics

the connective ∨ satisfies the associative law; (P ∨Q) ∨R WV P ∨ (Q ∨R), itis easy to see that the operation of union is associative:

(A ∪B) ∪ C = A ∪ (B ∪ C).

For:

x ∈ (A ∪B) ∪ C WV x ∈ A ∪B ∨ x ∈ C

WV (x ∈ A ∨ x ∈ B) ∨ x ∈ C

WV x ∈ A ∨ (x ∈ B ∨ x ∈ C)WV x ∈ A ∨ x ∈ B ∪ C)WV x ∈ A ∪ (B ∪ C).

We may therefore denote the union of three sets A, B and C by A ∪ B ∪ C.The removal of the brackets in this case does not lead to an ambiguity. Moregenerally, the union of four or more sets does not depend on the order in whichthe operation of union is applied and hence we do not need to use brackets todistinguish this ordering. The same also holds for intersections; the operationof ∩ is associative and so the repeated application of ∩ does not need the useof brackets to indicate the order in which the operation is performed.

The logical connective ¬ may also be used to define a set operation. Supposethat A and B are two sets. Then A\B denotes the set of all objects which belongto A but not to B:

A\B = {x | x ∈ A ∧ ¬x ∈ B};

i.e.A\B = {x | x ∈ A ∧ x 6∈ B}.

For example if A = {0, 3, 7, 8} and B = {2, 3, 6, 8, 9}, then A\B = {0, 7}. Notethat, B\A = {2, 6, 9}. Thus, in general, A\B and B\A are different sets. “A\B”may be read as “A minus B” and is called the difference of A and B.

Suppose that X is the universal set and that all sets under consideration aresubsets of X. Let A be a set (i.e. a subset of X). Then the difference of X andA is called the complement of A (in X) and is denoted by A′. Thus:

A′ = {x : X | ¬x ∈ A} = {x : X | x 6∈ A}.

For example, if R (the set of all real numbers) is the universal set in a particulardiscussion and A is the set of all real numbers less than or equal to 2, then A′

is the set of all real numbers greater than 2.These set operations also explain why we need the empty set. For example,

if A = {1, 3, 4, 6} and B = {2, 7, 8}, then A ∩ B is the set of all objects whichbelong to both A and B. But there is no object which belongs to both A andB and hence no object which belongs to A ∩ B. Thus A ∩ B is the empty set;A ∩ B = ∅. Without the concept of empty set, we would not be able to definein general the intersection of two sets.

64

Page 70: Logic and Discrete Mathematics

4.6 Venn Diagrams

In this section we assume that the sets A,B,C etc. under discussion are subsetsof a universal set X. We can obtain an intuitively helpful idea of how sets behaveby drawing special diagrams called Venn diagrams. To represent the universalset we draw a rectangular region in a plane:

The universal set is then represented by the points in the rectangular region.The subsets of X are represented by circular or oval regions contained withinthe rectangular region. The following diagram represents a general set A:

Note that the rectangular region is divided into 2 parts or subregions, calledatoms. These atoms represent the sets A and A′ as shown by the shading in thefollowing Venn diagrams:

65

Page 71: Logic and Discrete Mathematics

In the case of two sets A and B the following Venn diagram represents themost general situation:

Note that there are 4 atoms which represent the sets A ∩ B, A\B, B\A and(A ∪B)′:

Note that the shaded region representing A ∪B is region composed of or parti-tioned into the atoms which represent the sets A ∩B, A\B and B\A:

66

Page 72: Logic and Discrete Mathematics

This suggests that:

A ∪B = (A ∩B) ∪ (A\B) ∪ (B\A).

Indeed this equation is an identity; i.e. it is satisfied by any pair of sets A andB. Many set identities can be observed in this way from a Venn diagram andcan then be verified by more rigorous methods.

The general arrangement of three sets A,B,C is given in the Venn diagram:

In this case there are 8 atoms:

A∩B∩C, A\(B∪C), B\(C∪A), C\(A∪B), (A∩B)\C, B∩C)\A,C ∩A)\B, (A ∪B ∪ C)′.

Sets obtained from these ‘basic’ sets A,B,C, . . . using the operations of union,intersection, difference etc. may be represented by the shading of one or moreof these atoms. Thus for example A\B ∩C is represented by the shaded regionin the Venn diagram:

67

Page 73: Logic and Discrete Mathematics

We must however temper the use of Venn diagrams with a warning. They shouldbe drawn in sufficient generality for the problem in hand and should not exhibitan assumption which is not warranted. Thus for example the following Venndiagram although partitioning the rectangular region into 8 subregions makesthe assumption that (A ∩B)\C = ∅:

Note that with this general arrangement, the ‘atom’ C\(A ∪ B) is representedby the two non-overlapping shaded regions in the Venn diagram:

As noted above we may use Venn diagrams to suggest identities involving twoor more sets. Suppose that P and Q are sets which may be represented by theshading of one or more atoms of three sets A,B, C. Then P ∩Q is representedby those shaded atoms which are common to both P and Q and P ∪ Q isrepresented by all the shaded atoms associated with either P or Q. Thus forexample B is composed of the atoms:

B\A ∪ C, (A ∩B)\C, (C ∩B)\A, A ∩B ∩ C;

and C is composed of the atoms:

C\A ∪B, (A ∩ C)\B, (C ∩B)\A, A ∩B ∩ C;

Thus B ∪ C is composed of all the atoms listed for B and C; namely:

B\A∪C, (A∩B)\C, C\A∪B, (A∩C)\B, (C ∩B)\A, A∩B ∩C;

Now A is composed of the atoms:

A\B ∪ C, (A ∩B)\C, (A ∩ C)\B, A ∩B ∩ C;

Hence A ∩ (B ∪ C) is composed of the atoms:

(A ∩B)\C, (A ∩ C)\B, A ∩B ∩ C.

68

Page 74: Logic and Discrete Mathematics

This analysis may be expressed in terms of Venn diagrams as follows:

A similar analysis for (A ∩B) ∪ (A ∩ C) is:

69

Page 75: Logic and Discrete Mathematics

By comparing the Venn diagrams it appears that:

(A ∩B) ∪ (A ∩ C) = A ∩ (B ∪ C).

A proper proof of this identity is given as follows:

x ∈ (A ∩B) ∪ (A ∩ C) WV x ∈ A ∩B ∨ x ∈ A ∩ C

WV (x ∈ A ∧ x ∈ B) ∨ (x ∈ A ∧ x ∈ C)WV x ∈ A ∧ (x ∈ B ∨ x ∈ C)WV x ∈ A ∧ x ∈ B ∪ C

WV x ∈ A ∩ (B ∪ C).

4.7 Disjoint Sets

Two sets are said to be disjoint if they have no common element. Thus forexample, the following two sets are disjoint:

{Reading,Windsor,Slough, London};{Oxford,Cambridge,Basingstoke,Birmingham,Salisbury}.

On the other hand the sets:

{George, John,Paul,Ringo};{Ringo,Pete}

are not disjoint, since Ringo is an element common to both sets. Clearly twosets A and B are disjoint if and only if A ∩B = ∅.

This definition extends to more than two sets. We say that three or moresets are disjoint if no two of them have an element in common. Thus for examplethe sets:

{0, 2, 5, 10}, {3, 8, 12}, {4, 6, 20}, {7, 11, 15, 18}, {23, 24, 25, 26, 27, 28}

are disjoint. We may represent disjoint sets on a Venn diagram by regions ofwhich no two overlap. Thus the atoms which represent the intersections of twosets in the diagram are removed by shrinking their area to zero.

70

Page 76: Logic and Discrete Mathematics

4.8 Cardinality

A set A is said to be finite if the number of elements in the set is finite; i.e. forsome natural number n, the number of elements in the set is n. For example,the set {John,Paul,George,Ringo} is finite, since the number of elements in theset is 4. Note that ∅ is finite since the number of elements in this set is 0.However the sets N, Z and R are not finite; in this case we say that the sets areinfinite. Thus a set is infinite if it is not finite.

The number of elements in a finite set, A, is called the cardinality of the setand is denoted by #A. If A and B are disjoint finite sets, then:

#(A ∪B) = #A + #B.

This principle clearly extends to more than two sets.Let A and B be two not necessarily disjoint sets. By considering the atoms

in the case of two sets, we may observe that:

#A = #(A ∩B) + #(A\B);#B = #(A ∩B) + #(B\A);

#(A ∪B) = #(A ∩B) + #(A\B) + #(B\A).

(For example A is the union of the disjoint sets - or the disjoint union of thesets - A ∩B and A\B.) It follows that:

#(A ∪B) + #(A ∩B) = (#(A ∩B) + #(A\B) + #(B\A)) + #(A ∩B)= (#(A ∩B) + #(A\B)) + (#(A ∩B) + #(B\A))= #A + #B.

4.9 Sets of Sets

A set is an object in its own right. Thus we may take sets as elements in othersets. In this way we may form sets of sets. For example we may consider theset:

A = {N, Z, R}.

Note that #A = 3. A is NOT the set of all real numbers; it does not containevery natural number, every integer and every real number. Its elements aresets not numbers. Similarly:

S = {{1, 2, 4, 5, 8}, {2, 3, 6}, {3, 7}, {7, 8, 9}}

is a set containing 4 elements; each element is itself a set. The set S doesNOT contain the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9. We may interpret sets of sets ineveryday life. For example a football league is a collection or set of clubs andeach club is a collection or set of players (and possibly support staff). Many largeorganizations also have a similar structure, perhaps with many more layers, suchas regional, divisional, branch, department, staff. A region may be composedof a number of divisions, each division has a number of branches, each branchis divided into departments and at the lowest level each department contains anumber of staff.

71

Page 77: Logic and Discrete Mathematics

4.10 The Power Set of a Set

If A is a set the power set of A is the set of all subsets of A, and is denoted byPA. For example, if A = {1, 2, 5}, then:

PA = {∅, {1}, {2}, {5}, {1, 2}, {1, 5}, {2, 5}, {1, 2, 5}}.

Note that ∅ and A, itself, are subsets of A and hence are elements of PA.In the language of sets, we adopt the convention that P binds more strongly

than the ‘connectives’ ∩, ∪, \. Thus, for example, PA∪PB means (PA)∪ (PB).

4.11 Worked Example

Let A = {1, 2, 4, 5, 8, 9}, B = {0, 1, 2, 7, 9}, C = {3, 5, 6, 8} and D = {1, 3, 5, 7}.Represent each of the following sets by EITHER a list of its elements betweenbraces, with no element listed more than once, OR the symbol ∅:

(i) (A\B) ∪ C

(ii) A\(B ∪ C)

(iii) {x2 − 3x • x : N | 5x < 21}

(iv) {x : Z | x2 ∈ A}

(v) {x : Z | x2 ∈ C}

(vi) {x : N | {x, x + 3} ⊆ A}

(vii) {x : N | {x, x + 3} ⊆ B}

(viii) PD\PC.

Solution. (i) A\B = {4, 5, 8}. Therefore (A\B)∪C = {4, 5, 8}∪ {3, 5, 6, 8} ={3, 4, 5, 6, 8}.

(ii) B ∪ C = {0, 1, 2, 3, 5, 6, 7, 8, 9}. Therefore A\(B ∪ C) = {4}.

(iii) First we must identify the set {x : N | 5x < 21}. It consists of all thenatural numbers x such that 5x < 21; i.e. the natural numbers 0, 1, 2, 3, 4.Next we must evaluate the term x2 − 3x for these natural numbers; thus:

02 − 3× 0 = 0;

12 − 3× 1 = −2;

22 − 3× 2 = −2;

32 − 3× 3 = 0;

42 − 3× 4 = 4.

The required set must therefore contain these numbers, but listed no morethan once. Hence:

{x2 − 3x • x : N | 5x < 21} = {−2, 0, 4}.

72

Page 78: Logic and Discrete Mathematics

(iv) We must determine all integers x such that x2 ∈ A. The only completesquares in A are 1, 4, 9. Hence the possible values of x are−1, 1,−2, 2,−3, 3.Thus:

{x : Z | x2 ∈ A} = {−3,−2,−1, 1, 2, 3}.

(v) In this case we must determine all integers x such that x2 ∈ C. There areno complete squares in the set C. Therefore:

{x : Z | x2 ∈ C} = ∅.

(vi) In this example we require all natural numbers x so that {x, x + 3} ⊆ A.Obviously every x satisfying this condition must belong to the set A. Hencewe determine those elements x ∈ A such that x + 3 ∈ A. Considering theelements of A in turn we find that the only elements x of A such thatx + 3 ∈ A are 1, 2, 5. Therefore:

{x : N | {x, x + 3} ⊆ A} = {1, 2, 5}.

(vii) In this case there are no elements of the set B such that x + 3 ∈ B. Thus:

{x : N | {x, x + 3} ⊆ B} = ∅.

(viii) Now PD is the set of all subsets of D. The subsets of D are:

∅, {1}, {3}, {5}, {7}, {1, 3}, {1, 5}, {1, 7}, {3, 5}, {3, 7}, {5, 7}{1, 3, 5}, {1, 3, 7}, {1, 5, 7}, {3, 5, 7}, {1, 3, 5, 7}.

Among these 16 sets only ∅, {3}, {5} and {3, 5} are subsets of C. Therefore:

PD\PC = {{1}, {7}, {1, 3}, {1, 5}, {1, 7}, {3, 7}, {5, 7}{1, 3, 5}, {1, 3, 7}, {1, 5, 7}, {3, 5, 7}, {1, 3, 5, 7}}.

4.12 Worked Example

State the cardinalities of the following sets:

(a) {1 + 3, 3− 2, 6− 2, 2 + 7, 4 + 9, 5− 1, 5 + 4}.

(b) {{1, 2}, {1, 3}, {2, 4}, {4, 5, 6}}.

(c) {{1, 2} ∪ {2, 3, 4}, {2, 3, 4}\{1, 2}, {1, 4} ∪ {2, 3}, {3, 4, 5} ∩ {1, 3, 4, 6},{3, 4, 5} ∪ {2, 3}}.

(d) {{1, 2, 3}, {1, 2, 4}, {2, 4, 5}}\{{1, 3, 4}, {4, 5, 6}, {4, 1, 2}}.

Solution. (a) The cardinality of this set is NOT 7. Since 1 + 3 = 4, 3− 2 = 1,6− 2 = 4, 2 + 7 = 9, 4 + 9 = 13, 5− 1 = 4 and 4 + 5 = 9, the set containsonly the 4 elements 1, 4, 9, 13. Thus the cardinality is 4.

(b) The elements of this set are themselves sets, NOT the numbers within thesesets. The cardinality of the given set is therefore 4.

73

Page 79: Logic and Discrete Mathematics

(c) The elements of this set are again sets. In this case we need to clarify whatelements these sets contain. Indeed we have:

{1, 2} ∪ {2, 3, 4} = {1, 2, 3, 4}{2, 3, 4}\{1, 2} = {3, 4}{1, 4} ∪ {2, 3} = {1, 2, 3, 4}

{3, 4, 5} ∩ {1, 3, 4, 6} = {3, 4}{3, 4, 5} ∪ {2, 3} = {2, 3, 4, 5}

Indeed there are only 3 distinct sets among these 5 sets; namely {1, 2, 3, 4},{3, 4} and {2, 3, 4, 5}. Thus the cardinality of the given set is 3.

(d) Since {1, 2, 4} = {4, 1, 2}, there are only two of the three elements in theset {{1, 2, 3}, {1, 2, 4}, {2, 4, 5}} which are not elements in the subsequentset {{1, 3, 4}, {4, 5, 6}, {4, 1, 2}}; namely the elements {1, 2, 3} and {2, 4, 5}.Thus the cardinality of the given set is 2.

4.13 Worked Example

Many sentences in English often use collective words; words which representcollections or sets of objects. Discussions about these objects can then be for-mulated mathematically using set theory. Suppose for example that:

A is the set of all houses which have burglar alarms,B is the set of all houses in Berkshire,C is the set of all houses which have central heating,D is the set of all detached houses,G is the set of all houses which have double glazing.

Using only (some or all of) the symbols:

A, B, C, D, G, ∅, ∪, ∩, \, =, 6=, ⊆, (, ), =⇒

write down expressions for the following sets and statements:

(a) The set of all detached houses in Berkshire which have central heating.

(b) The set of all houses in Berkshire which have neither central heating nordouble glazing.

(c) All detached houses in Berkshire have burglar alarms or double glazing orboth.

(d) There is at least one house in Berkshire which has central heating but notdouble glazing.

(e) If all houses in Berkshire have central heating, then all detached houses inBerkshire must have central heating.

Solution. (a) The set of all detached houses is D, the set of all houses in Berk-shire is B and the set of all houses with central heating is C. Thereforethe set of all detached houses in Berkshire which have central heating isD ∩B ∩ C.

74

Page 80: Logic and Discrete Mathematics

(b) The set of all houses which have central heating or double glazing or both isC ∪G. A house in Berkshire which does not have central heating or doubleglazing belongs to the set B but not to the set C∪G. Therefore the requiredset is B\(C ∪G).

(c) A house has a burglar alarm or double glazing or both if it belongs to theset A ∪ G. A detached house in Berkshire belongs to the set D ∩ B. Thestatement therefore asserts that an element of D ∩B belongs to A∪G; i.e.D ∩B is a subset of A ∪G:

D ∩B ⊆ A ∪G.

(d) A house in Berkshire with central heating belongs to the set B ∩ C. If itdoes not also have double glazing it cannot belong to G. Thus such a housebelongs to the set (B ∩ C)\G. Hence the statement asserts that this set isnot empty; i.e:

(B ∩ C)\G 6= ∅.

(e) The statement “all houses in Berkshire have central heating” translates intothe statement B ⊆ C. The statement “all detached houses in Berkshirehave central heating” similarly translates into D ∩ B ⊆ C. Thus the fullstatement asserts:

B ⊆ C =⇒ D ∩B ⊆ C.

4.14 Worked Example

As before instead of using letters to denote objects such as sets we may usewords or word combinations. For example suppose that the expression Studentdenotes the set of all students in the University of Reading and that the followingexpressions denote subsets of Student:

mathematician, physicist, chemist, computer-scientist,St-Andrew, St-George, St-Patrick, Wantage,soccer-player, tennis-player.

Using only (some or all of) the above names for subsets of Student and thefollowing symbols:

∅, ∪, ∩, \, =, 6=, ⊆, (, ), =⇒

write down expressions for the following subsets of Student and statements:

(a) The set of all Chemistry students in St. Andrew’s Hall.

(b) The set of all Physics students in St. George’s Hall who do not play socceror tennis.

(c) No computer Science students live in St. Patrick’s Hall.

(d) All Mathematics students and all Computer Science students live in St.Patrick’s or Wantage Hall.

(e) If all Mathematics students in St. Patrick’s Hall play soccer, then those inWantage Hall will have to play it too.

75

Page 81: Logic and Discrete Mathematics

Solution. (a) The set of all Chemistry students in St. Andrew’s Hall is the setof all those students who belong to both the sets chemist and St-Andrew. Inother words the set is chemist ∩ St-Andrew.

(b) Similarly the set of all Physics students in St. George’s Hall is the setphysics ∩ St-George. The set of students who play either soccer or tennisis set of students who belong to one or both of the sets soccer-player andtennis-player; i.e. the set soccer-player ∪ tennis-player. Thus the set of allPhysics students in St. George’s Hall who do not play soccer or tennis is:

(physicist ∩ St-George)\(soccer-player ∪ tennis-player).

(c) The set of Computer Science students who live in St. Patrick’s Hall is theset computer-scientist ∩ St-Patrick The statement asserts that there are nostudents in this set; i.e:

computer-scientist ∩ St-Patrick = ∅.

(d) The set of all Mathematics students and all Computer Science students is theunion of the set mathematician and the set computer-scientist. Similarly theset of all students who live in St. Patrick’s Hall or Wantage Hall is the unionof the set St-Patrick and the set Wantage. The statement therefore assertsthat every element of the set textsfmathematician ∪ computer-scientist isan element of the set St-Patrick ∪Wantage; i.e:

mathematician ∪ computer-scientist ⊆ St-Patrick ∪Wantage.

(e) The set of all Mathematics students who live in St. Patrick’s Hall is the setmathematician∩St-Patrick. The statement “all mathematics students in St.Patrick’s Hall play soccer” translates into:

mathematician ∩ St-Patrick ⊆ soccer-player.

Similarly the statement “all mathematics students in Wantage Hall playsoccer” translates into:

mathematician ∩Wantage ⊆ soccer-player.

Therefore the given statement may be expressed as:

mathematician ∩ St-Patrick ⊆ soccer-player

=⇒ mathematician ∩Wantage ⊆ soccer-player.

76

Page 82: Logic and Discrete Mathematics

77

Page 83: Logic and Discrete Mathematics

Chapter 5

RELATIONS

5.1 Ordered Pairs

In many situations we need to consider pairs of objects arranged in a definiteorder. If x and y are two objects, we denote the ordered pair consisting ofthese objects by (x, y). The brackets indicate that the objects listed betweenthem are ordered. Thus the expression (x, y) represents the ordered pair of theobjects x and y with x placed first and y placed second. If the objects x andy are distinct then the ordered pair (x, y) is different from the ordered pair(y, x). They are the same only when the objects x and y are the same. Forexample a game between two soccer teams may be represented by an orderedpair in which the team placed first is the home team. Thus an internationalbetween England and Scotland played at Wembley may be represented by thepair (England, Scotland). Similarly, if England won the game by 2 goals to1 the score may also be represented by the ordered pair (2, 1). However, ifScotland won by 2 goals to 1, the score would be represented by the orderedpair (1, 2). Another well known example to students of Mathematics is theordered pair (x, y) of coordinates of a point in a plane relative to particularcoordinate axes drawn in the plane. In the usual orientation of the axes xrepresents the coordinate in the direction of the horizontal (i.e. x) axis and yrepresents the coordinate in the direction of the vertical (i.e. y) axis.

Definition. When considering an ordered pair (x, y), we shall say that:

x is the first element of the ordered pair;y is the second element of the ordered pair.

5.2 Equality of Ordered Pairs

(x, y) and (p, q) are regarded as the same ordered pair and are thus said to beequal if x and p are the same object (we may write x = p) and y and q arethe same object (y = q). If (x, y) and (p, q) are equal we write (x, y) = (p, q).Thus (x, y) = (p, q) if and only if x = p and y = q. If the objects u and v arenot the same we say that they are not equal and write u 6= v. In particular(x, y) 6= (p, q) if and only if x 6= p or y 6= q. Note that the justification for this

78

Page 84: Logic and Discrete Mathematics

statement is purely logical:

(x, y) 6= (p, q) WV ¬((x, y) = (p, q))WV ¬(x = p ∧ y = q)WV ¬x = p ∨ ¬y = q

WV x 6= p ∨ y 6= q.

5.3 Cartesian Product of Sets

Let A and B be sets. Then the set of all ordered pairs (x, y) with x ∈ A andy ∈ B is called the Cartesian product of A and B and is denoted by A×B. Forexample suppose that A = {f, g} and B = {p, q, r}. Then:

A×B = {(f, p), (f, q), (f, r), (g, p), (g, q), (g, r)}.

Note that, since #A = 2 , #B = 3 and #(A×B) = 6:

#(A×B) = #A×#B.

This equation holds in general for finite sets. For if #A = m and #B = n, then,for each x ∈ A, there exist n different pairs of the form (x, y) with y ∈ B (one forevery such y). Hence there are mn different pairs in A×B; i.e. #(A×B) = mn.

5.4 Relations

Let A be the set of all students in a certain university and let B be the setof all subjects taught in that university. Consider the relationship between astudent at the university and the subjects which the student studies at theuniversity. This relationship may be described by collecting together all thepairs (x, y) in A × B where x is a student and y is a subject which the stu-dent studies. Since not all students usually study all subjects the collection ofall such pairs will form a subset R of A × B. The subset R characterizes therelationship. For example, if John is a student of the university and he stud-ies Mathematics and Computer Science, but not Statistics, then the orderedpairs (John,Mathematics) and (John,Computer Science) belong to R, but not(John,Statistics), which nevertheless belongs to A×B. Only the pairs in A×Bwhich bear the relationship belong to R.

More generally a relation between a set A and a set B is a subset of A×B.Note that if A and B are distinct sets then A × B is different from B × A.Thus a relation between A and B need not be a relation between B and A. Inthe example considered in the previous paragraph the relationship of subject tostudent who studies that subject is different from the relationship of student tosubject which the student studies. Similarly the relationship of natural fatherto daughter is different from the relationship of daughter to natural father. Afather may have more than one daughter, but a daughter has precisely onefather. In the relationship of daughter to natural father, we may regard thedaughter as the ‘subject’ of the relationship and the father as the ‘object’ of therelationship.

79

Page 85: Logic and Discrete Mathematics

We may express the fact that R is a relation between the set A and theset B in other ways. Because R is a subset of A × B, it is a member of thepower set P(A×B); i.e. it is an object of ‘type’ P(A×B). Thus we may writeR : P(A × B) for the statement that R is a relation between A and B. Anequivalent ‘functional’ notation is:

R : A ↔ B.

This function notation provides an alternative to the ordered pair (x, y):

x 7→ y,

which reads “x maps to (or into) y”. Thus the statement which asserts that,under the relation R, x maps to y is equivalent to the statement that (x, y) ∈ R.If (x, y) ∈ R, we may also say that x is R-related to y. Thus a relation R betweensets A and B may be regarded as a binary predicate in predicate logic and hencewe may use the notation R(x, y) or xRy to mean that “x is R-related to y”. Inthis interpretation x is an object of type A and y is an object of type B andthe proposition R(x, y) (or xRy) is true if and only if (x, y) ∈ R. Converselya binary predicate D(x, y) which governs objects x of type A and objects y oftype B may be regarded as a relation D between A and B such that (x, y) ∈ Dif and only if D(x, y) is true.

5.5 Relations on a Set

Let A be a set. Then a relation R on A is a subset of A × A; i.e. a relationbetween A and A. For example, let A = {1, 2, 3, 4, 5}. Then:

R = {(1, 2), (1, 3), (1, 5), (2, 3), (4, 2), (4, 4), (5, 2)}= {1 7→ 2, 1 7→ 3, 1 7→ 5, 2 7→ 3, 4 7→ 2, 4 7→ 4, 5 7→ 2}

is a relation on A.Again for example a relation R on a set A may be regarded as equivalent to a

binary predicate R(x, y) or xRy which governs objects x, y of type A. (x, y) ∈ Rif and only if R(x, y) is true. For example, the binary predicate < which governsobjects of type R is a relation on R. As a relation < is the subset of R × Rconsisting of all pairs (x, y) of real numbers such that x < y.

An important relation on a set A is the relation I defined by:

I = {(x, y) • x, y : A | x = y}.

This relation is called the identity relation on A. Note that, if x and y areelements of A, then (x, y) ∈ I if and only if x = y. We usually denote theidentity relation on a set A by idA.

As is the practice of using a word or word combination to denote a setor a predicate, we may use them to denote relations. For example the set ofall students in a particular university might be denoted by the word Studentand the set of subjects taught in that university might be denoted by the wordSubject. Then the relation of student to subject which the student studies mightbe denoted by the word studies. More precisely we write:

studies : Student ↔ Subject.

80

Page 86: Logic and Discrete Mathematics

The statement that John studies Mathematics would be expressed by sayingthat (John,Mathematics) ∈ studies, or by writing John studies Mathematics.Similarly the relation of one person being the parent of another may be denotedby:

is-parent-of : Person ↔ Person,

where Person denotes the set of all people. The statement that John is parentof Mary may be expressed in the form:

(John,Mary) ∈ is− parent− of,

or:John is-parent-of Mary.

5.6 Domain and Range of a Relation

If R is a relation between the sets A and B, the set:

{x : A | (∃y : B • (x, y) ∈ R)}

is called the domain of R and is denoted by dom R, and the set:

{y : B | (∃x : A • (x, y) ∈ R)}

is called the range of R and is denoted by ranR. Thus an object belongs todom R if and only if it is the first element of at least one ordered pair whichbelongs to R, and an object belongs to ranR if and only if it is the secondelement of at least one ordered pair which belongs to R.

Example. Suppose that a small private ‘university’ has just 6 students named:

Alice, Bill, John, Mary, Ted and Anne

and offers courses in just 7 subjects; namely:

Geography, History, Mathematics, Physics, Chemistry, French andGerman.

Suppose that A is the set of students and B is the set of subjects. Suppose thatthe subjects studied by each student are as follows:

Alice studies Mathematics, Physics and Chemistry.Bill studies History and Mathematics.John studies no subject.Mary studies French, German and History.Ted studies only Physics.Anne studies no subject.

Suppose that R : A ↔ B is the relation which tells us which students studywhich subjects. Thus:

R = {(Alice,Mathematics), (Alice,Physics), (Alice,Chemistry)(Bill,History), (Bill,Mathematics), (Mary,French)(Mary,German), (Mary,History), (Ted,Physics)}.

81

Page 87: Logic and Discrete Mathematics

Then domR is the set:{Alice,Bill,Mary,Ted},

because Alice, Bill, Mary and Ted are the ‘objects’ which are placed first in atleast one ordered pair belonging to R. Similarly ranR is the set:

{Mathematics,Physics,Chemistry,History,French,German},

since Mathematics, Physics, Chemistry, History, French and German are placedsecond in at least one ordered pair contained in R. Note that there are twoelements of A which are not in dom R; namely John and Anne. There is justone element of B which is not in ranR; namely Geography.

5.7 The Inverse of a Relation

Consider the relation R of student to subject as given in the previous example.We may reverse the roles of student and subject in this relation to obtain therelation that specifies which subject is studied by which student. We denotethis relation by R∼ : B ↔ A. Thus:

R∼ = {(Mathematics,Alice), (Physics,Alice), (Chemistry,Alice)(History,Bill), (Mathematics,Bill), (French,Mary)(German,Mary), (History,Mary), (Physics,Ted)}.

R∼ is called the inverse of R. Note that dom R∼ = ranR and ran R∼ = dom R.For:

dom R∼ = {Mathematics,Physics,Chemistry,History,French,German}= ranR;

ranR∼ = {Alice, Bill, Mary, Ted} = dom R.

In general, if R : A ↔ B is a relation, then the inverse of R is the relationR∼ : B ↔ A defined by the rule that, if x ∈ A and y ∈ B, then:

(y, x) ∈ R∼ if and only if (x, y) ∈ R.

(i.e. y is R∼-related to x if and only if x is R-related to y) and:

dom R∼ = ranR; ranR∼ = dom R.

For:

y ∈ dom R∼ WV y ∈ B ∧ ∃x : A • (y, x) ∈ R∼

WV y ∈ B ∧ ∃x : A • (x, y) ∈ R

WV y ∈ ranR,

and:

x ∈ ranR∼ WV x ∈ A ∧ ∃y : B • (y, x) ∈ R∼

WV x ∈ A ∧ ∃y : B • (x, y) ∈ R

WV x ∈ dom R.

82

Page 88: Logic and Discrete Mathematics

5.8 Relational Image

Let R : A ↔ B be a relation and let E be a subset of A. Then R(|E|) denotesthe set of those elements of B to which at least one element of E is R-related.Thus with each subset E of A we associate a subset R(|E|) of B. Note that, forany y ∈ B, y ∈ R(|E|) if and only if there exists x ∈ E such that (x, y) ∈ R.R(|E|) is called the relational image of E through R or the R-image of E.

Example. Let A = {1, 2, 3, 4, 5, 6, 7, 8} and let B = {a, b, c, d, e, f, g, h, k}, wherea, b, c, d, e, f, g, h, k are distinct objects. Suppose that the relation R : A ↔ B isgiven by:

R = {(1, d), (2, b), (2, g), (3, e), (3, h), (5, d), (5, e), (5, k),(6, a), (6, b), (6, g), (6, k), (8, e), (8, h), (8, k)}.

Suppose that E is the subset {3, 5, 7, 8} of A. Then:

no element of E is R-related to a;no element of E is R-related to b;no element of E is R-related to c;the element 5 of E is R-related to d, since (5, d) ∈ R;the elements 3, 5, 8 of E are R-related to e, since (3, e), (5, e), (8, e) ∈ R;no element of E is R-related to f ;no element of E is R-related to g;the elements 3, 8 of E are R-related to h, since (3, h), (8, h) ∈ R;the elements 5, 8 of E are R-related to k, since (5, k), (8, k) ∈ R.

It follows that {d, e, h, k} is the set of all elements of B to which at least oneelement of E is R-related. Thus:

R(|E|) = {d, e, h, k}.

Similarly with any subset F of B we may associate the subset R∼(|F |)ofA. Then, if x ∈ A, x ∈ R∼(|F |) if and only if there exists y ∈ F such that(y, x) ∈ R∼; i.e. such that (x, y) ∈ R.

Example. Let R : A ↔ B be the relation as defined in the previous example.Let F = {a, b, c, g, h}. Then:

1 is not R-related to any element of F ;2 is R-related to the elements b, g of F , since (2, b), (2, g) ∈ R;3 is R-related to the element h of F , since (3, h) ∈ R;4 is not R-related to any element of F ;5 is not R-related to any element of F ;6 is R-related to the elements a, b, g of F , since (6, a), (6, b), (6, g) ∈ R;7 is not R-related to any element of F ;8 is R-related to the element h of F , since (8, h) ∈ R.

Therefore {2, 3, 6, 8} is the set of all elements of A which are R-related to atleast one element of F . Thus:

R∼(|F |) = {2, 3, 6, 8}.

Note that in answering a question of this type it is not necessary to be asdetailed as we have been in this and the previous example. All that is needed,

83

Page 89: Logic and Discrete Mathematics

for instance to determine R∼(|F |), is to mentally pick out the pairs in R whosesecond element belongs to F and then list without repetitions the first elementsof these pairs.

To recap, if R :↔ B is a relation, E is a subset of A and F is a subset of B,then:

R(|E|) = {y : B | ∃x : E • (x, y) ∈ R};R∼(|F |) = {x : A | ∃y : F • (x, y) ∈ R}.

5.9 Restrictions of Relations

Let R : A ↔ B be a relation, let E be a subset of A and let F be a subset ofB. Then we may define the following subsets of R:

E � R = {(x, y) : R | x ∈ E};E −� R = {(x, y) : R | x 6∈ E};R � F = {(x, y) : R | y ∈ F};R−� F = {(x, y) : R | y 6∈ F}.

Note that, since these are necessarily subsets of A×B, they are relations betweenA and B. Because they are subsets of R, they are called restrictions of R. Morespecifically:

E � R is called the domain restriction of R to E;E −� R is called the domain anti-restriction of R to E;R � F is called the range restriction of R to F ;R−� F is called the range anti-restriction of R to F .

Note that:

E −� R = (A \ E) � R; R−� F = R � (B \ F ).

Example. Let A = {1, 2, 3, 4, 5, 6, 7, 8} and let B = {a, b, c, d, e, f, g, h, k}, wherea, b, c, d, e, f, g, h, k are distinct objects. Suppose that the relation R : A ↔ B isgiven by:

R = {(1, d), (2, b), (2, g), (3, e), (3, h), (5, d), (5, e), (5, k),(6, a), (6, b), (6, g), (6, k), (8, e), (8, h), (8, k)}.

Suppose that E is the subset {3, 5, 7, 8} of A and F is the subset {a, b, c, g, h}of B. Then:

E � R = {(3, e), (3, h), (5, d), (5, e), (5, k), (8, e), (8, h), (8, k)};E −� R = {(1, d), (2, b), (2, g), (6, a), (6, b), (6, g), (6, k)};R � F = {(2, b), (2, g), (3, h), (6, a), (6, b), (6, g), (8, h)};R−� F = {(1, d), (3, e), (5, d), (5, e), (5, k), (6, k), (8, e), (8, k)}.

84

Page 90: Logic and Discrete Mathematics

5.10 Set Operations on Relations

Because relations are sets, we may apply the normal set operations ∪, ∩, \ onrelations. Thus, if R and S are relations between sets A and B, then so areR ∪ S, R ∩ S and R \ S.Example. Suppose that we are conducting a survey of the use of public transportin 1996 by people living in Hampshire. Let H be the set of all people livingin Hampshire and let D be the set of all days in 1996. Let B be the set of allordered pairs (x, y) such that x is a person living in Hampshire and y is a day in1996 on which x traveled by bus. Let T be the set of all ordered pairs (x, y) suchthat x is a person living in Hampshire and y is a day in 1996 on which x traveledby train. Thus B : H ↔ D and T : H ↔ D are relations. Then B ∪ T , B ∩ T ,B \T and T \B are relations between H and D. The ordered pair (x, y) belongsto B ∩ T if and only if (x, y) belongs to B and to T ; i.e. x is a person livingin Hampshire who traveled by both bus and train on the day y in 1996. Nowdom(B∩T ) is the set of all people living in Hampshire who traveled by both busand train on the same day in 1996. Note that dom(B∩T ) ⊆ (dom B)∩(dom T ).These sets need not be the same, since a person living in Hampshire may travelby bus on some day in 1996 and by train on some day in 1996, but not by bothbus and train on the same day in 1996. There are many properties of this kindthat may be investigated .

5.11 Worked Example

Suppose that:

A is the set of all students in the University;B is the set of all books belonging to the University Library;E is the set of all overseas students in the University;F is the set of all works of fiction belonging to the library;R : A ↔ B is the set of all ordered pairs (x, y) such that x is astudent in the university and y is a book which x borrowed from thelibrary during last term;D : A ↔ B is the set of all ordered pairs (x, y) such that x is astudent in the university and y is a book from the library which xdamaged last term.

In the phrases and statements which follow we use, in an obvious way, simplifiedwords or phrases to denote the objects of these sets. Thus, for example, theword ‘book’ refers to a book belonging to the University Library. Using only(some or all of) the symbols:

A, B, D, E, F, R, ∩, \, =, ⊆, (, ),∼, dom, ran, (|, |), �, −�, �, −�, ∅

write down expressions for the following sets and statements:

(a) The set of all ordered pairs (x, y) such that x is a student and y is a bookwhich x borrowed and damaged.

(b) The set of all ordered pairs (x, y) such that x is a student and y is a bookwhich x damaged without borrowing it.

85

Page 91: Logic and Discrete Mathematics

(c) The set of all ordered pairs (x, y) such that x is an overseas student and yis a work of non-fiction which x borrowed.

(d) The set of all works of fiction which were borrowed by at least one overseasstudent.

(e) The set of all students who damaged at least one book without borrowingit.

(f) The set of all books borrowed by students who damaged at least one book.

(g) All works of non-fiction were damaged by students.

(h) Every overseas student borrowed at least one work of fiction.

(i) No book was borrowed by both a home (i.e. non-overseas) student and anoverseas student.

Solution. (a) A student x borrowed a book y if and only if (x, y) ∈ R. Similarlyx damaged y if and only if (x, y) ∈ D. Thus x borrowed and damaged y ifand only if (x, y) ∈ R and (x, y) ∈ D; i.e. (x, y) ∈ R ∩D. Thus R ∩D isthe set of all ordered pairs (x, y) such that x is a student and y is a bookwhich x both borrowed and damaged.

(b) Let x be a student who damaged but did not borrow the book and let y bea book. Then x did not borrow y if and only if (x, y) 6∈ R. Then by thearguments used in part (a) x damaged but did not borrow y if and onlyif (x, y) ∈ D and (x, y) 6∈ R; i.e. (x, y) ∈ D \ R. Thus the required set isD \R.

(c) x is an overseas student and y is a work of non-fiction which x borrowed ifand only if (x, y) ∈ R, x ∈ E and y 6∈ F . There are two ways of combiningthese conditions; either:

(x, y) ∈ R ∧ x ∈ E ∧ y 6∈ F WV ((x, y) ∈ R ∧ x ∈ E) ∧ y 6∈ F

WV (x, y) ∈ E � R ∧ y 6∈ F

WV (x, y) ∈ (E � R)−� F

or:

(x, y) ∈ R ∧ x ∈ E ∧ y 6∈ F WV x ∈ E ∧ ((x, y) ∈ R ∧ y 6∈ F )WV x ∈ E ∧ (x, y) ∈ R−� F

WV (x, y) ∈ E � (R−� F ).

Thus the required set can be expressed as (E � R)−� F or as E � (R−� F ).Note that, in general, these restrictions are the same. Hence we may expressthe set simply as E � R−� F .

(d) y is a book which was borrowed by at least one overseas student if and onlyif there exists x ∈ E such that (x, y) ∈ R; i.e. y ∈ R(|E|). y is a work offiction if and only if y ∈ F . Thus the required set is R(|E|) ∩ F .

86

Page 92: Logic and Discrete Mathematics

(e) From part (b), D \ R is the set of all ordered pairs (x, y) such that x isa student and y is a book which x damaged without borrowing it. Theset of all students who damaged at least one book without borrowing it istherefore the domain of the relation D \R; i.e. the set dom(D \R).

(f) The set of all students who damaged at least one book is clearly the domainof the relation D; i.e. the set dom D. y is a book borrowed by such astudent if and only if there exists x ∈ dom D such that (x, y) ∈ R; i.e.y ∈ R(|dom D|). Thus the required set is R(|dom D|).

(g) The set of all works of non-fiction is B \F . y is a book damaged by at leastone student if and only if there exists x ∈ A such that (x, y) ∈ D; i.e. ifand only if y ∈ ranD. Therefore the set of all books damaged by at leastone student is ranD. The statement asserts that every element of B \ F isan element of ranD; i.e. B \ F ⊆ ranD.

(h) x is a student who borrowed at least one work of fiction if and only if thereexists y ∈ F such that (x, y) ∈ R; i.e. x ∈ R∼(|F |). The statement thereforeasserts that every element in E is an element in R∼(|F |); i.e. E ⊆ R∼(|F |).

(i) y is a book borrowed by an overseas student if and only if there exists x ∈ Esuch that (x, y) ∈ R; i.e. y ∈ R(|E|). Thus the set of all books borrowedby overseas students is R(|E|). Similarly, since the set of home students isA \ E, the set of all books borrowed by home students is R(|A \ E|). Thestatement therefore asserts that R(|E|) ∩R(|A \ E|) = ∅.

5.12 Relational Overriding

A relation (i.e. a set of ordered pairs) might constitute information which is kepton paper or in a computer database or both. For instance a University mustkeep records of which subjects each of its students is studying. This informationmight change and the records must then be altered. Thus the original relationis overridden with new information which therefore transforms it into a newrelation.

Lets take another example. A bookseller’s shop tries to keep records ofpotential customers and the subjects in which they are believed to be interestedso that each customer can be informed of all new books on appropriate subjects.For the sake of simplicity suppose that there are just nine customers calledAnne, Bill, Charlie, Fred, George, Jane, Mary, Sue and Tom kept on record andthat the bookseller retails books on just eight subjects; namely Art, Botany,Chemistry, Gardening, History, Politics, Sport and Travel. Suppose that thebookseller’s records indicate that:

Anne is interested in Botany, Gardening and Travel;Bill is interested in Botany, Gardening and Sport;Fred is interested in Art and Sport;George is interested in Travel;Sue is interested in Gardening and Sport;Tom is interested in Sport.

Let A be the set of all customers and let B be the set of all subjects. Then thebookseller’s records constitute a relation R : A ↔ B. An ordered pair (x, y)

87

Page 93: Logic and Discrete Mathematics

belongs to R if and only if x ∈ A, y ∈ B and the customer x is believed to beinterested in the subject y. Thus:

R = {(Anne, Botany), (Anne, Gardening), (Anne, Travel),(Bill, Botany), (Bill, Gardening), (Bill, Sport),(Fred, Art), (Fred, Sport), (George, Travel),(Sue, Gardening), (Sue, Sport), (Tom, Sport)}.

The bookseller now wishes to update the records and therefore writes to eachcustomer requesting an up-to-date list of the subjects in which he or she isinterested. Only Anne, Charlie, Mary, Sue and Tom reply, stating that:

Anne is interested in Chemistry and Gardening;Charlie is interested in Art, Botany and Chemistry;Mary is interested in Gardening and Travel;Sue is interested in Gardening and Sport;Tom is interested in Art and Travel.

This results in another relation S : A ↔ B. An ordered pair (x, y) belongs toS if and only if x is a customer who sent a reply and y is one of the subjects ofinterest listed in that reply. Thus:

S = {(Anne, Chemistry), (Anne, Gardening), (Charlie, Art),(Charlie, Botany), (Charlie, Chemistry), (Mary, Gardening),(Mary, Travel), (Sue, Gardening), (Sue, Sport),(Tom, Art), (Tom, Travel)}.

Note that dom S = {Anne, Charlie, Mary, Sue, Tom}. The booksellers recordsare amended so that they now contain the set of ordered pairs:

{(Anne, Chemistry), (Anne, Gardening), (Bill, Botany),(Bill, Gardening), (Bill, Sport), (Charlie, Art)(Charlie, Botany), (Charlie, Chemistry), (Fred, Art),(Fred, Sport), (George, Travel), (Mary, Gardening),(Mary, Travel), (Sue, Gardening), (Sue, Sport),(Tom, Art), (Tom, Travel)}.

These records thus form a new relation, denoted by R⊕S, and called the relation“R overridden by S”. Note that the ordered pairs in R⊕ S consist of:

(i) the ordered pairs in S;

(ii) the ordered pairs in R whose first elements are not in dom S.

For example the ordered pair (Fred, Art) belongs to R, but its first element,Fred, is not in domS. Thus (Fred, Art) remains in R⊕ S.

R ⊕ S is obtained from R by removing all pairs (x, y) from R in which thefirst element, x, belongs to dom S and replacing them by the pairs in S. Thuswe may define:

R⊕ S = S ∪ ((dom S)−� R).

This definition applies to any two relations R : A ↔ B and S : A ↔ B betweenthe same sets A and B. Thus (x, y) ∈ R⊕ S if and only if, either (x, y) ∈ S, or(x, y) ∈ R and x 6∈ dom S.

88

Page 94: Logic and Discrete Mathematics

5.13 Worked Example

Let A = {0, 1, 2, 3, 4, 5, 6, 7, 8} and let B = {a, b, c, d, e, f}, where a, b, c, d, e, fare distinct objects. Let R : A ↔ B and S : A ↔ B be the relations given by:

R = {(0, c), (2, a), (2, b), (3, a), (3, c), (3, d), (5, d), (7, d), (7, f)};S = {(2, b), (2, d), (2, f), (4, a), (4, b), (7, a), (8, a), (8, c)}.

Represent the set R⊕S by a list of its elements between braces, with no elementlisted more than once.

Solution. First note that all the pairs in S belong to R⊕ S. Now:

dom S = {2, 4, 7, 8}.

Therefore 0, 1, 3, 5, 6 are the elements of A which are not in dom S. Hence thepairs, (x, y), in R with x 6∈ dom S are:

(0, c), (3, a), (3, c), (3, d), (5, d).

Thus:

R⊕ S = {(0, c), (2, b), (2, d), (2, f), (3, a), (3, c), (3, d),(4, a), (4, b), (5, d), (7, a), (8, a), (8, c)}.

We may list the elements of R⊕S with a simple mental process which considersthe elements of A = {0, 1, 2, 3, 4, 5, 6, 7, 8} in turn. First consider 0. Now 0 6∈dom S and there is only one pair in R with first element 0; namely (0, c). Thuswe put (0, c) in the list. Next we consider 1. There is no pair in either R orS with first element 1. Hence we proceed to the next element 2 of A. Now2 ∈ dom S. Thus we list all the pairs of S with first element 2; namely (2, b),(2, d) and (2, f). Next we consider the element 3 of A. Now 3 6∈ dom S andthere are three pairs in R with first element 3; namely (3, a), (3, c) and (3, d).Thus we add these pairs to the list. We continue in this way until we haveexhausted all the elements of A.

5.14 Composition of Relations

Suppose that A,B,C are sets and R : A ↔ B and S : B ↔ C are relations.Then we can construct a relation R o

9 S : A ↔ C by the rule:

(x, z) ∈ R o9 S if and only if there exists an object y ∈ B such that

(x, y) ∈ R and (y, z) ∈ S or equivalently xRy and ySz.

The relation R o9 S is called the composition of R and S. Note that if (x, z)

belongs to R o9 S, then there exists an element y ∈ B such that (x, y) ∈ R and

(y, z) ∈ S. In particular y ∈ ranR and y ∈ dom S. Thus y ∈ ranR ∩ dom S.Conversely, if y ∈ ranR∩ dom S, then (x, z) ∈ R o

9 S if x is R-related to y and yis S-related to z. Thus to determine the pairs (x, z) in R o

9 S, we first determinethe set ranR∩dom S and then for each element y in this set determine all pairs(x, z) such that x is R-related to y and y is S-related to z.

89

Page 95: Logic and Discrete Mathematics

Example. Let:

A = {1, 2, 3, 4, 5, 6},B = {a, b, c, d, e, f, g, h}C = {i, j, k, l, m, n},

where a, b, c, d, e, f, g, h, i, j, k, l,m, n are distinct objects. Let R : A ↔ B andS : B ↔ C be relations given by:

R = {(1, a), (1, b), (1, c), (1, e), (2, a), (3, b), (3, c), (5, c), (5, f), (5, h)};S = {(a, j), (b, i), (b, j), (c, j), (c, l), (c,m), (d, l), (d, m), (e,m), (e, n), (h, n)}.

Then:

ranR = {a, b, c, e, f, h};dom S = {a, b, c, d, e, h}.

Hence:ranR ∩ dom S = {a, b, c, e, h}.

Consider the element a. Then the elements 1, 2 are R-related to a and a is onlyS-related to the element j. Thus the pairs (1, j), (2, j) are in Ro

9S. Next 1, 3, areR-related to b and b is S-related to the objects i, j. Thus (1, i), (1, j), (3, i), (3, j)are in R o

9 S. Note that (1, j) is already a member of R o9 S; we only count it

once. This means that we have found 5 elements of R o9 S at this stage. Now

1, 3, 5 are R-related to c and c is S-related to j, l,m. Thus the pairs:

(1, j), (1, l), (1,m), (3, j), (3, l), (3,m), (5, j), (5, l), (5,m)

are all in R o9 S. Next 1 is the only element R-related to e and e is S-related to

the elements m,n. Thus the pairs (1,m), (1, n) are objects of R o9 S. Finally 5

is the only element R-related to h and h is S-related to n. Thus (5, n) belongsto R o

9 S. Therefore collecting all the pairs of R o9 S together:

R o9 S = {(1, i), (1, j), (1, l), (1,m), (1, n), (2, j), (3, i),

(3, j), (3, l), (3,m), (5, j), (5, l), (5,m), (5, n)}.

Alternatively, we may write down the elements of A which are R-related toobjects in dom S; in this case: 1, 2, 3, 5. Then we proceed as follows:

Since (1, a) ∈ R and (a, j) ∈ S, (1, j) ∈ R o9 S;

Since (1, b) ∈ R and (b, i) ∈ S, (1, i) ∈ R o9 S;

Since (1, b) ∈ R and (b, j) ∈ S, (1, j) ∈ R o9 S;

Since (1, c) ∈ R and (c, j) ∈ S, (1, j) ∈ R o9 S;

Since (1, c) ∈ R and (c, l) ∈ S, (1, l) ∈ R o9 S;

Since (1, c) ∈ R and (c,m) ∈ S, (1,m) ∈ R o9 S;

Since (1, e) ∈ R and (e,m) ∈ S, (1,m) ∈ R o9 S;

Since (1, e) ∈ R and (e, n) ∈ S, (1, n) ∈ R o9 S;

Since (2, a) ∈ R and (a, j) ∈ S, (2, j) ∈ R o9 S;

Since (3, b) ∈ R and (b, i) ∈ S, (3, i) ∈ R o9 S;

90

Page 96: Logic and Discrete Mathematics

Since (3, b) ∈ R and (b, j) ∈ S, (3, j) ∈ R o9 S;

Since (3, c) ∈ R and (c, j) ∈ S, (3, j) ∈ R o9 S;

Since (3, c) ∈ R and (c, l) ∈ S, (3, l) ∈ R o9 S;

Since (3, c) ∈ R and (c,m) ∈ S, (3,m) ∈ R o9 S;

Since (5, c) ∈ R and (c, j) ∈ S, (5, j) ∈ R o9 S;

Since (5, c) ∈ R and (c, l) ∈ S, (5, l) ∈ R o9 S;

Since (5, c) ∈ R and (c,m) ∈ S, (5,m) ∈ R o9 S;

Since (5, h) ∈ R and (h, n) ∈ S, (5, n) ∈ R o9 S.

Then listing these pairs without repetition we obtain the same set R o9 S.

Example. Let A be the set of all students in the University, B be the set ofall courses taught in the University in the academic year 1996/97 and let Cbe all the days of that year. Suppose that R : A ↔ B be the relation whichtells us which student is taking which course and let S : B ↔ C be the re-lation which tells us which course has a lecture on which day. Suppose thatJohn takes the course Discrete Mathematics and that there is a lecture in Dis-crete Mathematics on January 20. Then (John,Discrete Mathematics) ∈ Rand (Discrete Mathematics, January 20) ∈ S. Then (John, January 20) ∈ R o

9 S.This relationship asserts that John has a lecture on January 20. Thus therelation R o

9 S : A ↔ C tells us which students take lectures on which days.Example. Let A be the set of all customers of a particular bookseller and letB be the set of all subjects of the books on sale by the bookseller. Let R :A ↔ B be the relation which indicates which customers are interested in whichsubjects. For example suppose that John is interested in Sport. John is acustomer of the bookseller and Sport is a subject covered by books on saleby the bookseller. Then (John,Sport) ∈ R. Let C be the set of books ina new consignment of books sent to the bookseller and let S : B ↔ C bethe relation which associates with each subject each book in the consignmentwhich is regarded as relevant to that subject. For example, suppose that theconsignment contains a book entitled “The History of Sport”, which is regardedas relevant to both History and Sport. Then (History, “The History of Sport”)and (Sport, “The History of Sport”) both belong to S. Consider the relationR o

9 S : A ↔ B. If the pair (x, z) belongs to this relation, then there exists asubject y such that (x, y) ∈ R and (y, z) ∈ S. Thus x is a customer and x isinterested in subject y and z is a book in the new consignment which is relevantto the subject y. The customer x may therefore wish to consider the book y forpurchase. Therefore the bookseller should inform the customer y that the bookz has now become available.

We will consider later special relations called functions. For such a relationf : A ↔ B any element x ∈ A is f -related to one and only one element y in B.We denote y by f(x). In particular dom R = A. Suppose that R : A ↔ B andS : B ↔ C are functions. Then R o

9 S : A ↔ C is also a function. If x ∈ A,then R(x) ∈ B and S(R(x)) ∈ C. Moreover (R o

9 S)(x) = S(R(x)). It is naturalin the context of functions to use a notation for the composition of R and Swhich keeps the same order as the notation S(R(x)). Indeed the compositionof the two functions R and S is usually denoted by S ◦R. Thus, if x ∈ A, then(S ◦R)(x) = S(R(x)). For this reason the composition of two relations also mayuse this “backwards” or “reverse” notation.

In considering the composition R o9 S : A ↔ C of two relations R : A ↔ B

and S : B ↔ C, the sets A,B,C need not be distinct. In particular, if C = A,

91

Page 97: Logic and Discrete Mathematics

then R o9 S is a relation on A. It follows that the composition of two relations on

a set A is a relation on A. For example, if R : A ↔ A is a relation on A, thenso is the composition R o

9 R.As an operation the composition of relations is associative; i.e. if R : A ↔ B,

S : B ↔ C and T : C ↔ D are relations, then:

(R o9 S) o

9 T = R o9 (S o

9 T ).

For:

(w, z) ∈ (R o9 S) o

9 T WV ∃y : C • (w, y) ∈ R o9 S ∧ (y, z) ∈ T

WV ∃y : C • (∃x : B • (w, x) ∈ R ∧ (x, y) ∈ S) ∧ (y, z) ∈ T

WV ∃y : C;x : B • (w, x) ∈ R ∧ (x, y) ∈ S ∧ (y, z) ∈ T

WV ∃x : B; y : C • (w, x) ∈ R ∧ (x, y) ∈ S ∧ (y, z) ∈ T

WV ∃x : B • (w, x) ∈ R ∧ (∃y : C • (x, y) ∈ S ∧ (y, z) ∈ T

WV ∃x : B • (w, x) ∈ R ∧ (x, z) ∈ S o9 T

WV (x, z) ∈ R o9 (S o

9 T ).

Note that, if R : A ↔ B is a relation, then:

R o9 idB = R = id A o

9 R.

5.15 The Directed Graph of a Relation on a Set

Let R : A ↔ A be a relation on the set A. If x, y ∈ A and (x, y) ∈ R, recall thatwe may write x 7→ y. This suggests that the elements of A be represented bypoints in a diagram with the pairs (x, y) ∈ R represented by arrows which start

at the points x and end at the points y; thus: The points are called

vertices and the arrows are called edges. The complete diagram is called thedirected graph of the relation. Fop example suppose that A = {0, 1, 2, 3, 4, 5, 6}and that R : A ↔ A is the relation on A given by the set:

R = {(0, 1), (0, 4), (0, 5), (1, 2), (1, 4), (2, 0), (2, 2), (2, 5),(3, 1), (3, 4), (4, 3), (6, 0), (6, 3)}.

The directed graph of R consists of seven vertices which represent the objects0, 1, 2, 3, 4, 5, 6 of A and thirteen edges representing the pairs in R. The directedgraph of R therefore may be drawn as follows:

92

Page 98: Logic and Discrete Mathematics

In this directed graph the edge represents the ordered pair (0, 1). The

other ordered pairs of R are represented in a similar way. In particular theordered pair (2, 2) is represented by the vertex 2 and an edge which starts at 2and ends at 2. Such an edge is called a loop. Note that the vertices 3 and 4 arejoined by two edges, one from 3 to 4 and the other in the reverse direction.

We shall regard a directed graph as something which represents a network ofone-way streets, each vertex representing a junction and each edge representinga one-way street from one junction to another. We may only travel along thesestreets in the direction given by the arrowhead. A two-way street is representedby two edges between the same two vertices but with opposite directions. In thedirected graph of the relation R above there is just one two-way street betweenthe junctions 3 and 4. Also in this graph we may move or travel down a singleone-way street from the junction 1 to the junction 4. However we cannot directlymove from 4 to 1 since there is no edge with arrow pointing from 4 to 1. Wemay also move from 2 to 2 along the loop starting at 2 and ending at 2.

5.16 The Relation R2

Let R be a relation on a set A. Then we may form the composition of R : A ↔ Awith R : A ↔ A. This defines the relation R o

9 R : A ↔ A. The relation R o9 R is

usually denoted by R2. Recall that (in this case):

(x, z) ∈ R2 if and only if there exists an object y (belonging to A)such that (x, y) ∈ R and (y, z) ∈ R.

In terms of the directed graph of R this means that there exist two edges asshown in the diagram:

In other words, (x, z) ∈ R2 if and only if we can travel from the junction x tothe junction z along two one-way streets in succession via a single intermediatejunction y.

5.17 Worked Example

Let A = {0, 1, 2, 3, 4, 5, 6} and let the relation R : A ↔ A be given by:

R = {(0, 1), (0, 4), (0, 5), (1, 2), (1, 4), (2, 0), (2, 2), (2, 5),(3, 1), (3, 4), (4, 3), (6, 0), (6, 3)}.

We have already considered this relation and drawn its directed graph. We mayconstruct the relation R2 by observing that:

93

Page 99: Logic and Discrete Mathematics

Since (0, 1) ∈ R and (1, 2) ∈ S, (0, 2) ∈ R2;Since (0, 1) ∈ R and (1, 4) ∈ S, (0, 4) ∈ R2;Since (0, 4) ∈ R and (4, 3) ∈ S, (0, 3) ∈ R2;Since (1, 2) ∈ R and (2, 0) ∈ S, (1, 0) ∈ R2;Since (1, 2) ∈ R and (2, 2) ∈ S, (1, 2) ∈ R2;Since (1, 2) ∈ R and (2, 5) ∈ S, (1, 5) ∈ R2;Since (1, 4) ∈ R and (4, 3) ∈ S, (1, 3) ∈ R2;Since (2, 0) ∈ R and (0, 1) ∈ S, (2, 1) ∈ R2;Since (2, 0) ∈ R and (0, 4) ∈ S, (2, 4) ∈ R2;Since (2, 0) ∈ R and (0, 5) ∈ S, (2, 5) ∈ R2;Since (2, 2) ∈ R and (2, 0) ∈ S, (2, 0) ∈ R2;Since (2, 2) ∈ R and (2, 2) ∈ S, (2, 2) ∈ R2;Since (2, 2) ∈ R and (2, 5) ∈ S, (2, 5) ∈ R2;Since (3, 1) ∈ R and (1, 2) ∈ S, (3, 2) ∈ R2;Since (3, 1) ∈ R and (1, 4) ∈ S, (3, 4) ∈ R2;Since (3, 4) ∈ R and (4, 3) ∈ S, (3, 3) ∈ R2;Since (4, 3) ∈ R and (3, 1) ∈ S, (4, 1) ∈ R2;Since (4, 3) ∈ R and (3, 4) ∈ S, (4, 4) ∈ R2;Since (6, 0) ∈ R and (0, 1) ∈ S, (6, 1) ∈ R2;Since (6, 0) ∈ R and (0, 4) ∈ S, (6, 4) ∈ R2;Since (6, 0) ∈ R and (0, 5) ∈ S, (6, 5) ∈ R2;Since (6, 3) ∈ R and (3, 1) ∈ S, (6, 1) ∈ R2;Since (6, 3) ∈ R and (3, 4) ∈ S, (6, 4) ∈ R2.

Thus:

R2 = {(0, 2), (0, 3), (0, 4), (1, 0), (1, 2), (1, 3), (1, 5), (2, 0), (2, 1), (2, 2), (2, 4),(2, 5), (3, 2), (3, 3), (3, 4), (4, 1), (4, 4), (6, 1), (6, 4), (6, 5)}.

In terms of the graph of R we may note that (0, 3) ∈ R2 because we may travelfrom 0 to 3 along two edges via 4:

Similarly the ordered pair (4, 4) belongs to R2 because we may travel from 4 to

4 along two edges via 3: The pair (1, 2) belongs to R2 because we can

travel from 1 to 2 along two edges in succession; namely along the edge from 1to 2 and then along the loop from 2 to 2:

Similarly the pair (2, 2) belongs to R2 since we may travel from 2 to 2 by moving

twice round the loop . The fact that (6, 4) ∈ R2 may be explained in

94

Page 100: Logic and Discrete Mathematics

two different ways. We may travel form 6 to 4 via 0 using the edges:

or via 3 using the edges: .

5.18 The Relation R3

Let R : A ↔ A be a relation on the set A. Then, since composition of relationsis associative, R2 o

9 R = R o9 R2. We will denote the relation R2 o

9 R by R3. Thus:

(w, z) ∈ R3 if and only if there exist objects x, y such that the pairs(w, x), (x, y) and (y, z) belong to R.

It follows that (x, z) ∈ R3 if and only if in the directed graph of R there threeedges as shown in the diagram:

In other words (w, z) ∈ R3 if and only if we can travel along three successiveedges from x to z.

5.19 Worked Example

Let A = {0, 1, 2, 3, 4, 5, 6} and let R : A ↔ A be the relation as defined above;viz.:

R = {(0, 1), (0, 4), (0, 5), (1, 2), (1, 4), (2, 0), (2, 2), (2, 5),(3, 1), (3, 4), (4, 3), (6, 0), (6, 3)}.

Then:

R2 = {(0, 2), (0, 3), (0, 4), (1, 0), (1, 2), (1, 3), (1, 5), (2, 0), (2, 1), (2, 2), (2, 4),(2, 5), (3, 2), (3, 3), (3, 4), (4, 1), (4, 4), (6, 1), (6, 4), (6, 5)}.

It follows that, by a mental calculation:

R3 = R o9 R2

= {(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (1, 0), (1, 1), (1, 2), (1, 4),(1, 5), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (3, 0), (3, 1), (3, 2),(3, 3), (3, 4), (3, 5), (4, 2), (4, 3), (4, 4), (6, 2), (6, 3), (6, 4)}.

The relation R3 may also be determined from the directed graph of R. (w, z) ∈R3 if and only if we can travel from w to z along three successive edges. Forexample (2, 4) ∈ R3 because we can travel from 2 to 4 via the vertices 0 and 1as shown in the diagram:

95

Page 101: Logic and Discrete Mathematics

Also (6, 3) ∈ R3 as shown in the diagram:

The diagram:

shows that (3, 1) ∈ R3. To see that (1, 5) ∈ R3, note that we may travel from1 to 5 in three “moves”, namely a move from 1 to 2 followed by a move roundthe loop attached to the vertex 2 and finally a move from 2 to 5:

(1, 2) ∈ R3 because we may travel from 1 to 2 along three successive edges;namely along the edge from 1 to 2 followed by journey which goes twice roundthe loop attached to the vertex 2. Similarly, by considering the journey whichgoes three times round the loop attached to the vertex 2, (2, 2) ∈ R3.

5.20 The Relations Rn for a natural number n

Given the relation R : A ↔ A on a set A, we may construct in succession therelations R2, R3, R4, etc. by using the iteration:

Rn+1 = R o9 Rn.

for all natural numbers n ≥ 1. We have already done this for the cases n = 1and n = 2. By convention, we write R0 = idA. Then the above iteration alsoholds for n = 0 and hence is valid for all natural numbers n. Since the operationo9 is associative, we may prove, by induction that, for all natural numbers n:

Rn+1 = Rn o9 R.

For any natural number n, let P (n) be the statement:

Rn+1 = Rn o9 R.

The statement P (0) is clearly true. Assume that P (n) is true for the naturalnumber n. Then:

Rn+1 = Rn o9 R.

96

Page 102: Logic and Discrete Mathematics

Hence:

Rn+2 = R o9 Rn+1

= R o9 (Rn o

9 R)= (R o

9 Rn) o9 R

= Rn+1 o9 R.

Thus P (n + 1) is true. Therefore, by induction P (n) is true for all naturalnumbers n. More generally we may show that for any natural numbers m andn:

Rm o9 Rn = Rm+n = Rn o

9 Rm.

In particular:R4 = R o

9 R3 = R2 o9 R2.

It follows that (v, z) ∈ R4 if and only if we can travel from v to z in four movesin the directed graph of R; thus:

For example, if R is the relation on A = {0, 1, 2, 3, 4, 5, 6} with directed graph:

then from the following extract:

we see that (6, 3) ∈ R4.To construct Rn for large values of n, we do not need to evaluate all smaller

“powers” of R. For instance we may determine R5 from R2 and R3; thusR5 = R2 o

9 R3. Then, for example, R10 = R5 o9 R5 and R15 = R5 o

9 R10.We may consider negative powers of a relation R, by defining, for every

positive integer n, R−n = (R∼)n. Then, in particular, R−1 = R∼. One word ofwarning; the rule:

Rm+n = Rm o9 Rn

is NOT valid for all integers m,n. For instance:

R1 o9 R−1 6= R0.

97

Page 103: Logic and Discrete Mathematics

For example, consider the relation R : A ↔ A as defined above; viz.:

R = {(0, 1), (0, 4), (0, 5), (1, 2), (1, 4), (2, 0), (2, 2), (2, 5),(3, 1), (3, 4), (4, 3), (6, 0), (6, 3)},

where A = {0, 1, 2, 3, 4, 5, 6}. Then:

R−1 = R∼

= {(0, 2), (0, 6), (1, 0), (1, 3), (2, 1), (2, 2), (3, 4), (3, 6),(4, 0), (4, 1), (4, 3), (5, 0), (5, 2)}.

Hence:

R o9 R−1 = {(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (2, 0), (2, 1),

(2, 2), (2, 6), (3, 0), (3, 1), (3, 3), (4, 4), (6, 2), (6, 4), (6, 6)}.

Thus R o9 R−1 6= id A; i.e. R1 o

9 R−1 6= R0.

5.21 Non-Mathematical Example

Let Person be the set of all people (living or dead), and let parent-of : Person ↔Person be the set of all ordered pairs (x, y), where x and y are people and xis a parent of y. Then we may construct further relations on the set Person,by forming all positive powers of parent-of. In particular the relation parent-of2

consists of all ordered pairs (x, z), where x and z are people and x is a grandpar-ent of z. For (x, z) ∈ parent-of2 if and only if there exists an object y in Personsuch that (x, y and (y, z) belong to parent-of. Thus x is a parent of y and y isa parent of z. Therefore x is a grandparent of z. Similarly (w, z) ∈ parent-of3

if and only if w and z are people and w is a great grandparent of z. Thus wemay write:

parent-of2 = grandparent-of,

and:parent-of3 = great-grandparent-of,

and so on.

98

Page 104: Logic and Discrete Mathematics

5.22 Properties of Relations

A relation R on a set A is said to be:

(i) reflexive if:∀x : A • xRx;

(ii) symmetric if:∀x, y : A • xRy =⇒ yRx;

(iii) transitive if:∀x, y, z : A • xRy ∧ yRz =⇒ xRz.

A relation R on A fails to be reflexive, if there exists an element x ∈ A suchthat (x, x) 6∈ R. For:

¬∀x : A • xRx WV ∃x : A • ¬xRx

WV ∃x : A • ¬(x, x) ∈ A

WV ∃x : A • (x, x) 6∈ R.

Similarly:

¬∀x, y : A • xRy =⇒ yRx WV ∃x, y : A • ¬(xRy =⇒ yRx)WV ∃x, y : A • ¬(¬(x, y) ∈ R ∨ (y, x) ∈ R)WV ∃x, y : A • (x, y) ∈ R ∧ (y, x) 6∈ R.

Thus R is not symmetric if there exist elements x, y of A such that (x, y) belongsto R but not (y, x). By negating this statement, we observe that R is symmetricif there do not exist elements x, y of A such that (x, y) ∈ R, but (y, x) 6∈ R. Asimilar argument on the definition of transitivity, yields the statement: R is nottransitive if there exist elements x, y, z of A such that (x, y) and (y, z) belongto R, but not (x, z). Thus R is transitive if there do not exist elements x, y, zof A such that (x, y) and (y, z) belong to R, but not (x, z).

Consider the relation R on A = {1, 2, 3, 4, 5, 6} given by:

R = {(1, 1), (1, 2), (2, 1), (2, 2), (2, 5), (3, 3),(4, 2), (4, 4), (5, 2), (5, 5), },

This relation is not reflexive, since there exists the element 6 of A such that(6, 6) 6∈ R. The relation is not symmetric, since there exist the elements 2, 4 ofA such that (4, 2) ∈ R, but not (2, 4). Again the relation is not transitive, sincethere exist the elements 1, 2, 5 of A such that (1, 2) and (2, 5) belong to R, butnot (1, 5).

Example. Given a relation R on a set A, R may be reflexive or it may notbe reflexive. Thus relative to the condition of being reflexive, there are twopossibilities. Similarly there are two possibilities regarding the conditions ofsymmetry and transitivity. Then, with regard to all three conditions, there are23 = 8 different cases. Let us construct an example for each of these cases withA = {1, 2, 3}.

For the relation R to be reflexive we need the pairs (1, 1), (2, 2), (3, 3) to bein R. With just these pairs in R, the relation is also symmetric and transitive.

99

Page 105: Logic and Discrete Mathematics

Suppose that we require R to be reflexive and transitive, but not symmetric.For the relation not to be symmetric there exists elements x, y of A such that(x, y) ∈ R, but not (y, x). In particular x 6= y. Let us suppose that (1, 2) ∈ R,but not (2, 1). Thus the relation:

R = {(1, 1), (1, 2), (2, 2), (3, 3)}

is reflexive, but not symmetric. It is also transitive, since there do not existelements x, y, z of A such that (x, y) and (y, z) belong to R, but not (x, z).

Suppose that R is reflexive and symmetric, but not transitive. Then Rcontains the pairs (1, 1), (2, 2), (3, 3). For R not to be transitive we requireelements x, y, z of A such that (x, y) and (y, z) belong to R, but not (x, z). Wemay suppose, for instance, that (1, 2) and (2, 3) belong to R, but not (1, 3).However, for R to be symmetric, the pairs (2, 1) and (3, 2) must belong to R.Thus:

{(1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 2)} ⊆ R.

It is easy to see that the relation {(1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 2)} isreflexive and symmetric, but not transitive. Therefore we may choose:

R = {(1, 1), (1, 2), (2, 1), (2, 2), (2, 3), (3, 2)}.

Next suppose that R is reflexive, but not symmetric nor transitive. Then asabove, since R is reflexive, but not transitive:

{(1, 1), (1, 2), (2, 2), (2, 3), (3, 3)} ⊆ R.

It suffices to take:

R = {(1, 1), (1, 2), (2, 2), (2, 3), (3, 3)},

since this relation cannot also be symmetric.For R not to be reflexive there exists an element x of A such that (x, x) 6∈ R.

Simple arguments as above lead to the following examples:

R = {(1, 1)} is symmetric and transitive, but not reflexive.R = {(1, 2), (2, 1)} is symmetric, but not reflexive nor transitive.R = {(1, 2)} is transitive, but not reflexive nor symmetric.R = {(1, 2), (2, 3)} is not reflexive nor symmetric nor transitive.

Given a relation R on a set A, we may ascertain by just looking at thedirected graph of R whether the relation is reflexive or symmetric. For instance,if A = {1, 2, 3, 4, 5} and the relation R : A ↔ A is given by:

R = {(1, 1), (1, 2), (1, 3), (2, 2), (3, 2), (3, 3), (3, 5), (4, 4)(4, 5), (5, 1), (5, 3), (5, 5)},

then the directed graph of R is:

100

Page 106: Logic and Discrete Mathematics

In this case R is reflexive, since a loop is attached to each vertex. For a relationto be symmetric there cannot be a one-way street between two junctions in itsgraph. In this case R cannot be symmetric, since its graph contains a one-waystreet joining the junctions 1 and 2. In other words the pair (1, 2) belongs to Rbut not the pair (2, 1).

Consider the relation R : A ↔ A, where A = {1, 2, 3, 4, 5} and:

R = {(1, 1), (1, 2), (1, 4), (2, 1), (2, 2), (3, 3), (3, 4), (4, 1)(4, 2), (5, 4), (5, 5)}.

Its directed graph is:

Since no loop is attached to the vertex 4, R is not reflexive. It is not symmetric,since its graph contains the one-way street from the junction 3 to the junction4.

Consider the set:

A = {Aldershot, Basingstoke, Maidenhead,

Reading, Oxford, Windsor}.

and let R : A ↔ A be the relation on A with directed graph given by:

101

Page 107: Logic and Discrete Mathematics

Then R is not reflexive, since there is no loop attached to the vertex ‘Reading’.R is not symmetric since its graph contains a one-way street from ‘Reading’to ‘Basingstoke’. In the graph one cannot travel directly from ‘Basingstoke’ to‘Reading’. Note that it takes a journey along at least two streets to travel from‘Basingstoke’ to ‘Reading’. For instance we may journey from ‘Basingstoke’ to‘Reading’ via ‘Oxford’. If on the other hand the graph of R is:

then R is symmetric; there is no one-way street. The relation is still not reflexive,since there is no loop attached to the vertex ‘Oxford’.

It is more difficult to determine whether a relation is transitive by just look-ing at its graph. Suppose that R : A ↔ A is a relation on a set A. Then in termsof its graph R is transitive if and only if its graph has the following property:

Whenever a journey from one junction to another may be traveledalong two streets in succession it may be traveled directly along justone street.

The previous relation is not transitive, since we can travel from ‘Reading’ to‘Oxford’ via ‘Maidenhead’, but we cannot go directly from ‘Reading’ to ‘Oxford’.In other words the pairs:

(Reading,Maidenhead), (Maidenhead,Oxford)

belong to R, but the pair (Reading,Oxford) does not. However the directedgraph:

represents a transitive relation on the set:

{Sunday,Monday, Tuesday, WednesdayThursday, Friday, Saturday}.

102

Page 108: Logic and Discrete Mathematics

It is easy to see that in this graph any journey from one junction to anotheralong two streets in succession may also be performed directly along just onestreet. Note that in the graph of a transitive relation, whenever there is atwo-way street, then a loop is attached to each of the two junctions joined bythe street. In the above graph there is a two-way street joining the junctions‘Friday’ and ‘Saturday’. To each of these junctions is attached a loop. If wewere to remove the loop at the junction ‘Saturday’, we would obtain the graph:

of a relation which is not transitive. Although we may travel from ‘Saturday’ to‘Saturday’ along two streets in succession (via ‘Friday’) we can no longer makethe journey along just one street; i.e. a loop attached to the junction ‘Saturday’.

There are many other contexts in which we may consider relations with oneor more of the properties: reflexive, symmetric and transitive. For instance,let P be the set of all people and suppose that R is the relation on P whichrelates two people with an account at the same bank. Thus, if x, y are twopeople, then we write xRy if and only if x has an account at the same bankas y. R need not be reflexive, since not all people have bank accounts. It iscertainly symmetric. Again it need not be transitive, since some people havebank accounts at two different banks. For example a person x may have a bankaccount at Barclays Bank only, a person y may have accounts at both BarclaysBank and Lloyd’s Bank, and a person z may have an account at Lloyds Bankonly. Then (x, y) ∈ R and (y, z) ∈ R, but (x, z) 6∈ R.

5.23 Partitions of a Set

Let A be a set. Then a set of non-empty subsets of A is called a partition ofA if each element of A belongs to exactly one of these subsets. For example, ifA = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, then:

{{0, 2, 4}, {1, 3}, {5, 6, 8, 9}, {7}}

is a partition of A. On the other hand:

{{0, 2, 4}, {1, 3}, {5, 6, 8, 9}, {3, 7}}

is not a partition of A, since, although each element of A belongs to one of thesesubsets, the element 3 belongs to two of them; namely {1, 3} and {3, 7}. Also:

{{0, 2, 4}, {1, 3}, {5, 6, 8, 9}}

103

Page 109: Logic and Discrete Mathematics

is not a partition of A, since the element 7 does not belong to any of the subsetslisted. Note that a set of subsets of A is a partition of A if and only if theirunion is the set A and the intersection of any two distinct subsets of the set isempty; i.e. the subsets are disjoint. Thus a partition of A splits or “partitions”A into disjoint parts. For example we may partition the set P of all pieces in achess set into the set W of all white pieces and the set B of all black pieces; i.e.the set {W,B} is a partition of P . Similarly a deck of cards may be partitionedinto the 4 different ‘suits’; viz. clubs, diamonds, hearts and spades. Thus, if Cis the set of cards bearing clubs, D is the set of all cards bearing diamonds, His the set of all cards bearing hearts and S is the set of all cards bearing spades,then {C, D, H, S} is a partition of set A of all cards in the deck.

5.24 Equivalence Relations

A relation R on a set A is said to be an equivalence relation on A if it is reflexive,symmetric and transitive. For example let A = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} andsuppose that the relation R on A is given by:

R = {(0, 0), (0, 2), (0, 4), (1, 1), (1, 3), (2, 0), (2, 4), (3, 1),(3, 3), (4, 0), (4, 2), (4, 4), (5, 5), (5, 6), (5, 8), (5, 9),(6, 5), (6, 6), (6, 8), (6, 9), (7, 7), (8, 5), (8, 6),(8, 8), (8, 9), (9, 5), (9, 6), (9, 8), (9, 9)}.

It is easy to see that R is reflexive and symmetric. Its graph is:

Note that a loop is attached to each vertex and all streets are two-way. By acloser investigation it can be seen that R is also transitive. Observe from thegraph that the set A may be partitioned into 4 subsets:

{{0, 2, 4}, {1, 3}, {5, 6, 8, 9}, {7}}.

Note that elements x and y of A belong to the same subset if and only if(x, y) ∈ R. In other words x and y belong to the same subset if and only ifwe can travel along a street from x to y. We may prove that this is a propertyof all equivalence relations. The subsets in the partition are called equivalenceclasses.

104

Page 110: Logic and Discrete Mathematics

Let R be an equivalence relation on a set A. Let x ∈ A. Define:

[x] = {y : A | (x, y) ∈ R}.

Then for all elements x of A [x] is a subset of A. Since R is reflexive, (x, x) ∈ Rfor every element x of A. Thus x ∈ [x] for every x in A. Therefore, if P denotesthe set of all subsets of A of the form [x] for some x in A, every element of Abelongs to at least one of the subsets contained in P . We claim that distinctsubsets X and Y in P are disjoint; i.e. X ∩ Y = ∅. Assume that X and Yare distinct subsets of A in P and that z ∈ X ∩ Y . Suppose that X = [x]and Y = [y] for some x, y ∈ A. Then, since z ∈ X = [x] and z ∈ Y = [y],(x, z) ∈ R and (y, z) ∈ R. Since R is symmetric, (z, y) ∈ R. Hence, since Ris transitive, (x, y) ∈ R. Since R is symmetric, (y, x) ∈ R. If w ∈ X = [x],then (x, w) ∈ R and hence, since R is transitive and (y, x) ∈ R, (y, w) ∈ R.Thus w ∈ [y] = Y . Hence X ⊆ Y . Since (x, y) ∈ R, a similar argument showsthat Y ⊆ X. Therefore X = Y . This is a contradiction, since we assumed thatX and Y are distinct. It follows that distinct subsets of A in P are disjoint.Therefore P is a partition of A. The subsets in P are called equivalence classesof R.

Let P be a partition of A. Define the relation RP on A so that, if x, y ∈ A,then (x, y) ∈ RP if and only if x and y belong to the same subset of A in P .It is easy to show that RP is an equivalence relation and that P is the set ofequivalence classes of RP . We may also prove that, if P is the set of equivalenceclasses of an equivalence relation R on a set A, then RP = R. Thereforeequivalence relations on a set A may be regarded as partitions of the set A andconversely. They represent different points of view of the same concept.

Partitions occur naturally in many situations in which objects are classified.For example, the books in a library are classified by subject matter. They aregiven an appropriate class number. Books belonging to the same class are giventhe same class number. The set of books in the library is therefore partitionedinto subsets of books with the same class number. Two books are related if theyhave the same class number. This relation is an equivalence relation.

5.25 Worked Example

Let A = {a, b, c, d, e, f, g, h}, where a, b, c, d, e, f, g, h are distinct objects. LetR,S, T be the relations on A given by:

R = {a 7→ a, b 7→ b, c 7→ c, c 7→ g, c 7→ h, d 7→ d,

e 7→ c, e 7→ e, e 7→ g, e 7→ h, f 7→ f, g 7→ c,

g 7→ g, g 7→ h, h 7→ c, h 7→ g, h 7→ h};S = {a 7→ a, a 7→ b, a 7→ d, a 7→ h, b 7→ a, b 7→ b,

b 7→ d, b 7→ h, c 7→ c, c 7→ e, c 7→ g, d 7→ a

d 7→ b, d 7→ d, d 7→ h, e 7→ c, e 7→ e, g 7→ c,

g 7→ g, h 7→ a, h 7→ b, h 7→ d, h 7→ h};T = {a 7→ b, a 7→ c, a 7→ d, a 7→ e}.

Answer the following questions, and justify each negative answer:

105

Page 111: Logic and Discrete Mathematics

(i) Is R reflexive?

(ii) Is R symmetric?

(iii) Is R transitive?

(iv) Is R an equivalence relation?

(v) Is S reflexive?

(vi) Is S symmetric?

(vii) Is S transitive?

(viii) Is S an equivalence relation?

(ix) Is T reflexive?

(x) Is T symmetric?

(xi) Is T transitive?

(xii) Is T an equivalence relation?

Solution. [1] Yes.

[2] No. Since(e, c) ∈ R but (c, e) 6∈ R, R is not symmetric.

[3] Yes.

[4] No. R is not an equivalence relation since it is not symmetric.

[5] No. Since (f, f) 6∈ S, S is not reflexive.

[6] Yes.

[7] No. Since (e, c) ∈ S and (c, g) ∈ S, but (e, g) 6∈ S, S is not transitive.

[8] No. S is not an equivalence relation since it is not reflexive.

[9] No. Since (a, a) 6∈ T , T is not reflexive.

[10] No. Since (a, b) ∈ T , but (b, a) 6∈ T , T is not symmetric.

[11] Yes.

[12] No. T is not an equivalence relation since it is not reflexive.Remark. It is easy to check when a relation is reflexive and symmetric, but notso easy to deal with transitivity. Note that a relation R on a set A is transitiveif and only if R o

9 R ⊆ R. For, if R is transitive and (x, z) ∈ R o9 R, then there

exists an object y in A such that (x, y) ∈ R and (y, z) ∈ R and hence (x, z) ∈ R.Conversely, if R o

9 R ⊆ R and if (x, y) ∈ R and (y, z) ∈ R, then (x, z) ∈ R o9 R

and hence (x, z) ∈ R. Thus to verify that a relation is transitive, we mustcompute R o

9 R and check whether R o9 R is a subset of R. By a long and detailed

computation:

R o9 R = {(a, a), (b, b), (c, c), (c, g), (c, h), (d, d),

(e, c), (e, e), (e, g), (e, h), (f, f), (g, c),(g, g), (g, h), (h, c), (h, g), (h, h)}.

106

Page 112: Logic and Discrete Mathematics

Thus R o9 R ⊆ R and hence R is transitive. Similarly:

T o9 T = ∅.

Therefore T o9 T ⊆ T and hence T is transitive.

107

Page 113: Logic and Discrete Mathematics

108

Page 114: Logic and Discrete Mathematics

Chapter 6

FUNCTIONS

6.1 Total and Partial Functions

Let R : A ↔ B be a relation between sets A and B. In most cases each elementof A may be R-related to more than one element of B. For example, if A isthe set of all students in a University, B is the set of all subjects taught in theUniversity and R is the set of all ordered pairs (x, y) such that student x studiesthe subject y, then each student may study more than one subject.

Now suppose that C is the set of all dates (such as 1 October 1969). Definethe relation S : A ↔ C so that (x, y) ∈ S if and only if the student x hasthe date of birth y. Then since every student has exactly one date of birth,S : A ↔ C is a relation in which every element x of A is S-related to exactlyone element of C. We may denote the date of birth of the student x by S(x).Then S consists of all ordered pairs of the form (x, S(x)), where x ∈ A. We saythat S is a total function from the set A to the set C.

Let D be the set of all Halls of Residence of the University and let T be theset of all ordered pairs (x, y), where x is a student who is living in the Hall ofResidence y. In this case, since not all students live in a Hall of Residence, but,if so, a student can only live in just one Hall of Residence, each element of Ais T -related to at most one element of D. We say that T is a partial functionfrom A into D. If we restrict T to those students living in a Hall of Residence,then T becomes a total function; i.e. if E is the set of students living in Hall,then E � T may be regarded as a total function from E into D. In this case,if x ∈ E we may denote the Hall in which x lives by T (x). If x ∈ A \ E, thenT (x) has no meaning. Note that E = dom T .

Let A and B be sets and suppose that R : A ↔ B is a total function fromA into B. If x ∈ A then R(x) denotes the unique object in B to which x isR-related. We call R(x) the R-image of x or the image of x under R or thevalue of R at x. Note that dom R = A, since every object of A is R-related toexactly one element of B. The declaration R : A → B is used to denote a totalfunction from A into B.

Now suppose that R : A ↔ B is a partial function from A to B. LetE = dom R. Then every element of E is R-related to exactly one element of B,but every element of A not belonging to E is not R-related to any element ofB. Thus E is the set of all elements of A which are R-related to exactly one

109

Page 115: Logic and Discrete Mathematics

element of B. If x ∈ E, then x is R-related to a unique element of B whichis denoted by R(x). The declaration R : A 7→ B is used to denote a partialfunction. Clearly a total function is also a partial function. Indeed a totalfunction f : A → B is a partial function f : A 7→ B for which dom f = A.Note also that a partial function is in particular a relation between two sets. Ifthe relation R : A ↔ B is a total function, then the declaration R : A → B ispreferable to the declarations R : A ↔ B and R : A 7→ B, since a total functionis more than just a relation or partial function.Example. Let A = {0, 1, 2, 3, 4}, B = {5, 6, 7} and let:

f = {0 7→ 5, 1 7→ 7, 2 7→ 6, 3 7→ 5, 4 7→ 7}.

Then f is a relation between the sets A and B. Moreover, since every elementof A is f -related to exactly one element of B, f is a total function from A to B,and we may write f : A → B. To be precise:

0 is f -related to 5;1 is f -related to 7;2 is f -related to 6;3 is f -related to 5;4 is f -related to 7,

and no element of A is f -related to any element of B other than the one givenin this list. Note that all the declarations:

f : A → B f : A 7→ B f : A ↔ B

are valid, but the first is the most informative. Note also that:

f(0) = 5; f(1) = 7; f(2) = 6; f(3) = 5; f(4) = 7.

Since f is a total function dom f = A. In this case ran f = B.Example. Let A = {0, 1, 2, 3, 4}, B = {5, 6, 7} and let:

g = {1 7→ 7, 2 7→ 6, 4 7→ 7}.

Then g is a relation between the sets A and B. Moreover, since every elementof A is g-related to at most one element of B, g is a partial function from A toB, and we may write g : A 7→ B. To be precise:

0 is not g-related to any element of B;1 is g-related to 7;2 is g-related to 6;3 is not g-related to any element of B;4 is g-related to 7,

and no element of A is g-related to any element of B other than the one givenin this list. Note that the declarations:

g : A 7→ B g : A ↔ B

are both valid, but the first is the most informative. The declaration f : A → Bis invalid. Note that in this case we may write:

g(1) = 7; g(2) = 6; g(4) = 7.

The domain of g is {1, 2, 4} and the range of g is {6, 7}.

110

Page 116: Logic and Discrete Mathematics

Example. Let A = {0, 1, 2, 3, 4}, B = {5, 6, 7} and let:

h = {0 7→ 5, 1 7→ 7, 2 7→ 6, 3 7→ 5, 4 7→ 7, 2 7→ 5}.

Then h is a relation between the sets A and B. Moreover, since 2 is h-relatedto two elements of B; namely 5 and 6, g is neither a total function nor a partialfunction from A to B. To be precise:

0 is h-related to 5;1 is h-related to 7;2 is h-related to both 5 and 6;3 is h-related to 5;4 is h-related to 7.

Note that only the declaration h : A ↔ B is valid. The declarations h : A → Band h : A 7→ B are both invalid.

Since (partial and total) functions are in particular relations, everythingthat applies to relations also applies to functions. Let f : A 7→ B be a partialfunction from the set A to the set B. Then f is a set of ordered pairs (x, y),with x ∈ A and y ∈ B. If (x, y) ∈ f , then x ∈ dom f and, since f is a partialfunction, y is the only element of B to which x is f -related. Indeed we maywrite y = f(x). Thus f consists of all ordered pairs (x, f(x)), where x ∈ dom fand no others. From the above examples we may write:

f = {(0, f(0)), (1, f(1)), (2, f(2)), (3, f(3)), (4, f(4))};g = {(1, g(1)), (2, g(2)), (4, g(4))}.

Since h is not a partial function, we cannot express h in the same way.

6.2 Injective Functions

Certain properties of function arise when we investigate conditions for a givenfunction to have an inverse; i.e. when is the inverse relation of a function alsoa function. Let f : A 7→ B be a partial function. Under what condition is theinverse relation f∼ : B ↔ A a partial function? Suppose that f∼ : B ↔ A isindeed a partial function. Then every element of B is R∼-related to at mostone element of A. We claim that no two distinct elements of A are f -related tothe same element of B. For assume that the distinct elements x and y of A aref -related to the same element z of B. Then (x, z) ∈ f and (y, z) ∈ f . Hence(z, x) and (z, y) both belong to f∼. Thus z is f∼-related to at least two distinctelements x and y of A; contradiction. Therefore no two distinct elements of Aare f -related to the same element of B.

Definition. Let A and B be sets. A partial function f : A 7→ B is said to beinjective if no two distinct elements of A are f -related to the same element ofB; i.e. have the same f -image.

Thus, if f : A 7→ B is a partial function such that the inverse relationf∼ : B ↔ A is also a partial function, then f is injective. The converse holds;i.e. if f : A 7→ B is injective, then the inverse relation f∼ : B ↔ A is a partial

111

Page 117: Logic and Discrete Mathematics

function. It is easy to see that f : A 7→ B is injective if and only if wheneverx, y ∈ A such that f(x) = f(y), then x = y. For:

∀x, y : A • f(x) = f(y) =⇒ x = y WV ∀x, y : A • ¬f(x) = f(y) ∨ x = y

WV ∀x, y : A • ¬f(x) = f(y) ∨ ¬x 6= y

WV ∀x, y : A • ¬(f(x) = f(y) ∧ x 6= y)WV ¬(∃x, y : A • f(x) = f(y) ∧ x 6= y).

The last line in this argument asserts that no two distinct elements of A havethe same f -image; i.e. that f is injective. Note also that f is injective if andonly if, whenever x and y are distinct elements of dom f , f(x) and f(y) aredistinct elements of B. In the study of relations the condition described in thedefinition of injectivity may be regarded as complimentary to the condition fora partial function.Example. Let A = {0, 1, 2, 3}, B = {4, 5, 6, 7, 8, 9} and let:

g = {(0, 5), (2, 8), (3, 4)}.

Then g : A ↔ B is a relation and:

0 is g-related to 5;1 is not g-related to any element of B;2 is g-related to 8;3 is g-related to 4,

and no element of A is g-related to any element of B other than the one givenin this list. Thus g is a partial function. Clearly no two elements of A areg-related to the same element of B. Therefore g is injective. Note that theinverse relation g∼ : B ↔ A is given by:

g∼ = {(4, 3), (5, 0), (8, 2)}.

Clearly g∼ is also a partial function. Note that g∼ is also injective. This isbecause g is the inverse relation of g∼; i.e. the inverse relation, g, of the partialfunction g∼ is a partial function.Example. Let A = {0, 1, 2, 3}, B = {4, 5, 6, 7, 8, 9} and let:

h = {(0, 5), (2, 8), (3, 5)}.

Then h : A ↔ B is a relation and:

0 is h-related to 5;1 is not h-related to any element of B;2 is h-related to 8;3 is h-related to 5,

and no element of A is g-related to any element of B other than the one givenin this list. Thus h is a partial function. In this case the elements 0 and 3 of Aare h-related to the same element, 5, of B. Therefore h is not injective. Notethat the inverse relation h∼ : B ↔ A is given by:

h∼ = {(5, 0), (5, 3), (8, 2)}.

Clearly h∼ is not a partial function. Note that injectivity has no meaning forgeneral relations; it only applies to partial functions.

112

Page 118: Logic and Discrete Mathematics

Example. Let A = {0, 1, 2, 3}, B = {4, 5, 6, 7, 8, 9} and let:

k = {(0, 5), (0, 8), (3, 4)}.

Then k : A ↔ B is a relation and:

0 is k-related to both 5 and 8;1 is not k-related to any element of B;2 is not k-related to any element of B;3 is g-related to 4.

Since 0 is related to more than one element of B, k is not a partial function.Note that the inverse relation k∼ : B ↔ A is given by:

k∼ = {(4, 3), (5, 0), (8, 0)}.

Clearly k∼ is a partial function. Note that k∼ is not injective, because theinverse relation, k, of the partial function k∼ is not a partial function.

An injective partial function from a set A to a set B is called a partialinjection from A to B. The declaration f : A 7� B is used to indicate that fis a partial injection from A to B. Note that, if the declaration f : A 7� B isvalid, then so are the declarations:

f : A 7→ B; f : A ↔ B.

However f : A 7� B is the most informative of the three declarations. In theabove three examples, the declarations:

g : A 7� B, g : A 7→ B, g : A ↔ B;h : A 7→ B, h : A ↔ B;k : A ↔ B

are valid, but not the declarations:

h : A 7� B; k : A 7� B; k : A 7→ B.

Let f : A 7� B be a partial injection. If y ∈ ran f , then, since f is injective,there exists one and only one element x ∈ dom f such that (x, y) ∈ f ; i.e.f(x) = y. Indeed, since (y, x) ∈ f∼ and f∼ is a partial function, x = f∼(y).Thus, if y ∈ ran f , then f∼(y) is the (unique) element x of dom f such thatf(x) = y.

Example. Let A = {1, 2, 3, 4, 5} and let B = {p, q, r, s}, where p, q, r, s aredistinct objects. Let:

f = {2 7→ r, 4 7→ p, 5 7→ s}.Then f : A 7� B is a partial injection and f∼ : B 7→ A is a partial function.Also:

dom f = {2, 4, 5}; ran f = {r, p, s}.Moreover:

f∼ = {r 7→ 2, p 7→ 4, s 7→ 5}.Hence:

f∼(r) = 2; f∼(p) = 4; f∼(s) = 5.

Indeed:

113

Page 119: Logic and Discrete Mathematics

f∼(r) = 2 is the (unique) element x of dom f such that f(x) = r;f∼(p) = 4 is the (unique) element x of dom f such that f(x) = p;f∼(s) = 5 is the (unique) element x of dom f such that f(x) = s.

Because a total function is also a partial function, the same definition ofinjectivity applies to total functions. An injective total function f from a setA to a set B is called a total injection from A to B and is declared by theexpression f : A � B. If f is a total injection from A to B, then all thefollowing declarations are valid:

f : A � B (f is a total injection from A to B).f : A 7� B (f is a partial injection from A to B).f : A → B (f is a total function from A to B).f : A 7→ B ( f is a partial function from A to B).f : A ↔ B (f is a relation between A and B).

Example. Let A = {0, 1, 2, 3}, B = {4, 5, 6, 7, 8, 9} and let:

e = {0 7→ 8, 1 7→ 5, 2 7→ 6, 3 7→ 9}.

Then:

0 is e-related to 8;1 is e-related to 5;2 is e-related to 6;3 is e-related to 9,

and no element of A is e-related to any element of B other than those givenin the list. Thus each element of A is e-related to exactly one element of B.Therefore e is a total function from A to B. Moreover, from the above list itis clear that no two distinct elements of A are e-related to the same element ofB. Hence f is a total injection from A to B. It follows that all the followingdeclarations are valid:

e : A � B;e : A 7� B;e : A → B;e : A 7→ B;e : A ↔ B.

6.3 Surjective Functions

Recall that injectivity may be regarded as complimentary to the condition fora relation to be a partial function and that the condition for a partial functionf : A 7→ B to be a total function is that dom f = A. We may regard thecondition ran f = B to be complimentary to the condition dom f = A. Apartial or total function f from a set A to a set B is said to be surjective ifran f = B. This is equivalent to the:

Definition. A partial or total function from the set A to the set B is said to besurjective if every element of B is the f -image of at least one element of A.

114

Page 120: Logic and Discrete Mathematics

A surjective partial function is called a partial surjection and a surjectivetotal function is called a total surjection. We declare a partial surjection f froma set A to a set B by the expression f : A 7→→ B and a total surjection f fromA to B by the expression f : A →→ B.

Example. Let A = {m,n, p, q, r, s, t, u, v},where m,n, p, q, r, s, t, u, v are distinctobjects, let B = {1, 2, 3, 4} and let:

g = {(n, 3), (p, 1), (q, 3), (s, 2), (t, 4), (u, 3), (v, 2)}.

Then g : A 7→ B is a partial function and:

1 is the g-image of p;2 is the g-image of s and of v;3 is the g-image of n, of q and of u;4 is the g-image of t.

Therefore each element of B is the g-image of at least one element of A. There-fore g is surjective. It follows that the following declarations are valid:

g : A 7→→ B (g is a partial surjection from A to B);g : A 7→ B (g is a partial function from A to B);g : A ↔ B (g is a relation between A and B).

Example. Let A = {m,n, p, q, r, s, t, u, v},where m,n, p, q, r, s, t, u, v are distinctobjects, let B = {1, 2, 3, 4} and let:

h = {(m, 1), (n, 2), (q, 4), (s, 1), (t, 4)}.

Then h : A ↔ B is a partial function and:

1 is the h-image of m and of s;2 is the h-image of n;3 is not the h-image of any element of A;4 is the h-image of q and of t.

Therefore not all elements of B are the h-image of an element of A. Thus h isNOT surjective. The declaration h : A 7→→ B is NOT valid. However the twodeclarations h : A 7→ B and h : A ↔ B are valid.

Putting C = {1, 2, 4} and regarding h as a partial function from A to C,every element of C is the h-image of at least one element of A. Thus h : A 7→ Cis a partial surjection. We may always restrict a partial (or total) function inthis way to turn it into a partial (or total) surjection.

Example. Let A = {m,n, p, q, r, s, t, u, v},where m,n, p, q, r, s, t, u, v are distinctobjects, let B = {1, 2, 3, 4} and let:

k = {(m, 3), (n, 1), (n, 4), (q, 2), (r, 3), (u, 4)}.

Then k : A ↔ B is a relation and:

m is k-related to 3;m is k-related to both 1 and 4;q is k-related to 2;r is k-related to 3:u is k-related to 4.

115

Page 121: Logic and Discrete Mathematics

Although ran k = B, we cannot say that k is surjective. For k is not even apartial function. Note that m is related to more than one element of B. Theonly valid declaration in this case is k : A ↔ B.

Example. Let A = {m,n, p, q, r, s, t, u, v},where m,n, p, q, r, s, t, u, v are distinctobjects, let B = {1, 2, 3, 4} and let:

e = {(m, 3), (n, 2), (p, 3), (q, 1), (r, 2), (s, 4), (t, 3), (u, 1), (v, 3)}.

Then e is a total function from A to B. Moreover:

1 is the e-image of q and of u;2 is the e-image of n and of r;3 is the e-image of each of the elements m, p, t, v;4 is the e-image of s.

Each element of B is the e-image of at least one element of A. Hence f is atotal surjection from A to B. It follows that all the following declarations arevalid:

e : A →→ B (e is a total surjection from A to B);e : A 7→→ B (e is a partial surjection from A to B);e : A → B (e is a total function from A to B);e : A 7→ B (e is a partial function from A to B);e : A ↔ B (e is a relation between A and B).

6.4 Bijective Functions

Let f : A 7→ B be a partial function from the set A to the set B. Recall that,the inverse relation f∼ : B ↔ A is a partial function if and only if f is injective.Moreover, if f is injective then so is the partial function f∼ : B 7→ A.

Now suppose that f : A → B is a total function. We now investigate underwhat conditions the inverse relation f∼ : B ↔ A is a total function. For f∼ tobe a total function, it must be in particular a partial function. Thus f must bea partial injection. This means that f is a total injection. Also for f∼ to bea total function, dom f∼ = B. But dom f∼ = ran f . Thus ran f = B; i.e. fis surjective. Thus for f∼ to be a total function, f must be both injective andsurjective.

Suppose that the total function f : A → B is both injective and surjective.Since f is surjective, every element of B is the f -image of at least one elementof A. Since f is injective, no two distinct elements of A have the same f -image;i.e. every element of B is the f -image of at most one element of A. Thus everyelement of B is the f -image of exactly one element of A. Conversely, if everyelement of B is the f -image of exactly one element of A, then f is both injectiveand surjective.

Definition. Let f : A → B be a total function from the set A to the set B. f issaid to be bijective if every element of B is the f -image of exactly one elementof A.

Thus, if f : A → B is a total function and, if the inverse relation f∼B ↔ Ais a total function, then f is bijective. The converse holds; i.e. if f : A → B is a

116

Page 122: Logic and Discrete Mathematics

bijective total function, then the inverse relation f∼B ↔ A is a total function.Since f is injective, f∼ : B ↔ A is a partial function. Since f is surjective:

dom f∼ = ran f = B.

Thus f∼ is a total function. Moreover f∼ is bijective. For we have alreadyseen that, since f is a partial injection, f∼ is a partial injection. Thus f∼ isinjective. Also, since:

ran f∼ = dom f = A,

f∼ is surjective. Since f∼ is both injective and surjective, it is bijective. f∼ iscalled the inverse function of f and is usually denoted by f−1.

A bijective total function from a set A to a set B is also called a bijectionfrom A to B. The declaration f : A �→ B is used to indicate that f is a bijectionfrom A to B.

Example. Let A = {p, q, r, s, t, u}, where p, q, r, s, t, u are distinct objects, letB = {1, 2, 3, 4, 5, 6} and let:

g = {(p, 3), (q, 4), (r, 1), (s, 5), (t, 2), (u, 6)}.

Clearly g is a total function from A to B. Moreover:

1 is the g-image of r;2 is the g-image of t;3 is the g-image of p;4 is the g-image of q;5 is the g-image of s;6 is the g-image of u,

and no element of B is the g-image of any element of A other than the onesgiven in the list. It follows that g is bijective. In this case all the followingdeclarations are valid:

g : A ↔ B, g : A 7→ B, g : A → B, g : A 7� B,g : A � B, g : A 7→→ B, g : A →→ B, g : A �→ B.

Now:g−1 = g∼ = {(1, r), (2, t), (3, p), (4, q), (5, s), (6, u)}.

Note that the bijection g ‘pairs off’ elements of A with elements of B in a ‘one-to-one’ fashion. Each element A of pairs off with just one element of B andeach element of B pairs off with just one element of A. Thus:

p pairs with just 3 = g(p);q pairs with just 4 = g(q);r pairs with just 1 = g(r);s pairs with just 5 = g(s);t pairs with just 2 = g(t);u pairs with just 6 = g(u),

and:

117

Page 123: Logic and Discrete Mathematics

1 pairs with just r = g∼(1);2 pairs with just t = g∼(2);3 pairs with just p = g∼(3);4 pairs with just q = g∼(4);5 pairs with just s = g∼(5);6 pairs with just u = g∼(6).

This feature is common to all bijections. If f : A �→ B is a bijection fromthe set A to the set B, then each element x ∈ A is paired with f(x) and eachelement y ∈ B is paired with f∼(y). Thus bijections are just one-to-one pairingsof one set with another. Note that the two sets must have the same number ofelements.

6.5 Worked Example

Let A = {p, q, r, s, t} and B = {1, 2, 3, 4, 5, 6, 7, 8}, where p, q, r, s, t are distinctobjects. Answer the following questions, and justify each negative answer:

(i) Is {(1, s), (2, q), (3, p), (4, s), (5, t), (6, p), (7, r), (8, t)} a total surjectionfrom B to A?

(ii) Is {p 7→ 2, r 7→ 4, s 7→ 1, t 7→ 4} a partial injection from A to B?

(iii) Is {(1, p), (2, r), (3, p), (5, s), (6, p), (7, t)} a partial surjection from B toA?

(iv) Is {5 7→ p, 3 7→ s, 7 7→ t, 8 7→ q} a partial injection from B to A?

(v) Is {(3, p), (4, r), (3, q), (5, t)} a partial function from B to A?

(vi) Is {p 7→ 4, s 7→ 3, r 7→ 6, t 7→ 2} a total injection from A to B?

Solution. (i) Yes.

(ii) No. If R = {p 7→ 2, r 7→ 4, s 7→ 1, t 7→ 4}, then two distinct elements, r, t,of A are R-related to the same element of B, and hence R is not injective.

(iii) No. If R = {(1, p), (2, r), (3, p), (5, s), (6, p), (7, t)}, then the element q ofA is not the R-image of any element of B, and so R is not surjective.

(iv) Yes.

(v) No. If R = {(3, p), (4, r), (3, q), (5, t)}, then the element 3 of B is R-related to two elements of A, and hence R is not a partial function fromB to A.

(vi) No. If R = {p 7→ 4, s 7→ 3, r 7→ 6, t 7→ 2}, then the element q of A is notR-related to any element of B, and so R is not a total function from A toB. Therefore R cannot be an injective total function from A to B; i.e. atotal injection from A to B.

118

Page 124: Logic and Discrete Mathematics

6.6 Functions as Operators or Procedures

A total function f : A → B from a set A to a set B may be regarded asan ‘operator’ or ‘procedure’. If we ‘input’ an element x of A, the procedure,f ,‘outputs’ the element f(x) of B. The operator need not be some randomprocess, but one which is regulated by some precise rule or rules. It may simplybe the rule which specifies the precise element which is output for each elementof A. Thus for example we may specify the total function f : A → B, whereA = {0, 1, 2, 3, 4, 5} and B = {p, q, r, s, t}, by the ‘rule’:

f(0) = r, f(1) = t, f(2) = p, f(3) = p, f(4) = q, f(5) = r.

More ‘regulated’ rules might involve a mathematical formula such as:

f(x) = x2 − 3x + 1,

or a computer program.A partial function f : A 7→ B may be regarded in the same way, but in

this case we must also specify a particular subset of A; namely the set dom f .We must input only those elements x of A which belong to dom f to obtain anoutput f(x). If x ∈ A and y ∈ B, then the statement “x is f -related to y” isequivalent to the statement “x ∈ dom f and y = f(x)”.

6.7 Relational Images of Functions

Let f : A → B be a function from the set A to the set B. Let E be a subset ofA and F be a subset of B. Then f(|E|) is a subset of B and f∼(|F |) is a subsetof A. An element y of B belongs to f(|E|) if and only if y is the f -image of atleast one element of E. Thus:

f(|E|) = {y : B | ∃x : A • y = f(x) ∧ x ∈ E}= {f(x) • x : A | x ∈ E}.

An element x of A belongs to f∼(|F |) if and only if x is f -related to at least oneelement; namely f(x); of F ; i.e. f(x) ∈ F . Thus:

f∼(|F |) = {x : A | f(x) ∈ F}.

Example. Let A = {0, 1, 2, 3, 4, 5, 6, 7, 8} and B = {p, q, r, s, t, u}, where p, q, r, s,t, u are distinct objects. Let f : A → B be the total function such that:

f(0) = p, f(1) = r, f(2) = t, f(3) = p, f(4) = r,

f(5) = s, f(6) = t, f(7) = r, f(8) = u.

Let E = {0, 2, 3, 4, 5, 7} and F = {r, s, u}. Then:

f(|E|) = {f(0), f(2), f(3), f(4), f(5), f(7)}= {p, t, p, r, s, r}= {p, r, s, t}.

Since f(1) = r, f(4) = r, f(5) = s, f(7) = r, f(8) = u all belong to F , butf(0) = p, f(2) = t, f(3) = p, f(6) = t do not:

f∼(|F |) = {1, 4, 5, 7, 8}.

119

Page 125: Logic and Discrete Mathematics

Now suppose that f : A 7→ B be a partial function form the set A to the setB. Let E be a subset of A and let F be a subset of B. Then again f(|E|) is asubset of B and f∼(|F |) is a subset of A. An element y of B belongs to f(|E|) ifand only if at least one element of E is f -related to y. Since any element of Awhich is f -related to an element of B must belong to dom f , an element y of Bbelongs to f(|E|) if and only if at least one element of E ∩ dom f is f -related toy. Thus:

f(|E|) = {y : B | ∃x : A • y = f(x) ∧ x ∈ E ∩ dom f}= {f(x) • x : A | x ∈ E ∩ dom f}.

An element x of A belongs to f∼(|F |) if and only if x is f -related to at least oneelement; namely f(x); of F ; i.e. f(x) ∈ F , in which case x ∈ dom f . Thus:

f∼(|F |) = {x : A | x ∈ dom f ∧ f(x) ∈ F}.

Example. Let A = {m,n, p, q, r, s, t, u, v, w}, where m,n, p, q, r, s, t, u, v, w aredistinct objects and let B = {0, 1, 2, 3, 4, 5}. Let f : A 7→ B be the partialfunction such that dom f = {m, p, q, s, t, v} and:

f(m) = 2, f(p) = 3, f(q) = 2, f(s) = 0, f(t) = 3, f(v) = 4.

Let E = {m,n, q, s, u} and F = {1, 2, 4, 5}. Then:

E ∩ dom f = {m, q, s}

and so:

f(|E|) = {f(m), f(q), f(s)}= {2, 2, 0}= {0, 2}.

Now f(m) = 2, f(q) = 2, f(v) = 4 belong to F , but f(p) = 3, f(s) = 0, f(t) =3 do not belong to F . Therefore:

f∼(|F |) = {m, q, v}.

6.8 Worked Example

Let S be the set of all students in the University of Wokingham and let H bethe set of all Halls of Residence in that University. George, Mary and Sally arethree students who belong to S. The following arrangements are at present inexistence at the University:

Some of the Halls are self-catering; i.e the students in these Hallsprovide their own meals;Every student lives in a Hall of Residence;The students in each Hall of Residence have elected, from amongtheir number, a representative to serve on the Council of the Uni-versity and a representative to serve on the Senate of the University;Each student has just taken an examination in Mathematics, an ex-amination in Physics and an examination in Chemistry, and has been

120

Page 126: Logic and Discrete Mathematics

awarded a mark belonging to the set M = {x : N | 0 ≤ x ≤ 100};A student passes an examination if and only if the mark awarded inthat examination is at least 40;A student receives a prize if he or she obtains either a mark of atleast 80 in the Mathematics examination or a mark of at least 70 inboth the Physics examination and the Chemistry examination.

Give suitable definitions of a subset J of H, three subsets P,Q,R of M andsix functions f : S → M , g : S → M , h : S → M , k : S → H, d : H → S ande : H → S, and then re-write the following statements about the University ofWokingham in a form which contains no words or symbols other than:

George, Mary, Sally, f , g, h, k, d, e, =, 6=, ⊆, ∈,J , P , Q, R, S, ∅, (|, |), (, ), ran , ∪, ∩, \.

(i) George and Mary do not live in the same Hall.

(ii) Mary lives in a Hall which is represented by Sally on the Council.

(iii) The Senate representatives of all the Halls passed the examination inMathematics.

(iv) Mary’s examination performance qualifies for a prize.

(v) No self-catering Hall is represented on the Council and Senate by thesame student.

(vi) Every student who does not represent a Hall on the Council or Senate

passed the Chemistry examination.

Solution. Let us define J to be the set of all self-catering Halls in the Universityof Wokingham. Then J is a subset of H. Let:

P = {x : N | 40 ≤ x ≤ 100};Q = {x : N | 70 ≤ x ≤ 100};R = {x : N | 80 ≤ x ≤ 100}.

Then P,Q,R are subsets of M . Let us define six total functions f : S → M ,g : S → M , h : S → M , k : S → H, d : H → S, e : H → S by specifying thatfor each student x in the set S:

f(x) is the mark obtained by x in the Mathematics examination;g(x) is the mark obtained by x in the Physics examination;h(x) is the mark obtained by x in the Chemistry examination;k(x) is the Hall of Residence in which x lives,

and that for each Hall y in the set H:

d(y) is the student who represents y on the Council;e(y) is the student who represents y on the Senate.

We can now re-write the statements in the required way as follows:

(i) The Hall in which George lives is k(George) and the Hall in which Marylives is k(Mary). Therefore the statement says that k(George) 6= k(Mary).

121

Page 127: Logic and Discrete Mathematics

(ii) The Hall in which Mary lives is k(Mary). Therefore the student whorepresents that Hall on the Council is d(k(Mary)). Hence the statementsays that d(k(Mary)) = Sally.

(iii) Since e is a total function from H to S, its domain, dom e, is H. Thereforeits range, ran e, is the set of all objects of the form e(x), where x ∈ H.Thus the statement asserts that every student in the set ran e passed theexamination in Mathematics. If x is a student, then f(x) is his or hermark in the Mathematics examination. Therefore the student x passed theexamination in Mathematics if and only if f(x) ∈ P . Hence the statement“every student in ran e passed the Mathematics examination” is equivalentto the statement “the f -image of every element of ran e belongs to P”; i.e.“the set of all f -images of elements of ran e is a subset of P”. The set of allf -images of elements of ran e is given by f(| ran e|). Therefore the requiredstatement is f(| ran e|) ⊆ P .

(iv) There are two methods by which a student may qualify for a prize. Thefirst method is to obtain a Mathematics mark of at least 80. Thus Maryqualifies for a prize by this method if and only if her Mathematics mark,f(Mary), belongs to the set R; i.e. f(Mary) ∈ R. Now f(Mary) ∈ R ifand only if Mary belongs to the set f∼(|R|). Thus Mary qualifies for aprize by the first method if and only if she belongs to the set f∼(|R|).The second method is to obtain Physics mark of at least at least 70 anda Chemistry mark of at least 70. Thus Mary qualifies for a prize by thismethod if and only if g(Mary) ∈ Q and h(Mary) ∈ Q; i.e. if and only ifMary belongs to the sets g∼(|Q|) and h∼(|Q|). Thus Mary qualifies for aprize by this method if and only if she belongs to the set g∼(|Q|)∩h∼(|Q|).It follows that Mary qualifies for a prize if she belongs to either the setf∼(|R|) or the set g∼(|Q|)∪ h∼(|Q|). Therefore the given statement may beexpressed in the form:

Mary ∈ f∼(|R|) ∪ (g∼(|Q|) ∩ h∼(|Q|)).

(v) The Council representative of a Hall y is d(y). Hence the set of Councilrepresentatives of the self-catering Halls is the set of d-images of elementsof J ; i.e. the set d(|J |). Similarly the set of all Senate representatives ofthe self-catering Halls is e(|J |). Thus the same student x is a representativeof a self-catering Hall on both Senate and Council if and only if x ∈ d(|J |)and x ∈ e(|J |); i.e. x ∈ d(|J |) ∩ e(|J |). Hence the given statement assertsthat the set d(|J |) ∩ e(|J |) has no members; i.e. d(|J |) ∩ e(|J |) = ∅.

(vi) We already know that the set of all students who represent Halls on Senateis ran e. Similarly ran d is the set of all students who represent Halls onCouncil. Thus (ran d)∪(ran e) is the set of all students who represent Hallson either Council or Senate (or both). Hence the set of all students whodo not represent their Halls on either Council or Senate is S \ ((ran d) ∪(ran e)). The statement says that every student in this set passed theexamination in Chemistry; i.e. for each student x in this set h(x) ∈ P .Hence the statement asserts that the h-image of every element x of the setS \ ((ran d) ∪ (ran e)) belongs to P ; i.e.

h(|S \ ((ran d) ∪ (ran e))|) ⊆ P.

122

Page 128: Logic and Discrete Mathematics

6.9 Functions Defined by Formulae

Let f : A 7→ B be a partial function. Then, if x ∈ dom f , x is f -relatedto precisely one element of B and this element is denoted by f(x). In manysituations there is a precise rule or formula which may be employed to determinef(x) whenever x belongs to dom f . For example, let f : R → R be the totalfunction such that for every x ∈ R x is f -related to x2. Then, for each x ∈ R,f(x) = x2. Indeed the formula ‘f(x) = x2’ characterizes the function f . [Inelementary mathematics the function is usually identified with the formula andis simply referred to as the ‘function’ f(x) = x2.] Many functions are determinedby formulae in this way. Consider the formula:

f(x) =1

x− 3.

If x is a real number and x 6= 3, then f(x) is also a real number. Thus theformula determines a total function g : R\{3} → R such that, for all x ∈ R\{3},g(x) = 1

x−3 . The formula also gives rise to a partial function h : R 7→ R such thatdom h = R \ {3} and whenever x belongs to dom h, h(x) = 1

x−3 . Although thefunctions g and h use the same rule for determining images, they are different.Note that, as sets, g = h. However they are different types of function.

Let A = {x : N | 0 ≤ x ≤ 10}, B = {x : N | 0 ≤ x ≤ 100}, C = {1, 3, 5, 7, 9}and D = {2x + 1 • x : N | 0 ≤ x ≤ 49}. Let:

R = {(1, 1), (3, 9), (5, 25), (7, 49), (9, 81)}.

Define functions f : A 7→ B, g : A 7→ D, h : C → B, k : C → D, p : N 7→ D,q : D 7→ D, r : C → N and s : C → R so that:

f = g = h = k = p = q = r = s = R.

Then although as sets the functions f, g, h, k, p, q, r, s are all the same, as func-tions they are all different, since their ‘types’ are not the same. For example fis a function from A to B, but g is a function from A to D. The function f isregarded as a subset of A × B; i.e. an object of the power set P(A × B); i.e.an object of ‘type’ P(A × B). Note that each of these functions are associatedwith the formula R(x) = x2. Thus, for example, f(x) = x2 for all x ∈ dom fand r(x) = x2 for all x ∈ dom r. Note that:

dom f = dom g = dom h = dom k = dom p = dom q = dom r = dom s = C.

and:

ran f = ran g = ranh = ran k = ran p = ran q

= ran r = ran s = {1, 9, 25, 49, 81}.

6.10 Composition of Functions

Suppose that A, B, C are three sets and f : A → B is a total function from Ato B and g : B → C is a total function from B to C. Then, in particular, fis a relation between A and B and g is a relation between B and C. Hence we

123

Page 129: Logic and Discrete Mathematics

may form the relation f o9 g between A and C. Suppose that (x, z) ∈ f o

9 g. Thenthere exists an element y ∈ B such that (x, y) ∈ f and (y, z) ∈ g. Since f is a(total) function y is uniquely determined by x; i.e. x is f -related to y and onlyy; indeed we may write y = f(x). Similarly z is uniquely determined by y andwe may write z = g(y). Therefore z is uniquely determined by x and we maywrite z = g(y) = g(f(x)). This means that f o

9 g is at least a partial functionfrom A to C. Moreover, since f is a total function, every element of A has anf -image in B. Similarly every element of B has a g-image in C. In particular, ifx belongs to A, x has the f -image f(x) in B and f(x) has the g-image g(f(x))in C and hence x is f o

9 g-related to f(g(x)). Since this holds for every elementof A, it follows that f o

9 g is a total function. In this case we may write for allx ∈ A:

(f o9 g)(x) = g(f(x)).

For example, suppose that:

A = {0, 1, 2, 3, 4, 5,6, 7, 8, 9}, B = {p, q, r, s, t, u, v, w},C = {a, b, c, d, e, m, n},

where a, b, c, d, e, m, n, p, q, r, s, t, u, v, w are distinct objects. Suppose thatf : A → B is the total function specified by:

f(0) = p, f(1) = r, f(2) = r, f(3) = s, f(4) = t,

f(5) = v, f(6) = t, f(7) = v, f(8) = v, f(9) = w

and suppose that g : B → C is the total function specified by:

g(p) = a, g(q) = a, g(r) = a, g(s) = d,

g(t) = b, g(u) = m, g(v) = m, g(w) = m.

Denote f o9 g by h. Then:

h(0) = g(f(0)) = g(p) = a, h(5) = g(f(5)) = g(v) = m,

h(1) = g(f(1)) = g(r) = a, h(6) = g(f(6)) = g(t) = b,

h(2) = g(f(2)) = g(r) = a, h(7) = g(f(7)) = g(v) = m,

h(3) = g(f(3)) = g(s) = d, h(8) = g(f(8)) = g(v) = m,

h(4) = g(f(4)) = g(t) = b, h(9) = g(f(9)) = g(w) = m.

We may approach this analysis of h = f o9 g from the point of view of relations.

Thus we may write:

f = {(0, p), (1, r), (2, r), (3, s), (4, t), (5, v), (6, t), (7, v), (8, v), (9, w)};g = {(p, a), (q, a), (r, a), (s, d), (t, b), (u, m), (v,m), (w,m)}.

Then:

(0, p) ∈ f and (p, a) ∈ g; ∴ (0, a) ∈ h;(1, r) ∈ f and (r, a) ∈ g; ∴ (1, a) ∈ h;(2, r) ∈ f and (r, a) ∈ g; ∴ (2, a) ∈ h;(3, s) ∈ f and (s, d) ∈ g; ∴ (3, d) ∈ h;(4, t) ∈ f and (t, b) ∈ g; ∴ (4, b) ∈ h;

124

Page 130: Logic and Discrete Mathematics

(5, v) ∈ f and (v,m) ∈ g; ∴ (5,m) ∈ h;(6, t) ∈ f and (t, b) ∈ g; ∴ (6, b) ∈ h;(7, v) ∈ f and (v,m) ∈ g; ∴ (7,m) ∈ h;(8, v) ∈ f and (v,m) ∈ g; ∴ (8,m) ∈ h;(9, w) ∈ f and (w,m) ∈ g; ∴ (9,m) ∈ h,

Therefore:

h = {(0, a), (1, a), (2, a), (3, d), (4, b), (5,m), (6, b), (7,m), (8,m), (9,m)},

so that:

h(0) = a, h(1) = a, h(2) = a, h(3) = d, h(4) = b,

h(5) = m, h(6) = b, h(7) = m, h(8) = m, h(9) = m.

If f : A → B and g : B → C are total functions we may use an alternativenotation for the composition, f o

9 g, of f and g. If x ∈ A, then the f o9 g-image of

x is given by g(f(x)). If we denote f o9 g by g ◦ f , then the order of f and g are

preserved when we write down the g ◦ f -image of an element x of A; thus:

(g ◦ f)(x) = (f o9 g)(x) = g(f(x)).

The total function g ◦ f = f o9 g is called the composite of f and g.

Let f : A → A be a total function from A to A. Then as a relation f is arelation on the set A. Hence we may form the relations, f2 = f o

9 f , f3 = f2 o9 f ,

f4 = f3 o9 f , etc. and these relations are obviously total functions. Moreover, if

x ∈ A:

f2(x) = (f o9 f)(x) = f(f(x));

f3(x) = (f2 o9 f)(x) = f(f2(x)) = f(f(f(x)));

f4(x) = (f3 o9 f)(x) = f(f3(x)) = f(f(f(f(x)))); etc.

For example, if A = {0, 1, 2, 3, 4, 5, 6, 7} and f : A → A is the total functionsuch that:

f(0) = 3, f(1) = 4, f(2) = 6, f(3) = 6,

f(4) = 0, f(5) = 2, f(6) = 1, f(7) = 2.

then:

f2(5) = f(f(5)) = f(2) = 6;

f3(5) = f(f2(5)) = f(6) = 1;

f4(5) = f(f3(5)) = f(1) = 4; etc.

6.11 Number Ranges

Let a and b be integers. Then we define the set a . . b by:

a . . b = {x : Z | x ≥ a ∧ x ≤ b}.

125

Page 131: Logic and Discrete Mathematics

For example:

15 . . 22 = {x : Z | x ≥ 15 ∧ x ≤ 22}= {15, 16, 17, 18, 19, 20, 21, 22};

38 . . 48 = {x : Z | x ≥ 38 ∧ x ≤ 48}= {48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58};

(−11) . . (−4) = {−11, −10, −9, −8, −7, −6, −5, −4}.

Note that, since there are no integers x such that x ≥ 22 and x ≤ 15, the set22 . . 15 is empty. Indeed in general, if a > b, then a . . b = ∅. The notationa . . b is therefore usually reserved for the case in which a ≤ b. In particulara . . a = {a}.

6.12 Sequences

Let n be a natural number and let X be a set. Then a total function from 1 . . nto X is called a sequence, or more precisely a sequence over X. For example, if:

P = {Andrew, James, Mary, Sue},

then:{1 7→ Andrew, 2 7→ James, 3 7→ Sue, 4 7→ James}

is a sequence (over P ). Similarly:

{1 7→ Sue, 2 7→ Mary, 3 7→ Andrew, 4 7→ Sue, 5 7→ James,6 7→ Mary, 7 7→ Sue, 8 7→ Mary, 9 7→ Andrew, 10 7→ James}

is a sequence (over P ).If X is a set, then seq X denotes the set of all sequences over X. Let

s ∈ seq X. Then, if (r, t) ∈ s, t is called the r − th term of s. For example, if:

s = {1 7→ Sue, 2 7→ Mary, 3 7→ Andrew, 4 7→ Sue, 5 7→ James,6 7→ Mary, 7 7→ Sue, 8 7→ Mary, 9 7→ Andrew, 10 7→ James},

then, since (7,Sue) ∈ s, Sue is the 7 − th term of s. Note also that Sue is the1− st and 4− th term of s. To specify the sequence s it suffices to list its termsin order:

Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James.

To distinguish the sequence from the list we delimit the list with the symbols 〈and 〉 and write:

s = 〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James〉.

Although a sequence is in fact a function, we may regard it as an (ordered) listin this way. Such a list may involve repetitions of elements in the list. Thus,for example, Sue appears in the above ordered list in three different positions.

Let s : 1 . . n → X be a sequence, where n is a natural number. Then, ifn ≥ 1, it is clear to see that s is a set of n distinct ordered pairs. Thus #s = n.

126

Page 132: Logic and Discrete Mathematics

If n = 0, then the set 1 . . n is empty and hence s is empty. Therefore in thiscase #s = 0. Thus #s = n for all natural numbers n. If s is empty, we call sthe empty sequence and we write s = 〈 〉. If s is not empty, we say that s is anon-empty sequence. Strictly speaking we should distinguish empty sequencesover different sets and use different notations for them, but usually the contextis clear and no confusion should arise with the notation 〈 〉.

If we represent a sequence as an (ordered) list, we say that we are writingout the sequence; for example:

s = 〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James〉.

but, if we regard the sequence as a set defined by extension, we say that we arerepresenting the sequence by a list of its elements between braces; for example:

s = {1 7→ Sue, 2 7→ Mary, 3 7→ Andrew, 4 7→ Sue, 5 7→ James,6 7→ Mary, 7 7→ Sue, 8 7→ Mary, 9 7→ Andrew, 10 7→ James},

or:

s = {(1,Sue), (2,Mary), (3,Andrew), (4,Sue), (5, James),(6,Mary), (7,Sue), (8,Mary), (9,Andrew), (10, James)}.

6.13 Operations on Sequences

Let s be a sequence. Then rev s denotes the sequence obtained from s byreversing the order of its terms. For example, if s is the sequence:

〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James〉,

then rev s is the sequence:

〈James, Andrew, Mary, Sue, Mary, James, Sue, Andrew, Mary, Sue〉.

If s is a non-empty sequence, then:head s denotes the 1− st (i.e. first) term of s;last s denotes the (#s)− th (i.e. last) term of s;front s denotes the sequence obtained from s by removing its last term;tail s denotes the sequence obtained from s by removing its first term.For example if s is the sequence:

〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James〉,

then head s is Sue, last s is James, front s is the sequence:

〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew〉,

and tail s is the sequence:

〈Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James〉.

127

Page 133: Logic and Discrete Mathematics

If s and t are sequences, then s _ t is the sequence obtained from s and tby first writing out s as a list and then continuing the listing by writing out t.For example suppose that:

s = 〈Sue, Mary, Andrew, Sue, James〉;t = 〈Mary, Sue, Mary, Andrew, James〉,

then s _ t is the sequence:

〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, Andrew, James〉,

We call s _ t the concatenation of s and t.Care must be taken in using the set notation for these sequence operations.

For instance we may express the sequence:

s = 〈Sue, Mary, Andrew, Sue, James, Mary, Sue, Mary, 〉,

in the form:

s = {1 7→ Sue, 2 7→ Mary, 3 7→ Andrew, 4 7→ Sue, 5 7→ James,6 7→ Mary, 7 7→ Sue, 8 7→ Mary, 9 7→ Andrew}.

It would however be wrong to say that tail s is the sequence:

t = {2 7→ Mary, 3 7→ Andrew, 4 7→ Sue, 5 7→ James,6 7→ Mary, 7 7→ Sue, 8 7→ Mary, 9 7→ Andrew}.

Recall that a sequence is a total function of the form s : 1 . . n → X, for somenatural number n. Thus the domain of a sequence is always a set of the form1 . . n, for some natural number n. Note that, however we regard t above asa total function, its domain cannot contain the natural number 1. Hence tcannot be a sequence. There are similar dangers in applying the other sequenceoperations to sequences represented by sets defined by extension. There is muchless chance of making mistakes if we regard sequences as (ordered) lists whenapplying the above operations on them.

A sequence as we have defined it is often referred to as a “finite” sequence todistinguish it from an “infinite” sequence. An infinite sequence may be definedas a total function s : N → X form the set of all natural numbers N into a set X.The n− th term, s(n), is usually denoted by sn and the sequence itself by {sn}.In this course the word “sequence” refers exclusively to finite sequences. If weneed to consider an infinite sequence we will always add the word “infinite”.

6.14 Functional Overriding

Suppose that f : A 7→ B and g : A 7→ B are partial functions from a set A toa set B. Then f and g are relations between A and B. Hence they give riseto the relation f ⊕ g between A and B. For the simplicity of notation let usrelabel the relational overriding f ⊕ g by h. Then, for every element x of A andevery element y of B, (x, y) ∈ h if and only if EITHER (x, y) ∈ g OR (x, y) ∈ fand x 6∈ dom g. If (x, y) ∈ g, then x ∈ dom g and y = g(x). If (x, y) ∈ f , thenx ∈ dom f and y = f(x). In either case, if x ∈ A, then there is at most one

128

Page 134: Logic and Discrete Mathematics

element y of B such that (x, y) ∈ h. It follows that h is a partial function fromA to B: h : A 7→ B. Then:

x ∈ dom h WV ∃1y : B • (x, y) ∈ h

WV ∃1y : B • (x, y) ∈ g ∨ ((x, y) ∈ f ∧ x 6∈ dom g)WV (∃1y : B • (x, y)∈g) ∨ (∃1y : B • (x, y) ∈ f ∧ x 6∈ dom g)WV x ∈ dom g ∨ (x ∈ dom f ∧ x 6∈ dom g)WV x ∈ dom g ∨ x ∈ dom f \ dom g

WV x ∈ dom g ∪ (dom f \ dom g)WV x ∈ dom g ∪ dom f.

Thereforedom h = dom g ∪ dom f.

Moreover, if x ∈ dom h, then h(x) = g(x), if x ∈ dom g and h(x) = f(x) ifx ∈ dom f \ dom g.

To recap, if f : A 7→ B and g : A 7→ B are partial functions, then f ⊕ g is apartial function h : A 7→ B such that:

dom h = dom f ∪ dom g;h(x) = g(x) if x belongs to dom g;h(x) = f(x) if x belongs to dom f but not to dom g.

Example. Suppose that A = {0, 1, 2, 3, 4, 5, 6, 7} and B = {p, q, r, s, t, u}, wherep, q, r, s, t, u are distinct objects. Let f : A 7→ B and g : A 7→ B be partialfunctions given by:

f = {0 7→ s, 2 7→ r, 3 7→ p, 5 7→ q, 6 7→ p};g = {3 7→ q, 4 7→ s, 5 7→ u, 7 7→ q}.

Let h = f ⊕ g. It is easy to check that:

h = {0 7→ s, 2 7→ r, 3 7→ q, 4 7→ s, 5 7→ u, 6 7→ p, 7 7→ q}.

Therefore dom h = {0, 2, 3, 4, 5, 6, 7} and:

h(0) = s, h(2) = r, h(3) = p, h(4) = s, h(5) = u, h(6) = p, h(7) = q.

Similarly dom f = {0, 2, 3, 5, 6} and:

f(0) = s, f(2) = r, f(3) = p, f(5) = q, f(6) = p,

and dom g = {3, 4, 5, 7} and:

g(3) = q, g(4) = s, g(5) = u, g(7) = q.

Then:

(dom f) ∪ (dom g) = {0, 2, 3, 5, 6} ∪ {3, 4, 5, 7}= {0, 2, 3, 4, 5, 6, 7}= dom h.

129

Page 135: Logic and Discrete Mathematics

Since:

h(3) = q = g(3), h(4) = s = g(4), h(5) = u = g(5), h(7) = q = g(7),

we see that h(x) = g(x) when x ∈ {3, 4, 5, 7} = dom g.Now dom f \ dom g = {0, 2, 3, 5, 6} \ {3, 4, 5, 7} = {0, 2, 6}. Since:

h(0) = s = f(0), h(2) = r = f(2), h(6) = p = f(6),

we see that h(x) = f(x) for all x ∈ {0, 2, 6} = dom f \dom g. This confirms, forthis particular case, the rule:

dom h = dom f ∪ dom g;h(x) = g(x) if x belongs to dom g;h(x) = f(x) if x belongs to dom f but not to dom g.

6.15 Worked Example

Suppose that we are required to specify the computer program which will controlthe operations of an automatic vending machine. The vending machine is ableto retail a certain collection of items which we will denote by Merchandise,which includes for example a given kind of chocolate bar, denoted by chocolate,and a certain brand of orange juice contained in a carton, denoted by orange-juice. The program must involve a database which tells it how much to chargefor each item in the set Merchandise. This database may be expressed as apartial function:

cost : Merchandise 7→ N,

which associates with each item in the domain of the partial function the priceof that item, in pence. Note that perhaps only a small fraction of the items inthe set Merchandise will be on sale at any particular time. Initially only thoseitems on sale will have a price put on them; the others will only be priced ifand when they are purchased from the wholesaler to be put into the machinefor sale. Therefore there exist items which belong to the set Merchandise, butnot to the domain of cost. If the item chocolate is stocked by the machine andis to be priced at 39 pence, then:

cost(chocolate) = 39.

On the other hand, if orange-juice is not yet on sale in the machine, then it doesnot belong to the domain of cost. At a certain time in the future we may wishto stock the machine with textorange-juice and hence at the appropriate timewe must enter a corresponding price into the database. Also note that pricesmay change from time to time and so occasionally we may need to update thedatabase with new prices. When the database needs updating we may providenew instructions to the program by specifying a partial function:

newcost : Merchandise 7→ N.

For example, the item orange-juice may be put on sale at a price of 51 pence.Hence:

newcost(orange-juice) = 51.

130

Page 136: Logic and Discrete Mathematics

The items not in the domain of newcost will continue to be priced at theiroriginal value provided they belong to the domain of cost. After this updatingof the database, the machine will be programmed to use the updated pricedatabase given by the partial function:

cost′ : Merchandise 7→ N,

where:

cost′(x) = newcost(x) if x ∈ dom newcost;cost′(x) = cost(x) if x ∈ dom cost but x 6∈ dom newcost.

The new ‘database’ defined by cost′ gives the price of an item if and only if theitem has a price in the old ‘database’ defined by cost or has a price in the newinstructions given by newcost. Thus:

dom cost′ = (dom cost) ∪ (dom newcost).

It follows that the new database is determined by the partial function:

cost′ = cost⊕ newcost.

This reflects the idea that the new instructions to the program override theprevious ones given by the partial function cost only when there is a conflict inthe stated price of an item.

6.16 Bags

The expression N1 denotes the set N \ {0}; i.e. the set of all natural numbersother than 0. Thus the set N1 consists of all the positive integers. A partialfunction b : X 7→ N1 from a set X to N1 is called a bag (or multiset) of elementsof X. For example, if X = {p, q, r, s, t, u, v}, where p, q, r, s, t, u, v are distinctobjects, then:

{q 7→ 3, s 7→ 2, t 7→ 5, v 7→ 1}

is a partial function from X to N1 and hence a bag of elements of X.We may regard a bag as a collection of objects which can contain an object

“several times”. Thus the bag:

{q 7→ 3, s 7→ 2, t 7→ 5, v 7→ 1}

may be regarded as a collection to which q belongs 3 times, s belongs twice,t belongs 5 times and v belongs once. In other words we may imagine it as ashopping bag into which we have put 3 (identical) copies of the object q, 2 copiesof s, 5 copies of t and just one copy of v. We will use the following expressionto denote this bag:

[[q, q, q, s, s, t, t, t, t, t, v]].

It does not matter in which order we write the elements in the bag as long aseach element is listed the required number of times. Thus the same bag may beexpressed as:

[[s, q, t, t, v, s, q, t, t, q, t]].

131

Page 137: Logic and Discrete Mathematics

If X is a set, then bag X denotes the set of all bags of elements of X.Thus bag X is the set of all partial functions from X to N1. For example, ifX = {p, q, r, s, t, u, v}, where p, q, r, s, t, u, v are distinct objects, then:

{q 7→ 3, s 7→ 2, t 7→ 5, v 7→ 1} = [[q, q, q, s, s, t, t, t, t, t, v, ]]

is an element of bag X.

Example. The concept of bag is of particular use in the context of the vendingmachine considered in the previous worked example. Suppose for example thevending machine contains:

11 bars of chocolate;9 cartons of orange juice;12 cartons of grape juice;18 packets of jelly babies;10 packets of fruit gums;6 small packets of biscuits.

Then the contents of the vending machine might be represented by the bag:

{chocolate 7→ 11, orange-juice 7→ 9, grape-juice 7→ 12,

jelly-baby 7→ 18, fruit-gum 7→ 10, biscuit 7→ 6}.

Note that, in this example, the notation using the symbols [[ and ]] is much toocumbersome, since there would be, in total, 66 items to list. In this example itis assumed that:

chocolate, orange-juice, grape-juice,jelly-baby, fruit-gum, biscuit.

are used as names for particular elements of the set Merchandise. Thereforethe given bag is an element of the set:

bag Merchandise.

There is another obvious bag associated with the vending machine. At anygiven moment, there will be a certain collection of coins in the machine. Thiscollection may be regarded as a bag of elements of N; i.e. as an element of bag N.Suppose that the machine accepts coins to the value of 1, 2, 5, 10, 20, 50 and100 pence. At a particular moment in time, the machine contains 15 one-pencecoins, 13 two-pence coins, 18 ten-pence coins, 21 fifty-pence coins and 16 poundcoins, but no five-pence and twenty-pence coins. Then this collection of coinsmay be represented by the bag:

{1 7→ 15, 2 7→ 13, 10 7→ 18, 50 7→ 21, 100 7→ 16}.

Since this is a partial function from N to N1, it is bag of elements of N; i.e. anelement of the set bag N.

If X is a set, then recall that a partial function from X to N1 is a subsetof X × N1. In particular the empty set is a subset of X × N1 and hence is apartial function from X to N1. Therefore the empty set may be regarded asa bag of elements of X. Clearly this bag contains no objects. Thus we call

132

Page 138: Logic and Discrete Mathematics

it the empty bag and denote it by [[ ]]. Intuitively it may be thought of as ashopping bag which has nothing in it at all. We will regard the empty bag asan element of any set of bags. For instance we may consider it as an elementof bag Merchandise. This empty bag would occur when all the stock of thevending machine has been sold and none of it has been replaced.

We may classify a bag according to the number of each object it contains.Suppose that B is a bag of elements of a set X and that x is an element of X.Let B#x or count Bx to represent the number of copies of x in the bag B. Interms of the functional notation we have B#x = B(x), if x belongs to dom B,and B#x = 0, otherwise. For example suppose that X = {p, q, r, s, t, u, v},where p, q, r, s, t, u, v are distinct objects, and that B is the bag:

{q 7→ 3, s 7→ 2, t 7→ 5, v 7→ 1}.

Then:

B#p = 0, B#q = 3, B#r = 0, B#s = 2,

B#t = 5, B#u = 0, B#v = 1.

Thus there are no copies of p, three copies of q, no copies of r, two copies of s,five copies of t, no copies of u and one copy of v.

6.17 Operations on Bags

Given two shopping bags, it is clear that we may empty them into a singleshopping bag. This process may be applied to our more precise formulation ofbag. Suppose that B and C are bags of elements of a set X. Then we maydefine a bag D of elements of X such that:

D#x = B#x + C#x,

for all x ∈ X. In effect we have put the contents of both bags B and C into asingle bag denoted by D. We denote this bag D by B]C. For example supposethat:

X = {p, q, r, s, t, u, v};B = {q 7→ 3, s 7→ 2, t 7→ 5, v 7→ 1};C = {p 7→ 4, q 7→ 2, t 7→ 3, v 7→ 6}.

Then B contains:

no copies of p;3 copies of q;no copies of r;2 copies of s;5 copies of t;no copies of u;1 copy of v,

and C contains:

133

Page 139: Logic and Discrete Mathematics

4 copies of p;2 copies of q;no copies of r;no copies of s;3 copies of t;no copies of u;6 copy of v.

Hence B ] C contains:

0 + 4 = 4 copies of p;3 + 2 = 5 copies of q;0 + 0 = 0 copies of r;2 + 0 = 2 copies of s;5 + 3 = 8 copies of t;0 + 0 = 0 copies of u;1 + 6 = 7 copies of v.

Therefore:B ] C = {p 7→ 4, q 7→ 5, s 7→ 2, t 7→ 8, v 7→ 7}.

Consider the example of the vending machine. Suppose that at a particulartime the bag which represents the contents of the machine is:

B = {chocolate 7→ 11, orange-juice 7→ 9, grape-juice 7→ 12,

jelly-baby 7→ 18, fruit-gum 7→ 10, biscuit 7→ 6}.

Suppose that additional items were then added to the contents of the vendingmachine. To be precise suppose that these items were represented by the bag:

C = {orange-juice 7→ 20, fruit-gum 7→ 15, biscuit 7→ 10crisp 7→ 17, humbug 7→ 23},

where crisp denotes a packet of crisps and humbug denotes a packet of humbugs.Then B ] C is the bag D of elements of merchandise such that:

D#x = B#x + C#x,

for all elements x of Merchandise. Now D#x = 0 for all x in Merchandiseexcept for the following cases:

D#chocolate = 11 + 0 = 11;D#orange-juice = 9 + 20 = 29;D#grape-juice = 12 + 0 = 12;D#jelly-baby = 18 + 0 = 18;D#fruit-gum = 10 + 15 = 25;D#biscuit = 6 + 10 = 16;D#crisp = 0 + 17 = 17;D#humbug = 0 + 23 = 23.

Therefore:

B ] C = {chocolate 7→ 11, orange-juice 7→ 29, grape-juice 7→ 12,

jelly-baby 7→ 18, fruit-gum 7→ 25, biscuit 7→ 16,

crisp 7→ 17, humbug 7→ 23}.

134

Page 140: Logic and Discrete Mathematics

The example of a vending machine also suggests another possible operationon bags. Suppose that we consider the removal of items from the vendingmachine for whatever purpose [they may have been sold, or perhaps they havepassed a sale-by-date]. For example suppose that the bag:

B = {chocolate 7→ 11, orange-juice 7→ 9, grape-juice 7→ 12,

jelly-baby 7→ 18, fruit-gum 7→ 10, biscuit 7→ 6}.

represents the contents of the machine at a certain time. Suppose over a shortperiod of time certain of these contents have been removed. To be precise,suppose that those items removed are given by the bag:

E = {chocolate 7→ 6, orange-juice 7→ 9, jelly-baby 7→ 3, biscuit 7→ 4}.

The bag which represents what is left is denoted by B −∪ E; thus:

B −∪ E = {chocolate 7→ 5, grape-juice 7→ 12, jelly-baby 7→ 15,

fruit-gum 7→ 10, biscuit 7→ 2}.

More generally, if B and C are bags of elements of the set X and C is suchthat:

B#x ≥ C#x,

for every element x of X, then we may define B −∪ C as that bag of elements Gof X such that:

G#x = B#x− C#x,

for all x in X. However, since B ] C is defined for ALL bags of elements ofX, we would like the same to be true for B −∪ C. Let us consider the aboveexample. Suppose that a customer would like to buy from the vending machineitems represented by the bag:

F = {chocolate 7→ 5, orange-juice 7→ 9, jelly-baby 7→ 3, biscuit 7→ 13}.

If the stock of the vending machine is represented by the bag B above, thenthere are insufficient packets of biscuits in the vending machine to satisfy thecustomers needs. The best that the customer can achieve is to purchase all thepackets of biscuits in the machine; namely 4 packets. In this case the resultingstock of the machine is given by the bag:

G = {chocolate 7→ 6, grape-juice 7→ 12, jelly-baby 7→ 15, fruit-gum 7→ 10}.

Again in this case we use the same notation and denote G by B −∪F . Therefore,in general, for ANY bags, B and C of elements of X, we define B −∪C to be thebag G of elements of X such that, for every element x of X:

G#x ={

(B#x)− (C#x) if B#x ≥ C#x0 if B#x < C#x

135