discrete mathematics - pbworksbilalbajwa.pbworks.com/w/file/fetch/48531985/text.pdf · discrete...

130
Discrete Mathematics Revision Notes Jim Woodcock University of York MSc in Software Engineering Autmun Term 2006

Upload: phamtuyen

Post on 08-Sep-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Discrete Mathematics

Revision Notes

Jim Woodcock

University of York

MSc in Software Engineering

Autmun Term 2006

Page 2: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

2

Page 3: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Contents

1 Propositional Calculus 11.1 Propositions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Conjunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3 Disjunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.4 Negation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.5 Implication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31.6 Equivalence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.7 Propositions and Truth Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.8 Tautologies and Contradictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71.9 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91.10 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

2 Predicate Calculus 162.1 Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202.2 Validity and Satisfiability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.3 Properties of Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212.4 Multiple Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

3 Set Theory 303.1 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.2 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313.3 Finite and Infinite Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333.4 Equality of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343.5 Empty Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343.6 Subsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353.7 Proper Subset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373.8 Sets of Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383.9 Power Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383.10 Disjoint Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383.11 Venn’s Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393.12 Union . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403.13 Intersection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403.14 Di!erence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413.15 Properties of Set Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 423.16 Generalised Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433.17 Axiomatic Set Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

3.17.1 Axiomatics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

i

Page 4: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

3.17.2 Cantor’s and Russell’s Paradoxes . . . . . . . . . . . . . . . . . . . . . . . . . 443.17.3 The Zermelo-Fraenkel Axioms for Set Theory . . . . . . . . . . . . . . . . . . 45

3.18 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48

4 Relations 524.1 Ordered Pairs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 524.2 Cartesian Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534.3 Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 554.4 Inverse Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564.5 Identity Relation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574.6 Properties of Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574.7 Equivalence Relations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594.8 Source, Target, Domain, and Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604.9 Orderings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614.10 Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 614.11 Relational Restriction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 624.12 Relational Closure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634.13 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

5 Functions 665.1 Total and Partial Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685.2 Special Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685.3 Relational Operations on Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715.4 Relations and Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725.5 Cardinality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 725.6 The Pigeonhole Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735.7 Functional Composition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735.8 Functional Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 745.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75

A Solutions to Chapter 1: Propositional Calculus 77

B Solutions to Chapter 2: Predicate Calculus 93

C Solutions to Chapter 3: Set Theory 98

D Solutions to Chapter 4: Relations 111

E Solutions to Chapter 5: Functions 121

ii

Page 5: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Chapter 1

Propositional Calculus

1.1 Propositions

A proposition is some statement such as

1. 4 is a prime number.2. 3+ 3 = 6.3. 2 is an even integer, but 3 is not.4. My most recently written program always halts, if it’s allowed to run for long enough.

As we shall see, a fundamental property of a proposition is that it is either true or false, butnot both. In the example, the first proposition is false, and the second and third are true.The last may well be rather di"cult to determine, and its truth depends on important resultsin the theory of computation. However di"cult it may be to determine, the last propositionis definitely either true or false, but not both. This truthfulness or falsity of a proposition iscalled its truth value. Compound propositions are composed of subpropositions and variousconnectives. A fundamental property of a compound proposition is that its truth value iscompletely determined by the truth values of its subpropositions and their connectives.

A propositional variable denotes an arbitrary proposition with an unspecified truth value.We will use the letters p,q, r , with or without subscripts, for these variables. Sometimes weuse other, upper-case letters to denote specific propositions, such as H for the proposition“My most recently written program always halts, if it’s allowed to run for long enough”.

Propositions may be connected in various ways. The following table describes one unaryand four binary connectives, arranged in descending order of operator precedence:

¬ negation not! conjunction and" disjunction or# implication implies! equivalence if and only if

is equivalent to

The table gives the connective’s symbol, its name, and how it is pronounced.1 Using thenotion of precedence, we can see that the proposition

¬p ! q " r ! q # p ! r

1Note: “p and q” or “p conjoined with q”; not “p and-ed with q”.

1

Page 6: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

2

is equivalent to the parenthesised version

(((¬p) ! q) " r)! (q # (p ! r))

Example 1 Using these connectives, we can build up compound propositions:

¬Ja!a cakes are biscuits;

! < 4 ! ! < 5;

! < 4 # ! < 5;

Jim is thirty-something # Jim is under forty;

Jim is thirty-something ! Jim is under forty

"

In the following sections, we consider each of the connectives.

1.2 Conjunction

Any two propositions may be connected together using the word “and” to form a compoundproposition called the conjunction of the original propositions; for example, “Roses are redand violets are blue”. The conjunction is written symbolically as p ! q and is read “p and q”.It is true exactly when both p and q are true, and false otherwise.

1.3 Disjunction

Any two propositions may be connected together using the word “or” to form a compoundproposition called the disjunction of the original propositions; for example, “The bridge issafe, or Jim is a poor engineer”. The disjunction is written symbolically as p " q and is read“p or q”. It is true exactly either when p is true, or when q is true, and false otherwise. Inthis way, it is inclusive or.

Example 2 A lawyer might well use the term “and/or” to denote inclusive or. What if wewanted to describe exclusive or? For example, For example, a bar-room lawyer might takethe sentence “You may have a beer or you may have a whisky” to mean “You may have abeer or you may have a whisky, but not both”. How should we formalise this? Using B tosymbolise “you may have a beer”, and W to symbolise “you may have a whisky”, we obtain

B or W , but not both.

We should expand this compound to the more explicit one

B or W , but not both B and W .

Now we are ready to formalise this. The sentence must be broken up into its logical con-stituent parts. The major break occurs at “but”, which in this context signals a conjunction:

( B or W ) ! (not both B and W ).

The first conjunct is the easiest to deal with, as it is a straightforward disjunction:

( B " W ) ! (not both B and W ).

In the second conjunct, the major connective is the negation:

( B " W ) ! ¬ (both B and W ).

Page 7: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

3

The phrase “both B and W ” is simply a stylistic way of saying “B and W ”. Thus, “You mayhave a beer or you may have a whisky, but not both” is formalised as

(B " W ) ! ¬(B ! W ).

"

1.4 Negation

Given any proposition p, another proposition called the negation of p may be formed by isusing the unary connective “not”; for example, “It is not the case that roses are red and violetsare blue”. The negation is written symbolically as ¬p and is read “not p”. It is true exactlywhen p is false. Thus, our example may be rendered a little more formal as “¬(roses are red !violets are blue)”.

1.5 Implication

Of all the propositional connectives, implication seems the oddest when it is encountered forthe first time, and yet it is perhaps the most important connective from the point of view ofdeductive techniques. In modelling, it is used to formalise sentences of the form “If p, thenq”; for example, “If I eat Ja!a cakes, then I shall get fat” is formalised as “I eat Ja!a cakes# I get fat”. However, it does have the property that anything follows from a contradiction,and at first sight that is slightly surprising. Thus, the sentence “If Napoleon is German, thenI’m a Dutchman”, when translated into “Napoleon is German # I’m a Dutchman”, becomes aproposition that expresses a fact, even though Napoleon isn’t German and I’m not Dutch.

I have found it best to think of it as an ordering between the truth values: p # q shouldbe read as “p implies q”, or “p is stronger than q”. This relation on the two truth values isvery simple: false is stronger than true, and true is weaker than false. Furthermore, eachtruth value is as strong as itself. This gives us the observation about implication that p # qis true, except in the case that p is true but q is false. It is in this case that we are asking thequestion “Is true stronger than false?”; the answer is, by definition, no.2

In the proposition p # q, the proposition p is called the antecedent, and the propositionq is called the consequent.

Example 3 For example, the sentence “If the wind is not too strong and the thunderstormhas finished, then we can sail the boat” may be rendered into symbols as (with obviousabbreviations):

¬W ! ¬T # S

And the sentence “If you are right, then I apologise, but I think that you are wrong” maybe rendered as

(R # A) ! W

2It is easy to remember which truth value is stronger, if you consider them as two program specifications. Aprogram specification may be regarded, in the simplest case, as a predicate that must be satisfied (made true)by any program that is claimed to implement it. If you are asked to implement a program that satisfies thespecification “true”, then, because it is unconstrained, it can produce any output at all, and still be satisfactory.On the other hand, if you are asked to implement a program that satisfies the specification “false”, then no programyou can devise will be satisfactory. Thus, “true” is a very weak specification, and “false” a very strong one.

Page 8: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

4

And finally, the sentence “You will find him, if you look under the desk” may be renderedas

D # F

"

The last example shows the importance of identifying the antecedent and the consequentcorrectly. This can be harder than you might imagine at first sight. Consider the sentence

You may enter only if you have a ticket.

This is clearly an implication, but which way round is it? Thinking about the meaning of thesentence, we can see that your having a ticket is necessary in order for you to enter; however,it may not be su!cient.3 After all, we might want to let your sort in, even if you do have aticket. Therefore, “If you enter, then (at least) you have a ticket” is closer in meaning to ouroriginal sentence.

Thus, we formalise “p only if q” as

p # q

and “p if q” as

q # p

The converse of p # q is the proposition q # p, and the contrapositive of p # q is theproposition ¬q # ¬p.

1.6 Equivalence

The final propositional connective that we shall consider is equivalence. The propositionp ! q should be read as “p is equivalent to q”, or “p if and only if q” (the latter is oftenabbreviated to “p i! q”).4 The equivalence p ! q is true if and only if p and q have the sametruth value.

Example 4 For example, the sentence “A pass in Foundations is equivalent to a pass inManagement” is formalised as

F ! M

And the sentence “If and only if the time is right, will the revolution succeed” is formalisedas

T ! R

"

The fact that equivalence is used to formalise a sentence of the form “p if and only ifq” gives a clue as to the relation should between equivalence and implication. Indeed, theequivalence connective is sometimes called the biconditional, as is explained in the followingexample. The sentence “You will pass the Diploma if and only if you pass the assessment”means

3People sometimes read implications in this way. Thus, p # q may be read as “p is a su"cient condition forq”, or equivalently as “q is a necessary condition for p”.

4Some people also read the equivalence p ! q as “p is a necessary and su"cient condition for q.”

Page 9: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

5

p q p ! qt t tt f ff t ff f f

p q p " qt t tt f tf t tf f f

p q p # qt t tt f ff t tf f t

p q p ! qt t tt f ff t ff f t

p ¬pt ff t

Figure 1.1: Truth tables for the propositional connectives.

You will pass the Diploma if you pass the assessment, and you will pass the Diploma onlyif you pass the assessment,

which are formalised as

(A # D) ! (D # A)

It may also be formalised, using an equivalence, as

A ! D

1.7 Propositions and Truth Tables

By repetitive use of the logical connectives, we can construct more and more complicatedcompound propositions. As we said above, the truth value of these compound propositionsdepends on the truth values of their constituent parts, combined in various ways. That is,the truth value of a compound is a function of the truth values of its components. We can usethe informal descriptions of the connectives to draw up a set of rules, in the form of tables,that we can use to evaluate the truth value of such a compound proposition. These tablesare presented in Figure 1.1.

Since we wish to be quite general about this, the truth tables do not use actual propositionswhich are in fact true or false, but rather they use propositional variables, such as p and q.In the truth table for conjunction, the two columns (headed p and q) describe all possiblesituations regarding two propositional variables: they are both true, or one of them is trueand one is false, or they are both false. In order to make the table easier to read, the truthvalues have been abbreviated as t and f . There are 22 combinations; if there were threepropositional variables, then there would be 23 combinations; and in general if there were k,then there would be 2k combinations. The third column describes the truth value taken bythe conjunction in each of these situations: the conjunction p ! q is true exactly when bothp and q are true, and false otherwise.

These basic truth tables may be used to compute the truth values of compound proposi-tions. There should be as many propositional variables in the left-most columns as occur inthe compound proposition, and some consistent policy should be adopted for the assignmentof the truth values, such as counting down in binary notation.

Example 5 The truth table, for example, of the proposition¬(p ! ¬q)may be constructedas follows:

Page 10: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

6

p q ¬q p ! ¬q ¬(p ! ¬q)t t f f tt f t t ff t f f tf f t f t

The first two columns set out the various combinations of the values of the propositionalvariables, as before. There are further columns for progressively more complicated sub-propositions, the truth values at each step being determined by the rules embodied inthe truth tables. Finally, at the right-hand side of the table there is the truth value of thecompound proposition, with one entry for each of the possible combinations of values forp and q. The third and fourth columns contain intermediate results, and do not form partof the finished truth table for ¬(p ! ¬q).Another way of constructing the truth table is as follows. First draw out a table withsu"cient rows for every combination of values for p and q, and su"cient columns for p,q, and every propositional variable and connective in ¬(p ! ¬q):

p q ¬ (p ! ¬ q)t tt ff tf f

Truth values are now entered into the table in the following steps. First, the empty columnsheaded with the propositional variables are filled in:

p q ¬ (p ! ¬ q)t t t tt f t ff t f tf f f f

Now the table is completed by progressively filling in columns for connectives which arebeing applied to subpropositions whose entries are already filled in. At this point, thereis only one such column, namely the inner-most negation:

p q ¬ (p ! ¬ q)t t t f tt f t t ff t f f tf f f t f

Next, the conjunction’s column can be filled in:

p q ¬ (p ! ¬ q)t t t f f tt f t t t ff t f f f tf f f f t f

And finally, the outer-most negation:

p q ¬ (p ! ¬ q)t t t t f f tt f f t t t ff t t f f f tf f t f f t f

The truth table of the proposition consists of the original two columns for the proposi-tional variables p and q, and the final column.

Page 11: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

7

p q ¬(p ! ¬q)t t tt f ff t tf f t

This is the same truth table as that for p # q. Thus, we have proved the equivalence oftwo propositions. "

1.8 Tautologies and Contradictions

Propositions which evaluate to true in every combination of their propositional variablesare known as tautologies: they are always true. If, on the other hand, they evaluate to falseeverywhere, then they are known as contradictions. Of course, the negation of a contradictionis a tautology, and vice versa. A proposition which is neither a tautology nor a contradictionis termed a contingency.

Example 6 For example, it is a tautology that “every proposition is either true or false”.We can see this, by symbolising our sentence as p " ¬p, and then constructing the truthtable:

p p " ¬ pt t t f tf f t t t

It is a contradiction that “a proposition can be both true and false”. Again, we symbolisethis and construct a truth table:

p p ! ¬ pt t f f tf f f t t

"

In order to determine whether a proposition is a tautology, it is necessary to check only thoselines of the truth table for which the proposition could be false. Thus, consider the problemof determining whether p ! q # p is a tautology. If an implication a # b is false, then amust be true and b false. The truth table for p ! q # p has only one line where the value ofthe antecedent is true. So, we need consider only this situation:

p q p ! q # pt t t t

Two propositions p and q are said to be logically equivalent if the proposition p ! q isa tautology—this amounts to the same as saying that both have the same truth table. Iftwo propositions are logically equivalent, then one may be substituted for the other in anyproposition in which they occur. Thus, since p is logically equivalent to p " p, it follows thatp " q is logically equivalent to (p " p) " q. Figure 1.2 contains various useful identities. Wehave tried to give the logical identities meaningful names, so that they can be more easilyreferred to. Notice that conjunction and disjunction are said to be associative: that is, itdoesn’t matter where we put the parentheses in an expression such as p ! q ! r , since wehave that

(p ! q) ! r ! p ! (q ! r)

Logical identities may be used to show the relationship between various propositions.Example 7 For example, suppose that we wish to simplify the following proposition:

(p # q) " (p # r)# (q " r)

Page 12: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

8

1. p ! p " p idempotence of "2. p ! p ! p idempotence of !3. p " q ! q " p commutativity of "4. p ! q ! q ! p commutativity of !5. (p " q) " r ! p " (q " r) associativity of "6. (p ! q) ! r ! p ! (q ! r) associativity of !7. ¬(p " q)! ¬p ! ¬q De Morgan’s Law (1)8. ¬(p ! q)! ¬p " ¬q De Morgan’s Law (2)9. p ! (q " r)! (p ! q) " (p ! r) distributivity of ! over "

10. p " (q ! r)! (p " q) ! (p " r) distributivity of " over !11. p " true ! true zero for "12. p ! true ! p unit for !13. p " false ! p unit for "14. p ! false ! false zero for !15. p " ¬p ! true excluded middle16. p ! ¬p ! false contradiction17. p ! ¬¬p double negation18. (p # q)! ¬p " q implication19. (p ! q)! (p # q) ! (q # p) equivalence20. (p ! q # r)! (p # (q # r)) exportation21. (p # q) ! (p # ¬q)! ¬p absurdity22. (p # q)! (¬q # ¬p) contraposition

Figure 1.2: Logical identities

Proof

(p # q) " (p # r)# (q " r)

! by implication, twice

(¬p " q) " (¬p " r)# (q " r)

! by commutativity, associativity, and idempotence of "¬p " (q " r)# (q " r)

! by implication

¬(¬p " (q " r)) " (q " r)

! by De Morgan’s Law (1)

(¬¬p ! ¬(q " r)) " (q " r)

! by double negation

(p ! ¬(q " r)) " (q " r)

! by commutativity of "(q " r) " (p ! ¬(q " r))

! by distributivity of " over !((q " r) " p) ! ((q " r) " ¬(q " r))

! by excluded middle

Page 13: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

9

1. p # p " q addition2. p ! q # p simplification3. p ! (p # q)# q modus ponens4. (p # q) ! ¬q # ¬p modus tollens5. ¬p ! (p " q)# q disjunctive syllogism6. (p # q) ! (q # r)# (p # r) hypothetical syllogism7. (p ! q) ! (q ! r)# (p ! r) transitivity of !

Figure 1.3: Logical implications

((q " r) " p) ! true

! by unit for !(q " r) " p

! by commutativity

p " (q " r)

"

There are other useful tautologies that involve implications rather than equivalences, andfigure 1.3 contains some of these.

Example 8 5 A man who was captured by savages was promised his freedom if he coulddetermine with a single “yes or no” question the colour of the tribe’s idol. He knew theidol was either black or white. Unfortunately, the tribe contained two kinds of individuals:liars, who invariably gave the wrong answer to any question that they were asked; and truthtellers, who invariably gave the right answer. Fortunately, the victim was well-educated.He knew that he must ask a question which would be answered according to the followingtable:

Colour of IdolWhite Black

Liars Yes NoTruth-tellers Yes No

However, since a liar always gave the wrong answer, he realised that he must ask a questionwhose correct answers could be tabulated as follows:

Colour of IdolWhite Black

Liars No YesTruth-tellers Yes No

Whereupon he asked his nearest captor “Is it true that either you tell the truth and the idolis white, or that you lie and the idol is black?” This question enabled him to determinethe colour correctly, since an answer of yes meant the idol was white, and no meant thatit was black. Unfortunately, the savages thought that it was just a lucky guess, and theyreneged on their promise. "

1.9 Arguments

Suppose that the proposition p and p # q are both true. We can argue that, as a result ofthese suppositions, q must also be true. To see this, recall the truth table for implication:

5This example is well-known; our version follows (Stanat & McAllister, 1977).

Page 14: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

10

p q p # qt t tt f ff t tf f t

If we strike out those rows which do not correspond to the situation that p and p # q areboth true, then we arrive at the rather smaller table:

p q p # qt t t

There is only one situation, and in it q is true. We have proved the validity of an argumentknown as modus ponens. Compare this argument with the logical implication with samename in figure 1.3.

Formally, an argument is an assertion that a given set of propositions P1,P2, . . . ,Pn, calledthe premisses, entails another proposition Q , called the conclusion. Such an argument isdenoted using an assertion sign, known as the turnstile:

P1,P2, . . . ,Pn $ Q

This is formalised by saying that the argument P1,P2, . . . ,Pn $ Q is valid if Q is true when-ever all the premisses P1,P2, . . . ,Pn are true. This was what we were doing in the exampleconcerning modus ponens: we examined all those situations in which the antecedents weretrue, and then checked to see if the consequent was true also.

An argument which isn’t valid is called a fallacy.We end this chapter with three little proofs of the same theorem, all due to Binmore.

Example 9 The following argument is a fallacy:

p # q,q $ p

Again, the proof of this follows directly from the truth table for implication.6 "

Example 10 We give three di!erent proofs of the fact that, if x2 % 3x + 2 < 0, then x > 0.

Proof 1 Assume that x2 % 3x + 2 < 0. Then,

3x > x2 + 2 & 2 since x2 & 0.

Hence

x > 23 > 0

It follows that if x2 % 3x + 2 < 0, then x > 0.

Proof 2 The contrapositive statement is that “if x ' 0, then x2%3x+2 & 0”. We assumetherefore that x ' 0. Then

x % 1 ' 0 and x % 2 ' 0

Hence

x2 % 3x + 2 = (x % 1)(x % 2) & 0

It follows that “if x ' 0, then x2 % 3x + 2 & 0”, and hence that “if x2 % 3x + 2 < 0, thenx > 0”.

6This fallacy has been called “modus morons by Binmore.

Page 15: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

11

Proof 3 Assume “x2 % 3x + 2 < 0” and “x ' 0”. Then

x2 < 3x % 2 ' %2 < 0

This is a contradiction, and hence “if x2 % 3x + 2 < 0, then x > 0”.

"

In example 9, the proofs are quite informal; they can be formalised, however. Considerthe first proof, we can see that it is of the following form:

x2 % 3x + 2 < 0

! by rearranging

3x > x2 + 2

! since x2 & 0, we have that x2 + 2 & 0+ 2

3x > x2 + 2 ! x2 + 2 & 2

! by the meaning of &3x > x2 + 2 ! (x2 + 2 > 2 " x2 + 2 = 2)

! by distributivity of ! over "(3x > x2 + 2 ! x2 + 2 > 2) " (3x > x2 + 2 ! x2 + 2 = 2)

# by transitivity of >(3x > 2) " (3x > x2 + 2 ! x2 + 2 = 2)

# using the equality in the second disjunct

(3x > 2) " (3x > 2)

! by idempotence of "3x > 2

! dividing both sides by 3

x > 23

# since 23 > 0, and > is transitive

x > 0.

This is still not a formal proof, but the structure of an underlying formal proof has beenexposed.

Page 16: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

12

1.10 Problems

1. Let p be “it is cold” and let q be “it is raining”. Give a simple verbal sentence whichdescribes each of the following propositions:

(i) ¬p, (ii) p ! q, (iii) p " q, (iv) q " ¬p, (v) ¬p ! ¬q, (vi) ¬¬q.

2. Let p be “she is tall” and let q be “she is beautiful”. Write propositions that symbolisethe following:

(a) She is tall and beautiful.

(b) She is tall but not beautiful.

(c) It is false that she is short or beautiful.

(d) She is neither tall nor beautiful.

(e) It is not true that she is short or not beautiful.

3. (Hamilton) Translate into symbols the following compound statements:

(a) We shall win the election, provided that Jones is elected leader of the party.

(b) If Jones is not elected leader of the party, then either Smith or Robinson will leavethe cabinet, and we shall lose the election.

(c) If x is a rational number and y is an integer, then z is not real.

(d) Either the murderer has left the country or somebody is harbouring him.

(e) If the murderer has not left the country, then somebody is harbouring him.

(f) The sum of two numbers is even if and only if either both numbers are even orboth numbers are odd.

(g) If y is an integer, then z is not real, provided that x is a rational number.

4. (Stanat) Let p be the proposition “It is snowing.” Let q be the proposition “I will go totown.” Let r be the proposition “I have time.”

(a) Using propositional connectives, write a proposition which symbolises each of thefollowing:

i. If it is not snowing and I have time, then I will go to town.ii. I will go to town only if I have time.

iii. It isn’t snowing.iv. It is snowing, and I will not go to town.

(b) Write a sentence in English corresponding to each of the following propositions:

i. q ! r ! ¬p;ii. r ! q;

iii. (q # r) ! (r # q);iv. ¬(r " q).

.

5. (Stanat) State the converse and contrapositive of each of the following:

Page 17: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

13

(a) If it rains, I’m not going.

(b) I will stay only if you go.

(c) If you get 4lbs, you can bake the cake.

(d) I can’t complete the task if I don’t get more help.

6. (Grimaldi) Let p,q, r denote the following statements:

• p: Triangle ABC is isosceles;

• q: Triangle ABC is equilateral;

• r : Triangle ABC is equiangular.

Translate each of the following into an English sentence.

(a) q # p;

(b) ¬p # ¬q;

(c) q ! r ;

(d) p ! ¬q;

(e) r # p.

7. (Grimaldi)

(a) How many rows are needed for the truth table of the proposition

p " ¬q ! ¬r ! s # t

(b) If p1,p2, . . . ,pn are propositional variables, and the compound statement p con-tains at least one occurrence of each propositional variable pi , how many rows areneeded in order to construct the truth table for p?

8. Find truth tables for the following propositions:

(a) ¬p ! q

(b) ¬(p " q)(c) ¬(p " ¬q)

9. Rain on Tuesday is a necessary condition for rain on Sunday. If it rains on Tuesday, thenit rains on Wednesday. But it rains on Wednesday only if it rains on Friday. Moreover,no rain on Monday means no rain on Friday. Finally, rain on Monday is a su"cientcondition for rain on Saturday.

Express each of these statements in the form ‘p # q’. Given that it rains on Sunday,what can be said about Saturday’s weather?

10. Verify that the proposition p " ¬(p ! q) is a tautology.

11. Verify that the proposition (p ! q) ! ¬(p " q) is a contradiction.

12. Which of the following propositions are tautologies?

(a) p # (q # p);(b) q " r # (¬r # q);

Page 18: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

14

(c) (p ! ¬q) " ((q ! ¬r) " (r ! ¬p));(d) (p # (q # r))# ((p ! ¬q) " r).

13. Show that the following pairs of propositions are logically equivalent.

(a) p # q, ¬q # ¬p;

(b) (p " q) ! r , (p ! r) " (q ! r);(c) ¬p ! ¬q # ¬r , r # q " p;

(d) ¬p " q # r , (p ! ¬q) " r .

14. Show that the proposition (¬p # q)# (p # ¬q) is not a tautology.

15. Show that the following argument is valid: p # q,¬q $ ¬p.

16. Show that the following argument is valid: p ! q,q $ p.

17. Show that the following argument is a fallacy: p # q $ ¬p # ¬q.

18. Test the validity of the following argument:

If I study, then I will not fail mathematics.If I do not play Lemmings, then I will study.

But I failed mathematics.Therefore I played Lemmings.

19. What conclusion can be drawn from the truth of ¬p # p?

20. (Stanat) For each of the following expressions, use identities to find equivalent expres-sions which use only ! and ¬ and are as simple as possible.

(a) p " q " ¬r ;

(b) p " (¬q ! r # p);(c) p # (q # r).

21. (Stanat) For each of the following expressions, use identities to find equivalent expres-sions which use only " and ¬ and are as simple as possible.

(a) p ! q ! ¬r ;

(b) (p # q " ¬r) ! ¬p ! q;

(c) ¬p ! ¬q ! (¬r # p).

22. (Stanat) Establish the following tautologies by simplifying the left-hand side to the formof the right-hand side:

(a) (p ! q # p)! true;

(b) ¬(¬(p " q)# ¬p)! false;

(c) ((q # p) ! (¬p # q) ! (q # q))! p;

(d) ((p # ¬p) ! (¬p # p))! false.

23. (a) The nand operator (also known to logicians as the She"er stroke), is defined by thefollowing truth table:

Page 19: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

15

p q p nand qt t ft f tf t tf f t

Of course, nand is a contraction of not-and; p nand q is logically equivalent to¬(p !q). Show that

i. (p nand p)! ¬p;ii. ((p nand p)nand (q nand q))! p " q;

iii. ((p nand q)nand (p nand q))! p ! q.

(b) Find equivalent expressions for the following, using no connectives other thannand:

i. p # q;ii. p ! q.

(c) The nor operator (also known to logicians as the Pierce arrow), is defined by thefollowing truth table:

p q p nor qt t ft f ff t ff f t

For each of the following, find equivalent expressions which use only the nor op-erator.

i. ¬p;ii. p " q;

iii. p ! q.

24. Give an explanation of the second and third proofs in example 9.

25. Write a program to construct truth tables of propositions.

Page 20: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Chapter 2

Predicate Calculus

The language of propositions allows us to model a great variety of properties about specificobjects; however, it doesn’t allow us to state general properties, such as “Every cloud has asilver lining”. These general properties are known as universal properties, since they describeproperties that must be satisfied by every individual in some universe of discourse. In ourlittle example, we are considering the set of all clouds, and saying that every one of them hasa silver lining.

Example 11 The following are all examples of universal properties:

1. Every cloud has a silver lining.

2. All the bells in heaven shall ring.

3. Each student must hand in homework.

4. Nobody knows the trouble I seen.

5. Roses are red.

6. Jim doesn’t know anybody who can sign his bail application.

"

Sometimes we want to express the fact that at least one thing (without necessarily knowingwhich thing) has a particular property. This is known as an existential property.

Example 12 The following are all examples of existential properties:

1. Something’s got into the tank.

2. There is a tavern in the town.

3. I heard it from one of your friends.

4. A mad dog has bitten Robert.

5. Some people prefer logic.

"

In order to symbolise universal and existential properties we shall need two new symbols:“(” is the universal quantifier, and is read “for all”; “)” is the existential quantifier, and isread “there exists”. The quantifier symbols are used to build predicates; a predicate is like aproposition with various “slots” to be filled in by objects of various kinds. In this section weintroduce the syntax of predicates, leaving their formal properties until a little later.

Example 13 “) x : N • x > 5” is an existentially quantified predicate. "

16

Page 21: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

17

The phrase “x > 5” is not a proposition, because we cannot tell whether it is true or falsewithout knowing what x is. In fact, x is one of those slots we mentioned above. We can turnit into a proposition by giving a value for x, say 0. The proposition “0 > 5” is clearly false.

This technique of letting names stand for values is a powerful one, since it allows us tostate our more interesting properties. In the example, we stated that there is an x, which isa natural number, such that x > 5. We call this an existentially quantified predicate, and wecall the expression “there is an …” a quantifier. In mathematics, the symbol “)” is used todenote the expression “there is an …”; in Z, the natural numbers are denoted by the symbol“N”. As we shall see later, we could have formalised the sentence “There is a number greaterthan five” as

)y : N • y > 5

The di!erence is that we have used a di!erent name for the local variable.The existentially quantified predicate in Example 13 is true: there really is such an x. An

example is the number 6: it is a natural number, and it is greater than 5.

Example 14 Predicates (that is, propositions with free variables in them) occur commonlyin programming languages. For example, a statement of the form

if x > 3 then y := z

includes the predicate “x > 3”. When the statement is executed, the truth value of theassertion “x > 3” is determined using the current value of the variable x; the assertionis assigned either the value 1 (representing true) or 0 (representing false). However, thecoding of truth values as integers is sometimes exploited in strange ways in programminglanguages. For example, in PL/1,

A = X > 3

is a legitimate assignment statement; execution of this statement causes the numeric vari-able A to be assigned the value of 1 if X > 3 is true and 0 if X ' 3. Such a language isnot strongly typed. I find this example surprising because it permits the programmer tointerfere with the internal representation of Boolean values, thus violating many softwareengineering principles, including information hiding. "

Example 15 The sentences in Example 11 may be formalised as follows.

1. Let Cloud be the set of all clouds, and let SilverLining(x) mean that x has a silverlining.

( c : Cloud • SilverLining(c)

2. Let HolyBell be the set of all bells in heaven, and let Ring(x) mean that x shall ring.

(b : HolyBell • Ring(b)

3. Let Student stand for the set of all students, and Submit(x) mean that x must handin homework.

( s : Student • Submit(s)

4. Let Person be the set of all people, and let K(x)mean that x knows the trouble I seen.

(p : Person • ¬K(p)

5. Let Rose be the set of all roses, and Red(x) mean that x is red.

( r : Rose • Red(r)

Page 22: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

18

6. Let Person be the set of all people, and let x Knows y mean that x knows y , andx CanVouchFor y mean that x can sign y ’s bail application.

(p : Person • Jim Knows p # ¬(p CanVouchFor Jim)

This may also be written as

(p : Person | Jim Knows p • ¬(p CanVouchFor Jim)

"

Example 16 The sentences in Example 12 may be formalised as follows.

1. Let Thing stand for the set of all things, and InTank(x) mean that x is in the tank.

) x : Thing • InTank(x)

2. Let Tavern stand for the set of all taverns, and InTown(x))mean that x is in the town.

) t : Tavern • InTown(t)

3. Let Friends stand for the set of all your friends, and x Told y mean that x has told y .

) f : Friends • f Told me

4. Let MadDog stand for the set of all mad dogs, and x Bit y mean that x has bitten y .

)fido : MadDog • fido Bit Robert

5. Let Person stand for the set of all people, and PL(x) mean that x prefers logic.

)p : Person • PL(p)

"

Existential quantification may be thought of as a generalised form of disjunction:

) x : N • x > 5!(0 > 5) " (1 > 5) " (2 > 5) " (3 > 5) " . . .

The predicate must be true for some natural number.Another way of quantifying a predicate is to say that it is true for every value. Thus, “for

every x which is a natural number, x > 5”. The notation “(” is used to denote the universalquantifier :

( x : N • x > 5

Again, this is the same as

(y : N • y > 5

This universally quantified predicate is false, since not every natural number x is greaterthan 5. Consider the value “3”: it is a natural number, and it is less than 5. The universalquantifier may be thought of as a generalised conjunction:

( x : N • x > 5!(0 > 5) ! (1 > 5) ! (2 > 5) ! (3 > 5) ! . . .

Page 23: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

19

It must be true for every natural number.In Z, the quantifiers share a similar syntax:1

* x : s | p • q

where

• * is the quantifier ;

• x is the bound variable;

• s is the range of x;

• p is the (optional) constraint; and

• q is the predicate.

The two syntactic equivalences explain the constraint:

) x : s | p • q is a shorthand for ) x : s • p ! q

( x : s | p • q is a shorthand for ( x : s • p # q

The existentially quantified predicate

) x : s | p • q

is pronounced “there exists an x in s satisfying p, such that q.” The universally quantifiedpredicate

( x : s | p • q

is pronounced “for all x in s satisfying p, q holds.”Each quantifier introduces a “bound variable”, which is analogous to a local variable in

a block-structured programming language. In the quantified predicate “( x : s | p • q”, thebound variable has a scope that is exactly the constraint p and predicate q:

( x : s | p • q! "# $scopeof x

The quantifiers bind very loosely, so

( x : s • p ! q

is implicitly parenthesised as “( x : s • (p ! q)”, and not as “(( x : s • p) ! q”.Predicates such as “x > 3” contain a variable which is yet to be bound by a quantifier:

namely, “x”. Such yet-to-be-bound variables are called free variables.

Example 17 The following predicates are formed by universal quantification:

1. ( x : N • x < x + 1. “Every natural number x is less than x + 1.”

2. ( x : N • x = 3. “Every natural number x is equal to 3.”

1Do not take this example too literally: there is no quantifier called “*”. Rather, there are three logical quan-tifiers: “(” (for all…), “)” (there exists…), and “)1” (there is an unique…), and “*” stands here for one of thethem.

Page 24: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

20

The first predicate is true, but the second isn’t. "

Example 18 If A is an integer array with 50 entries, A1,A2, . . . ,A50, then we can assertthat all entries are nonzero as follows:

( i : N • 1 ' i ' 50 # Ai # 0

The entries are sorted in nondecreasing order if the following assertion holds:

( i : N • 1 ' i < 50 # Ai ' Ai+1

"

Example 19 For every number x and every number y , x + y is greater than or equal to x:

( x : N • (y : N • x + y & x

"

Example 20 The variable x is existentially quantified in the following predicates:

1. ) x : N • x < x + 1. “There is a number x which is less than x + 1.”

2. ) x : N • x = 3. “There is a number x which is equal to 3.”

3. ) x : N • x = x + 1. “There is a number x which is equal to x + 1.”

"

In general, the truth-table technique that we used in the last chapter for giving meaning toconnectives and reasoning about them is useless for the quantifiers, since the sets that boundvariables may range over are simply too large.

2.1 Substitution

Suppose that p is a predicate containing the free variable x. The quantified predicate “( x :S • p” asserts that p is true for every assignment of a value to x. Each theorem that followsfrom “( x : S • p” is obtained by substituting a term t for x in p. The notion of substitutionis precise, and depends on all the details of the language of logic and sets. We write p[t/x]to denote predicate p with term t substituted for x. It may be read as “p with t for x”.Substitution is also defined on terms themselves: “u[t/x]” is the term that results fromsubstituting t for x in u.

A bound variable must sometimes be renamed prior to substitution. For example, thefollowing is a theorem about numbers:

( x : Z • )y : Z • x # y

This is true for all numbers, so why not specialise it? Let’s take advantage of its being trueof the specific number y . This allows us to conclude that

)y : Z • y # y

Thus, we have concluded that there is a number that is di!erent from itself: nonsense! Whathas gone wrong? The problem is the capture of a free variable: the free variable y comes intothe scope of )y : Z • . . ., and becomes a bound variable.

For this reason, the substitution t for x in p is restricted to substituting t for free occur-rences of x in p.

Page 25: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

21

2.2 Validity and Satisfiability

Any predicate has n arguments; if it has no arguments, then it is a proposition. If p is ann-place predicate, and values c1, c2, . . . , cn are assigned to each of the individual variables, theresult is a proposition. If p is true for every choice of arguments, then p is said to be valid.If the predicate is true is some, but not necessarily all, choices of arguments, then p is saidto be satisfiable, and the values c1, c2, . . . , cn which make p true are said to satisfy p.

Valid, satisfiable, and unsatisfiable predicates are the analogues of tautologies, contin-gencies, and contradictions in the language of propositions.

Example 21 1. The following predicate on x is valid:

)y : N • y > x

For any natural number x, there exists a larger one.

2. This predicate is satisfiable but not valid:

)y : N • y < x

For some natural numbers x there exist smaller ones, but not for the number 0.

3. An example of an unsatisfiable predicate is

)y : N • y < x ! y > x

For no natural number can we find a second one which is both larger and smaller thanit.

2.3 Properties of Quantifiers

Consider the predicate

) x : S • p # q

Is it equivalent to the predicate

() x : S • p)# () x : S • q)

Does one imply the other? Are they at all related? In this section, we give some fundamentalidentities that answer questions such as these.

First, what can be learned from a quantified predicate?If the assertion p(x) is true for every possible value of x in s, then ( x : s • p(x) is true;

otherwise, ( x : s • p(x) is false. It also follows that if ( x : s • p(x) is true, then we canchoose any term t in s, and p(t) will be true:

( x : s • p(x), t + s $ p(t)

If the assertion p(x) is true for at least one element of s, then ) x : s • p(x) is true; otherwise,it is false. It also follows that, for any term t in s, if p(t) is true, then so is ) x : s • p(x):

t + s,p(t) $ ) x : s • p(x)

Page 26: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

22

The negation of the predicate “( x : N • x > 3” is simply “¬( x : N • x > 3”. Can this besimplified at all? Regarding the universally quantified predicate as a generalised conjunctionis instructive:

¬( x : N • x > 3

! universal quantification as conjunction

¬(0 > 3 ! 1 > 3 ! 2 > 3 ! 3 > 3 ! . . .)! by De Morgan’s Law

¬(0 > 3) " ¬(1 > 3) " ¬(2 > 3) " ¬(3 > 3) " . . .! existential quantification as disjunction

) x : N • ¬(x > 3)

Thus, we have a generalised form of De Morgan’s Laws for the generalisation of the conjunc-tion and disjunction operators:

(¬( x : S • p)! () x : S • ¬p)(¬) x : S • p)! (( x : S • ¬p)

Example 22 Suppose that Person is the set of all people, and that if you don’t love some-one, then you hate them. Now, is it true that there is no one who loves everybody? Itis di"cult to say whether such a warm-hearted individual really doesn’t exist, but wecan draw some conclusions from supposing it to be true. First, we can formalise it as“¬) x : Person • (y : Person • x loves y”. Calculating, we obtain the following derivation:

¬) x : Person • (y : Person • x loves y

! by De Morgan

( x : Person • ¬(y : Person • x loves y

! by De Morgan

( x : Person • )y : Person • ¬(x loves y)

! by definition

( x : Person • )y : Person • x hates y .

So, our sentence means the same as “everybody hates someone”. A depressing reflectionon human nature. "

Example 23 For every pair of integers x and y , there exists a z such that x + z = y . Thiscan be formalised as

( x : Z • (y : Z • ) z : Z • x + z = y

or more simply as

( x : Z; y : Z • ) z : Z • x + z = y

or even more simply as

( x,y : Z • ) z : Z • x + z = y

This predicate is true of the integers, but not of the natural numbers. To prove this weneed to show that the following predicate is true:

¬( x,y : N • ) z : N • x + z = y

Page 27: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

23

We can simplify this by pushing the negation into the predicate:

¬( x,y : N • ) z : N • x + z = y

! by De Morgan

) x,y : N • ¬) z : N • x + z = y

! by De Morgan

) x,y : N • ( z : N • ¬(x + z = y)

! by definition

) x,y : N • ( z : N • x + z # y

Notice how the application of De Morgan’s Law to the multiple quantifier worked.

The predicate is now in a form where we can more easily prove that it is true. If we select1 for x and 0 for y , we have

( z : N • 1+ z # 0

which is obviously true, since 0 is not the successor of any natural number. "

When we negate a quantified predicate, what happens to the range of the bound variable?Consider the following:

¬( x : N • x2 + x % 2 > 0

! since ( x : S • p is the same as ( x : X • x + S # p

¬( x : Z • x + N# x2 + x % 2 > 0

! by De Morgan

) x : Z • ¬(x + N# x2 + x % 2 > 0)

! by propositional calculus

) x : Z • ¬(¬(x + N) " x2 + x % 2 > 0)

! by De Morgan

) x : Z • ¬¬(x + N) ! x2 + x % 2 > 0

! by double negation

) x : Z • x + N ! x2 + x % 2 > 0

! since ) x : S • p is the same as ) x : X • x + S ! p

) x : N • x2 + x % 2 > 0

Thus, when we negate a quantified predicate, the range of the quantification remains un-changed.

To prove a predicate of the type “( x : S • p” can be quite demanding. One has to givean argument which demonstrates the truth of p whatever the value of x. It is certainly notenough to give some examples of values of x for which it can be seen that p is true.

To disprove a predicate of the type “( x : S • p” is much easier. This is the same asproving “) x : S • ¬p”, and to do this one need find only a single y for which p is false. Wesay that such a y provides a counterexample to the statement that “( x : S • p”.

Page 28: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

24

Example 24 Show that the statement

( x : Z | x > 0 • x2 % 3, x + 2 & 0

is false. A single counterexample will su"ce, and an appropriate value is 32 . We have that

( 32 )

2 % 3, ( 32 )+ 2 = % 1

4 < 0

"

If a predicate occurs in a disjunction or conjunction within the scope of a quantifier, andnone of its variables are bound by the quantifier, then it can be removed from the scope ofthe quantifier.

Let N stand for a predicate in which the variable x does not occur free. We have thefollowing equivalences.

(( x : S • p ! N )! ((( x : S • p) ! N )(( x : S • p " N )! ((( x : S • p) " N )() x : S • p ! N )! (() x : S • p) ! N )() x : S • p " N )! (() x : S • p) " N )

Now suppose that the variable bound by a quantifier occurs in both predicates of a disjunctionor conjunction. There are laws for the quantifiers that are analogous to the associativity lawsfor disjunction and conjunction, and form the distributivity laws for the quantifiers.

(( x : S • p ! q)! ((( x : S • p) ! (( x : S • q))() x : S • p " q)! (() x : S • p) " () x : S • q))

Example 25 The universal quantifier does not distribute over disjunction:

(( x : S • p " q) -! ((( x : S • p) " (( x : S • q))

The left-hand side states that, whichever value of x we choose, either p is true or q is truefor that value. The right-hand side states that either p is true for every value of x, or q istrue for every value of x.

An example should su"ce to convince. It is certainly true that every number is either evenor odd. It is not true that either every number is even, or every number is odd.

Similarly, existential quantification does not distribute through conjunction. It is certainlytrue that there is a number that is even, and that there is a number that is odd. However,it is not true that there is a number that is both even and odd. "

Although universal quantification does not distribute through disjunction to yield an equiv-alent predicate, it does yield a stronger one:

(( x : S • p) " (( x : S • q)# (( x : S • p " q)

Similarly, although existential quantification does not distribute through conjunction to yieldan equivalent predicate, it does yield a weaker one:

() x : S • p ! q)# () x : S • p) ! () x : S • q)

Page 29: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

25

1. (( x : S • p(x))# p(c)2. p(c)# () x : S • p(x))3. (( x : S • ¬p)! (¬) x : S • p)4. (( x : S • p)# () x : S • p)5. () x : S • ¬p)! (¬( x : S • p)6. (( x : S • p ! N )! (( x : S • p) ! N7. (( x : S • p " N )! (( x : S • p) " N8. (( x : S • p) ! (( x : S • q)! (( x : S • p ! q)9. (( x : S • p) " (( x : S • q)# (( x : S • p " q)

10. () x : S • p ! N )! () x : S • p) ! N11. () x : S • p " N )! () x : S • p) " N12. () x : S • p ! q)# () x : S • p) ! () x : S • q)13. () x : S • p) " () x : S • q)! () x : S • p " q)

Figure 2.1: Logical relationships between quantifiers

2.4 Multiple Quantifiers

If universal and existential quantifiers are mixed, then their order is significant.

Example 26 The sequence “( x : S • )y : T • . . .” can be paraphrased informally as“No matter what value x in S is chosen, a value y in T can be found such that…” In thisquantifier sequence, since y is chosen after x, the value of y may depend on the value ofx. For example, no matter what number we choose, there is always a larger number:

( x : N • )y : N • y > x

In contrast, the sequence “)y : T • ( x : S • . . .” asserts that “A value y in T can bechosen so that no matter what value x in S is chosen,…” In this case, since y is bound first,the value of y must be specified independently of the value of x. For example, there is anumber which is greater than every other number:

)y : N • ( x : N • y > x

Notice that these two predicates are the same, except that the order of the quantifiers hasbeen reversed. Of course, the first of the predicates is true, and the second is false. Thisis a good illustration that the order is important. "

Since it doesn’t matter which order we choose for a sequence which contains all universal orall existential quantifiers, there is a simplified notation. Instead of writing

( x : S • (y : T • p

we write

( x : S ; y : T • p

There is a similar simplified notation for the existential quantifier.

Page 30: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

26

2.5 Problems

1. (Copi, Suppes, Woodcock) Symbolise the following:

(a) “Snakes are reptiles.”

(b) “Snakes are not all poisonous.”

(c) “Children are present.”

(d) “Executives all have secretaries.”

(e) “Only executives have secretaries.”

(f) “Only community charge payers may vote in local elections.”

(g) “Employees may use only the goods lift.”

(h) “Only employees may use the goods lift.”

(i) “All that glisters is not gold.” [Gray]

(j) “All estate agents are not the same.”

(k) “Not all estate agents are the same.”

(l) “None but the brave deserve the fair.”

(m) “Not every visitor stayed for dinner.”

(n) “Not any visitor stayed for dinner.”

(o) “Nothing in the house escaped the children.”

(p) “Some students are both intelligent and hardworking.”

(q) “No coat is waterproof unless it has been specially treated.”

(r) “Some medicines are dangerous only if taken in excessive amounts.”

(s) “All fruits and vegetables are wholesome and nourishing.”

(t) “Everything enjoyable is either immoral, illegal, or fattening.”

(u) “A lecturer is a good teacher if, and only if, he is both well-informed and entertain-ing.”

(v) “Only university lecturers and firemen are both vastly underpaid and indispensi-ble.”

(w) “Not every actor who is famous is talented.”

(x) “It simply isn’t true that every watch will keep good time if and only if it is woundregularly and not abused.”

(y) “Not every person who talks a great deal has a great deal to say.”

(z) “No car that is over ten years old will be mended if it is severely damaged.”

2. Symbolise the following predicates about the nature of elephants.

(a) “Any elephant is attractive, if it is neat and well-groomed.”

(b) “Some elephants are gentle and have been well trained.”

(c) “Some elephants are gentle only if they have been well groomed by every student.”

(d) “Some elephants called Jumbo are gentle if they have been well trained.”

(e) “Any elephant is gentle that has been well trained.”

Page 31: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

27

(f) “Any elephant called Jumbo that is gentle has been well trained.”

(g) “No elephant is gentle unless it has been well trained.”

(h) “Any elephant is gentle if it has been well trained.”

(i) “Any elephant has been well trained if it is gentle.”

(j) “Any elephant is gentle if and only if it has been well trained.”

(k) “Gentle elephants have all been well trained.”

(l) “All elephants are called either Jumbo or Dumbo.”

(m) “Every student must ride to graduation on an elephant.”

3. Symbolise the following predicates about the nature of time.

(a) “Every instant of time follows another.”

(b) “If two instants of time are not identical, then one follows the other.”

(c) “Time has no beginning.”

(d) “Time has no end.”

(e) “One instant is after a second instant only if the second is before the first.’

4. Symbolise the following predicates about the numbers.

(a) “There’s a number between 3 and 5.”

(b) “Given any number there’s a smaller one.”

(c) “There’s no biggest number.”

(d) “Addition is commutative.”

(e) “There are two numbers which are such that their product is less than their sum.”

(f) “No cube can be expressed as the sum of two other cubes (unless at least one ofthe three numbers is zero).”

(g) “If n > 2, the equation xn + yn = zn cannot be solved in integers x,y , z, with x,y , zall non-zero.”

5. (Korfhage) Identify the free and bound variables in each of the following.

(a) (( x : T • A(x))# ()y : U • B(x,y)).(b) A(x,y) ! () x : T • B(y))# ((y : U ; z : V • C(x,y , z)).(c) (( x : T • )y : U • A(y , x) ! ((y : V • C(y)))# B(x,y).(d) ( x : T ; y : U • A(z)# B(z).(e) A(x)# (B(y)# () x : T • C(y)# ((y : U • D(x)))).

6. In each of the following, perform the intended substitutions in the corresponding pred-icates in the last exercise, if the substitutions are legal.

(a) Substitute f (x, z) for x.

(b) Substitute z for x, and g(y , z) for y .

(c) Substitute y for x, and f (x,y) for y .

(d) Substitute x for z.

(e) Substitute f (y) for x, and f (y) for y .

Page 32: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

28

7. (Macbeth & Hodges) Express the following as faithfully as possible, using a predicatethat starts with a universal or existential quantifier.

(a) Every noise appals me.

(b) Something wicked this way comes.

(c) I have a strange a"rmity.

(d) Their candles are all out.

(e) He has no children.

(f) Murders have been performed.

(g) x is a tale told by an idiot.

(h) None of woman born shall harm Macbeth.

8. Formalise the following propositions. For example, “everyone is married” would beformalised as

( x : Person • )y : Person • married(x,y)

(a) There is someone who is married to everyone else.

(b) For every integer x there is an integer y such that the sum of x and y is 0.

(c) There is a number y , such that for every number x, the sum of x and y is 0.

(d) No x is less than 0.

9. Find a predicate p in which x occurs, and for which ( x : N • p and ) x : N • p are bothfalse.

10. Find a predicate p in which x occurs, and for which ( x : N • p and ) x : N • p are bothtrue.

11. Let the following be defined:

N (x) “x is nonnegative”E(x) “x is even”O(x) “x is odd”P(x) “x is prime”

Formalise the following:

(a) There is an even integer.

(b) Every integer is either even or odd.

(c) All prime integers are nonnegative.

(d) The only even prime is two.

(e) There is one and only one even prime.

(f) Not all integers are odd.

(g) Not all primes are odd.

(h) If an integer isn’t even, then it’s odd.

12. Give a counterexample to the assertion

() x : N • p) ! () x : N • q) $ ) x : N • p ! q

Page 33: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

29

13. Give a counterexample to the assertion

( x : N • p " q $ (( x : N • p) " (( x : N • q)

14. Let A be a two-dimensional integer array with 20 rows (indexed from 1 to 20), and30 columns (indexed from 1 to 30). Using the predicate calculus, make the followingassertions:

(a) All entries of A are nonnegative.

(b) All entries of the 4th and 15th rows are positive.

(c) Some entries of A are zero.

(d) The entries of A are sorted into row-major order; that is, the entries are in orderwithin rows, and every entry of the ith row is less than or equal to every entry ofthe (i + 1)th row.

15. There is another quantifier

)1 x : s • p

which means “there is a unique x in s, such that p holds”.

(a) Define this quantifier in terms of universal and existential quantification.

(b) Universal quantification is a generalisation of conjunction; existential quantifica-tion is a generalisation of disjunction. Of what combinator of propositions is theunique quantifier a generalisation?

16. Prove the following laws about quantifiers:

(a) () x : S • p # q)! (( x : S • p)# () x : S • q)(b) (( x : S • p # q)# ((( x : S • p)# (( x : S • q))(c) (() x : S • p)# () x : S • q))# () x : S • p # q)(d) (( x : S • p # N )! () x : S • p)# N

(e) () x : S • N # p)! N # () x : S • p)(f) () x : S • p # N )! (( x : S • p)# N

Page 34: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Chapter 3

Set Theory

3.1 Sets

A fundamental concept in all branches of mathematics is that of a set. Most mathematiciansbelieve that it is possible to express all of mathematics in the language of set theory; indeed,most modern software engineers agree that mathematics forms the basis of software engi-neering also. In this chapter, we look at the basic ideas and the language of set theory. Thischapter draws on material from Lipschutz, Stanat, and Woodcock.

Section 3.17 contains a brief description of Axiomatic Set Theory; this may be skipped ata first reading without any loss.

Intuitively, a set is any well-defined list, collection, or class of objects. The objects in sets,as we shall see from our examples, can be anything: numbers, people, letters, rivers, evensets themselves. These objects are called the elements or members of the set.

Example 27 Although we shall study sets as abstract entities, the following are ten par-ticular examples of sets.

1. The numbers 1,3,7,4 and 10.

2. The solutions of the equation x2 % 3, x % 2 = 0.

3. The vowels of the alphabet: a, e, i,o, and u.

4. The people living on the earth.

5. The students Robert ,Catherine, and Jonathan.

6. The students who are absent from the class.

7. The countries England, France, and Denmark.

8. The capital cities of Europe.

9. The numbers 2,4,6,8, . . .10. The rivers in England.

"

Notice that the sets in the odd examples are defined by listing their members; and the setsin the even examples are defined by stating properties, that is by specifying a predicate thatcharacterises when an object is a member of the set. Since we enumerate the sets in the oddexamples, we call that style of specification set extension; since we use a rule to understandwhich elements are in the sets in the even examples, we call that style of specification setcomprehension.

30

Page 35: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

31

3.2 Notation

Sets will usually be denoted by capital letters, or words starting with a capital:

A,B,X ,Y , . . . ,Euclidean,River ,Person, . . .

The elements in our sets will usually be represented by lower case letters

a,b, x,y , . . .

We can define a particular set in extension by listing its members, separated by commas andenclosed in braces “{}”. For example, let A consist of the numbers 1,3,7, and 10; we write

A = {1,3,7,10}.

But if we want to define a particular set by stating properties which its elements must satisfy,we write

B = { x | x is even }

which is read “B is the set of numbers x such that x is even”. We call this a set comprehensionterm. The fact that the elements of this set are numbers may be inferred from the fact thatthe elements must be even. However, this informality won’t do when we have to be precise.We shall specify the type of the elements of a set in the following way

B = { x : N | x is even }

where N denotes the set of counting numbers, 1,2,3, . . .Example 28 In order to illustrate the use of the above notation, we rewrite the sets in ourexample. We denote the sets by A1,A2, . . . ,A10, respectively.

1. A1 = {1,3,7,10}.2. A2 = { x : N | x2 % 3, x % 2 = 0 }3. A3 = {a, e, i,o,u}.4. A4 = { x : Person | x is living on the earth }5. A5 = {Robert ,Catherine, Jonathan}.6. A6 = { x : Student | x is absent from class }.7. A7 = {England, France,Denmark}.8. A8 = { x : CapitalCity | x is in Europe }.9. A9 = {2,4,6,8, . . .}.

10. A10 = { x : River | x is in England }."

If an object x is a member of a set A, that is, A contains x as one of its elements, then wewrite

x + A

which is read “x belongs to A”, or “x is in A”. If on the other hand, an object x is not a memberof a set A, that is, A does not contain x as one of its elements, then we write

x $ A

Page 36: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

32

Example 29

1. Let A = {a, e, i,o,u}. Then a + A,b $ A, e + A, f $ A.

2. Let B = { x : N | x is even }. Then 3 $ B,6 + B,11 $ B,14 + B.

"

Notice that we have not given either a formal definition of a set, or a basis for decidingwhen an object is a member of a set. Any mathematical theory must ultimately rest on someprimitve or undefined notions; the notion of “set” and the relation “is an element of” arethe primitive concepts of set theory. As a consequence of not having definitions of theseconcepts, we have no formal test to determine whether or not something is a set, or whetheror not a given object is an element of a specified set. Because there is no test, we must relyon a common understanding of the meaning of the terms. We shall return to this point laterin this chapter.

Example 30 Almost anything which would be called a set in ordinary conversation is anacceptable set in the mathematical sense.

1. The set of nonnegative integers less than 4. This is a finite set with four members:0,1,2, and 3.

2. The set of books in the Bodleian Library at the present time. It would be di"cult tolist the members of this set because of the constant flux in the library’s collection;the di"culties are practical rather than theoretical.

3. The set consisting of people who spoke to Bertrand Russell on the 7 June 1906.This set is finite and probably contains at least one element. It has the alarmingcharacteristic that there is probably no way of determining its membership; thisdoes not detract from its acceptability as a set.

4. The set of live dinosaurs in the Pitt-Rivers Museum. Assuming that there have beenno sinister experiments in the Pitt-Rivers Museum, this set has the property that ithas no members: it is called the null or empty set.

5. The set of integers greater than 3. Even though this set is infinite, there is no di"cultyin in determining whether or not a specified integer is a member.

6. The set of all C++ programs which can be displayed on a single screen. This set is(presumably) rather large, but certainly finite; a correctly operating C++ compiler candetermine whether or not a program is a member of this set.

7. The set of all programs written in C++ which would halt if run for a su"cient time ona computer with unbounded storage. This set is not finite, because no matter howlarge a program we write, it is possible to write a longer program by inserting anotherstatement (the statement need not perform any useful task). Although there is a max-imum size of program that can be run on any particular computer, there is nothinginherent in the C++ language that limits the size of a program. Computability theoryhas established that there is no algorithm that can exist which determines whetheran arbitrary program is an element of this set; such a set is called undecidable.

8. The set of true propositions about the integers. This is an infinite set, as we caneasily demonstrate by considering propositions of the form

3+ 1 = 4.

Furthermore, there are propositions that are conjectured to be true, but which havenever been proved or disproved.

9. The set with two members, one of which is the set of even integers, and other the setof odd integers. Thus, sets can have other sets as members.

"

Page 37: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

33

Sometimes, we will want to construct sets with more complicated terms than the comprehen-sion notation above allows. In this case, we add a fat dot • followed by an extra expressionto the comprehension term. Thus, for example, the set of squares of even numbers might bewritten

{ x : N | x is even • x2 }

For further examples of this form of comprehension term, see Chapter 4.

3.3 Finite and Infinite Sets

Sets can be finite or infinite. Intuitively, a set is finite if it consists of a specific numberof di!erent elements, that is, if in counting the di!erent members of the set the countingprocess can come to an end. Otherwise the set is infinite. Later, we can define this moreprecisely.

Example 31

1. Let M be the set of the days of the week. Then M is finite.

2. Let N = {2,4,6,8, . . .}. Then N is infinite.

3. Let P = { x : River | x is on Earth }. Although it may be di"cult to count the numberof rivers in the world, P is still a finite set.

4. Suppose that statement labels in a (rather old-fashioned) programming languagemust be either a single alphabetic symbol or a single decimal digit. The first setis

{A,B,C , . . . ,Z},

and has precisely 26 elements; the second set is

{0,1,2, . . . ,9},

and has precisely ten elements. Since they do not share any elements in common,the total number of elements in the set of possible statement labels in 36.

5. A variable name in some versions of the programming language BASIC must be eitheran alphabetic symbol or an alphabetic symbol followed by a single decimal digit.There are 286 elements in the set of BASIC possible variable names .

6. Consider the “four cubes” puzzle. This involves four cubes each of whose faces ispainted in one of four di!erent colours. The puzzle is to stack the cubes in such away that each vertical side of the stack contains squares of all four colours. The orderof the cubes in the stack is clearly unimportant, and we do not wish to distinguishbetween arrangements which are identical except for rotations. We can count thenumber of significantly di!erent arrangements as follows:

(a) The first cube can be positioned in any of three di!erent ways, because there arethree pairs of faces which can be made the top and bottom surfaces.

(b) For each remaining cube, one of the six faces must be chosen as the bottom,and then one of four possible rotational positions must be chosen. This gives24 di!erent ways to position each of the last three cubes in the stack.

Thus, there are 3 , 24 , 24 , 24 = 41 472 di!erent arrangements. (You might careto write a program that solves the four cubes puzzle.)

"

Page 38: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

34

3.4 Equality of Sets

Set A is equal to set B if they both have precisely the same members, that is, if every elementwhich belongs to A also belongs to B and if every element which belongs to B also belongsto A. We denote the equality of sets A and B by

A = B

Example 32

1. Let A = {1,2,3,4} and B = {3,1,4,2}. Then A = B, that is, {1,2,3,4} = {3,1,4,2},since each of the elements 1,2,3, and 4 of A belongs to B, and each of the elements3,1,4,2 of B belongs to A. Note therefore that a set does not change if its elementsare rearranged.

2. Let C = {5,6,5,7} and D = {7,5,7,6}. Then C = D, that is {5,6,5,7} = {7,5,7,6},since each element of C belongs to B, and each element of D belongs to C . Note thata set does not change if its elements are repeated. Also, the set {5,6,7} equals C andD.

3. Let E = { x : N | x2 % 3, x = %2 }, F = {2,1}, and G = {1,2,2,1}. Then E = F = G.

"

The formal statement of when equality holds between sets is

A = B ! (( x : X • x + A ! x + B).

In the universal quantification we have to state the set for the range of the bound variable(“X ” in the above display). This should be chosen so that it contains both sets.

Example 33 Suppose that we have the following definitions:

Zeroes = { x : N | x2 % 3, x + 2 = 0 }SmallNums = {1,2}.

Now, our statement of equality gives us

Zeroes = SmallNums ! (( x : Z • x + Zeroes ! x + SmallNums)

Since both Zeroes and SmallNums are sets of things of type Z, we use Z in the quantifi-cation. Actually, both sets contain only natural numbers, although this is perhaps notimmediately evident in the case of Zeroes, so we could have used N. "

3.5 Empty Set

It is convenient to introduce the concept of the empty set, that is, a set which contains noelements. This set is sometimes called the null set. We say that such a set is void or empty,and denote it by the symbol ..

Example 34

1. Let A be the set of people in the world who are older than 200 years. To the best ofmy knowledge, A is the empty set.

2. Let B = { x : N | x2 = 4 ! x is odd }. Then B is the empty set.

"

Page 39: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

35

3.6 Subsets

If every element in a set A is also a member of a set B, then A is called a subset of B. Morespecifically, A is a subset of B if x in A implies x in B. We denote this relationship by writing

A / B

which can also be read “A is contained in B”.

Example 35

1. The set C = {1,3,5} is a subset of D = {5,4,3,2,1}, since each number 1,3, and 5belonging to C also belongs to D.

2. The set E = {2,4,6} is a subset of F = {6,2,4}, since each number 2,4, and 6belonging to E also belongs to F . Note, in particular, that E = F . In a similar manner,it can be shown that every set is a subset of itself.

3. Let G = { x : N | x is even }, that is, G = {2,4,6, . . .}, and let F = { x : N |x is a positive power of 2 }, that is, let F = {2,4,8,16, . . .}. Then F / G, that is Fis contained in G.

4. The set of women is a subset of the set of all humans.

5. The set {1,2,3,4,5} is a subset of the set { x : Z | 0 < x < 6 }."

We can state the definition of subset more formally:1

A / B ! (( x : X • x + A # x + B).

Theorem 1 Two sets A and B are equal if they each contain the other. That is, A = B, if andonly if A / B and B / A.

Proof

1. (the “only if” part) Suppose that A = B. Then, every member of A is also a member of B,so A is contained in B. By a similar argument, suppose that B = A, then every memberof B is also a member of A, and so B is contained in A. This establishes the fact that

(A = B # A / B) ! (B = A # B / A).

Now, since equality is symmetric, and by using a little propositional calculus, we have

A = B # A / B ! B / A.

2. (the “if” part) Suppose that A / B ! B / A. We have that

A / B ! B / A

! by definition

1The universal quantification may also be written as

( x : X | x + A • x + B,

or even in the rather succinct form as

( x : A • x + B.

Page 40: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

36

(( x : X • x + A # x + B) ! (( x : X • x + B # x + A)

! by predicate calculus

( x : X • x + A # x + B ! x + B # x + A

! by propositional calculus

( x : X • x + A ! x + B

Thus, A and B have exactly the same elements.

Theorem 2 The subset relationship is reflexive, in that for any set A, we have that A / A.

Proof

A / A

! by definition

( x : X • x + A # x + A

! since P # P is a tautology

( x : X • true

! by predicate calculus

true

Theorem 3 Since the empty set has no members, it is trivially a subset of every other set.

Proof

. / A

! by definition

( x : X • x + . # x + A

! but x + . must be false

( x : X • false # x + A

! by propositional calculus

( x : X • true

! by predicate calculus

true

Theorem 4 The empty set is unique.

Proof Before we can prove this fact we had better be a bit more precise. Is the empty setunique? The fact that we have a type system in our language means that the empty set ofcars is di"erent from the empty set of elephants, if “cars” and “elephants” are di"erent types.However, could there be two di"erent empty sets of elephants? The answer is obviously “no”,but it is already a consequence of the mathematics that we have set up so far. Suppose thatthe two di"erent empty sets are. and.0. Now, from our previous theorem, we have that the

Page 41: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

37

empty set is a subset of every other set; in particular we have that . / .0. But we must alsohave the same property for .0. Thus we have

. /.0 ! .0 / ..

Thus, we can conclude that . =.0.

Theorem 5 The subset relation is transitive, that is

A / B ! B / C # A / C .

Proof The proof of this fact is very simple, since it follows directly from the fact that implica-tion is transitive. Suppose that A / B and B / C. From A / B, it follows that

x + A # x + B.

From B / C, it follows that

x + B # x + C .

Therefore, by the transitivity of implication (also called hypothetical syllogism) we have

x + A # x + C .

Since this argument has been conducted without making any assumptions about x, it followsthat

( x : X • x + A # x + C ,

and so A / C.

If A is a subset of B, then we can also write

B 1 A

which reads “B is a superset of A” or “B contains A”.

3.7 Proper Subset

Since every set A is a subset of itself, we call B a proper subset of A if, first, B is a subset ofA and, secondly, if B is not equal to A. More briefly, B is a proper subset of A if

B / A ! B # A

We will sometimes write B 2 A to mean that B is a proper subset of A.

Example 36

1. The set of natural numbers is a proper subset of the set of integers.

2. The set of even integers is a proper subset of the set of integers.

"

Page 42: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

38

3.8 Sets of Sets

It sometimes will happen that the objects of a set are sets themselves; for example, the setof all subsets of A.

Example 37

1. The set {{2,3}, {2}, {5,6}} is a set of sets. Its members are {2,3}, {2}, and {5,6}."

It is not possible that a set has some members which are sets themselves and some whicharen’t. In fact, the type system will make sure that all the members of a set are the same kindof object.

3.9 Power Set

The family of all the subsets of any set S is called the power set of S . We denote the powerset of S by

P S .

Example 38

1. Let M = {a,b}, then PM = {{a,b}, {a}, {b},.}.2. Let T = {4,7,8}, then PT = {T , {4,7}, {4,8}, {7,8}, {4}, {7}, {8},.}.3. Let A =., then PA = {.}.4. Let A = {1}, then PA = {., {1}}.5. Let A = {1,2}, then PA = {., {1}, {2}, {1,2}}.6. If A is any (finite or infinite) set of natural numbers, then A + PN. If A is finite, thenPA is also finite; otherwise, PA is infinite.

"

If a set is finite, say S has n elements, then the power set of S can be shown to have 2n

elements. Observe, therefore, that for all sets S , we have that S 2 P S .

3.10 Disjoint Sets

If sets A and B have no elements in common, that is, if no element of A is in B, and no elementof B is in A, then A and B are disjoint.

Example 39

1. Let A = {1,3,7,8} and B = {2,4,7,9}. Then A and B are not disjoint, since 7 is inboth sets, that is, 7 + A and 7 + B.

2. Let A be the positive numbers and let B be the negative numbers. Then A and B aredisjoint, since no number is both positive and negative.

3. Let E = {x,y , z} and F = {r , s, t}. Then E and F are disjoint.

"

Page 43: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

39

3.11 Venn’s Diagrams

A simple but instructive way of illustrating the relationships between sets is in the use ofVenn’s diagrams. Here we represent a set by a simple plane area, usually bounded by a circleor an ellipse.

Example 40

1. Suppose that A 2 B. Then A and B can be described by the diagram:

B

A

2. Suppose that A and B are not comparable. Then A and B can be represented by thediagram on the left if they are disjoint, and by the diagram on the right if the are notdisjoint:

A

B

A

B

3. Let A = {a,b, c,d} and B = {c,d, e, f }. Then we illustrate these sets with a Venndiagram of the form:

A

B

a

b

c e

d

f

"

Page 44: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

40

3.12 Union

The union of sets A and B is the set of all elements which belong to A or to B or both. Wedenote the union of A with B by

A3 B

which is usually read “A union B”.

Example 41

1. In the following Venn diagram, the union of the two sets A and B contains every pointmarked:

A

B

a

b

c e

d

f

2. Let S = {a,b, c,d} and T = {f ,b,d,g}, then

S 3 T = {a,b, c,d, f ,g}

3. Let P be the set of positive real numbers and let Q be the set of negative real numbers.Then P 3Q consists of all the real numbers except zero.

"

The union of A with B may be defined concisely by

A3 B = { x : X | x + A " x + B }

Now, it follows directly from the definition of the union of two sets that union is a commu-tative operator, and that both A and B are subsets of A3 B

3.13 Intersection

The intersection of set A with set B is the set of elements which are common to A and to B.It is denoted by

A4 B

Example 42

1. In the following Venn diagram, the intersection of the two sets A and B contains onlythe points c and d :

Page 45: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

41

A

B

a

b

c e

d

f

2. Let S = {a,b, c,d} and T = {f ,b,d,g}. Then

S 4 T = {b,d}

3. Let V = {2,4,6, . . .}, and let W = {3,6,9, . . .}, then

V 4W = {6,12,18, . . .}

"

Now, it follows directly from the definition of the intersection of two sets that A4B and B4Aare the same. Furthermore, each of the sets A and B contain s A4 B as a subset. If A and Bhave no elements in common, then they are disjoint. This may be formalised by saying thattheir intersection is empty.

The intersection of A and B may be defined formally:

A4 B = { x : X | x + A ! x + B }

3.14 Di!erence

The di!erence between two sets A and B is the set of elements which belong to A but not toB; we denote it by

A \ B

which is read “A minus B”.Example 43

1. The di!erence between the two sets A and B contains only the points a and b:

A

B

a

b

c e

d

f

Page 46: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

42

2. Let S = {a,b, c,d} and T = {f ,b,d,g}, then

S \ T = {a, c}

3. Let R be the set of real numbers and let Q be the set of rational numbers. Then R\Qconsists of the irrational numbers.

"

The di!erence of A and B may be defined concisely

A \ B = { x : X | x + A ! x $ B }

The set A contains A \ B as a subset.

3.15 Properties of Set Operations

Theorem 6 The operations of union and intersection are commutative and associative; thatis, for arbitrary sets A, B, and C,

1. A3 B = B 3A

2. A4 B = B 4A

3. (A3 B)3 C = A3 (B 3 C)

4. (A4 B)4 C = A4 (B 4 C)

Proof The proofs of these assertions rely on the commutativity and associativity of disjunctionand conjunction. We give two proofs

(1) Let x be an arbitrary element of the set X . Then

x + A3 B

! definition of 3x + A " x + B

! commutativity of "x + B " x + A

! definition of 3x + B 3A

Thus, since x is arbitrary, we have proved that

( x : X • x + A3 B ! x + B 3A,

and hence that A3 B = B 3A.

(3) Let x be an arbitrary element. Then

x + A3 (B 3 C)

! definition of 3

Page 47: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

43

x + A " x + B 3 C

! definition of 3x + A " (x + B " x + C)! associativity of "(x + A " x + B) " x + C

! definition of 3x + A3 B " x + C

! definition of 3x + (A3 B)3 C

Since x was arbitrary, it follows that

( x : X • x + A3 (B 3 C)! x + (A3 B)3 C ,

and hence that A3 (B 3 C) = (A3 B)3 C.

Theorem 7 The set operations of union and intersection distribute over each other; that is, forarbitrary sets A,B, and C,

1. A3 (B 4 C) = (A3 B)4 (A3 C)

2. A4 (B 3 C) = (A4 B)3 (A4 C)

There are many more properties of the set operations, and some of them are listed in thefigure 3.1.

3.16 Generalised Operations

The binary operations of union and intersection may be regarded as special cases of moregeneral operations which form unions and intersections of any number of sets. These moregeneral operations are defined over sets of sets. If A is a set of sets, then

%A is its generalised

union: it contains all objects which are members of some member of A. The set&

A is thegeneralised intersection of A: it contains those objects which are members of all member sofA. Formally,

%A = { x : X | () S : A • x + S) }&A = { x : X | (( S : A • x + S) }.

3.17 Axiomatic Set Theory

This section may be skipped at a first reading without any loss. It contains a brief accountof the foundations of set theory, and although interesting, it is not essential reading.

So far, we have been content to use an intuitive notion of ‘set’. Roughly speaking, a setis any collection of objects, mathematical or otherwise. Actually, the development of settheory has been greatly advanced by the consideration of various (now famous) paradoxes,which make it clear that such an intuitive idea of a set needs to be carefully circumscribedin order to make it precise and, as far as possible, paradox-free.

The version of set theory that we adhere to is known as the Zermelo-Fraenkel System.Before we consider this system, we review the idea of an axiomatic theory; we then considerthe famous (or infamous) paradoxes.

Page 48: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

44

(a) A3A = A(b) A4A = A(c) A3. = A(d) A4. =.(e) A \ B / A(f) A / B ! C / D # A3 C / B 3D(g) A / B ! C / D # A4 C / B 4D(h) A / A3 B(i) A4 B / A(j) A / B # A3 B = B(k) A / B # A4 B = B(l) A \. = A

(m) A4 (B \A) =.(n) A3 (B \A) = A3 B(o) A \ (B 3 C) = (A \ B)4 (A \ C)(p) A \ (B 4 C) = (A \ B)3 (A \ C)

Figure 3.1: Properties of the Set Operators.

3.17.1 Axiomatics

In an axiomatic development of a branch of mathematics, one begins with:

• undefined terms;

• undefined relations;

• axioms relating the undefined terms and undefined relations.

Then, one develops theorems based upon the axioms and definitions. For example, in PlaneEuclidean Geometry, the undefined terms are “points” and “lines”; the undefined relation is“point on a line”; and two of the axioms are

1. Two di!erent points are on one and only one line.

2. Two di!erent lines cannot contain more than one point in common.

3.17.2 Cantor’s and Russell’s Paradoxes

Suppose that we allow ourselves the luxury of using sets just as we please. Consider the setof all sets U; that is,

U = {X | X is a set }.

Now, each subset of U is a set, and hence each subset of U is a member of U. Now for anyset X , the set of all subsets of X is the power set of X , denoted PX . Thus, we have that

PU /U

Page 49: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

45

because each subset of U is a member of U. On the other hand, it is a general fact aboutsets that the power set of X is always bigger than X itself. This is a contradiction, and formsCantor’s paradox.

Some sets are members of themselves (for instance, the set M of all mathematical con-cepts: this is itself a mathematical concept, and hence is a member of M itself) and somesets sre mot members of themselves (for instance, the set of natural numbers less than orequal to 10 is not itself a natural number less than or equal to 10).

We define a particular set R as follows:

R = {X | X $ X }.

That is, R is the set of all sets which are not members of themselves.So, is R an element of R? If R + R, then R belongs to the set of all sets which are not

members of themselves; that is, R is not a member of itself: R $ R. If R $ R, then R is not amember of itself, and hence lies in the set of all such sets, that is, in R: thus R + R. In eithercase, we reach a contradiction: Russell’s contradiction.2

3.17.3 The Zermelo-Fraenkel Axioms for Set Theory

These paradoxes arise because we have allowed ourselves too much freedom in defining sets.In the following axiom system for set theory, we shall give various conditions under whichwe can define a set: unless the axioms permit it, a set is not properly defined. In particular,we shall not be able to talk about “the set of all sets”, or “the set of all sets which do notbelong to themselves”. In this way, both Cantor’s and Russell’s paradoxes are avoided. Thereis no guarantee that other paradoxes will not arise; however, none has been found to date.

The axioms define a certain “universe” of sets, which consists of sets and nothing else.The elements of a set are always other specified sets in the universe. So, if we wish to describeany mathematical concept in terms of the universe, then that concept must be representedby a genuine set.

In the axiomatic development of set theory, we have that “element” and “set” are theundefined terms; “membership” is the undefined relation, and two of the axioms are

Axiom of Extension Two sets A and B are equal if and only if every element in A belongsto B and every element in B belongs to A.

A = B ! (( x : X • x + A ! x + B)

The second axiom (which is really three axioms in one) guarantees the existence of one set,the empty set, and also the right to two basic constructions: singletons and doublets.

Existence of Elementary Sets There is a set . with no members, that is,

( x : X • x $..

If A and B are any sets, then there are also the sets {A} and {A,B}.At this point, we can write down quite a long list of sets whose existence is guaranteed,

but each has no more than two elements. the third axiom allows us to form the unions ofsets.

2A nice interpretation of Russell’s paradox is the man who asserts

“I am lying.”Is he lying or is he telling the truth?

Page 50: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

46

Axiom of Union Given any set A, then there is a set%

A which has as its members preciselythe members of the members of A. More formally,

x + A ! ()Y : A • x + Y ).

Thus,%

A is the union of those sets which are members of A. For example, if A and B are sets,then

%{A,B} is the union of A and B, normally written A3 B. We can unravel the definition

to deduce

x +%{A,B}! x + A " x + B.

To be able to write down the intersection of two sets, we need to be able to write down a setcomprehension term, and there is no axiom yet that allows us to do that. The next axiompermits us to specify a subset of a given set, and it is the most important axiom, in that itprovides the main method of constructing new sets from old ones.

Axiom of Specification Let P(x) be any predicate and let A be any set. Then there exists aset

B = {a : A | P(a) },

consisting of precisely those members of A which satisfy the given predicate.Now, notice that we cannot write down the problematic set

R = {X | X $ X }

and appeal to this axiom for its existence. The di"culty is that we have failed to supply theset from which to draw the elements in the comprehension term. We have to write somethingof the form

R = {X : A | X $ X }

Now consider the paradox. Suppose that R + R: we deduce that

R + A ! R $ R.

Thus, we have the implication

R + R # R + A ! R $ R.

Suppose on the other hand that R $ R. If R + A, then we have that R + R, proving theimplication

R $ R ! R + A # R + R.

These two implications are contradictory, but we have not found a paradox, since we haven’tconsidered that our assumption that R + A might be false. In the case that R $ A, we havethat

R $ R ! R $ A # R $ R,

which is entirely consistent with the first deduction.The axioms now allow us to write down many finite sets, but as yet no infinite ones.

Page 51: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

47

Axiom of Infinity There is an infinite set.The next two axioms allow us to write down many infinite sets.

Axiom of Power Sets Given any set A there is a set PA whose members are all the subsetsof A; that is

X + PA ! X / A.

One way to construct new infinite sets is to write down a set whose elements are labelled byan existing set.

Axiom of Replacement Suppose that A is any set, and that f is any rule that specifies adefinite value f (X ) for each member X of A. Then there is a set

{X : A • f (X ) }

whose elements are precisely the sets generated by the rule.For example, if we take our set A to be the natural numbers N, then if we have a rule f

which generates the sets A1,A2, and so on (that is, f (i) = Ai ), then we are allowed by theAxiom of Replacement to write down the set

{ i : N • f (i) } = {A1,A2,A3, . . . }.

The last two axioms of Zermelo-Fraenkel set theory are sometimes regarded as being contro-versial. The first allows us to choose elements from nonempty sets in a systematic way.

Axiom of Choice Suppose that A is any set whose members are nonempty (that is, . $ A).Then there is a function f : A5%

A such that f (X ) + X , for each X + A.What f does is to choose for us the element f (X ) from X for each set X in A. Since none

of the X ’s are empty, then this seems perfectly reasonable, particularly so if A is a finite set.For instance, if A = {A1,A2,A3,A4}, then all f does is to choose four elements

f (A1) + A1, f (A2) + A2, f (A3) + A3, f (A4) + A4.

The controversial nature of the axiom arise from its generality: it applies to any set A, howeverbig it is. However, almost every mathematician accepts the Axiom of Choice nowadays.

All of the axioms so far have extended the notion of set, by allowing us to define moreand more sets. The final axiom restricts the notion.

Axiom of Foundation Given any nonempty set A, there is an element X + A such thatX 4A =..

This axiom rules out the possibility of having an infinite descending sequence of elementssuch as

. . .Xn+1 + Xn + . . . + X2 + X1,

for then the set { i : N • Xi } would contradict the axiom. It also rules out the possibility of aset A being a member of itself: consider A = {A}.

There are other axioms which are not listed here.

Page 52: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

48

3.18 Problems

1. Let M = {r , s, t}. State whether each of the following is correct or incorrect:(a) r + M (b) r / M(c) {r} + M (d) {r} /

2. Specify the following set explicitly:

(a) The set of nonnegative integers less than 5.

(b) The set of positive multiples of 12 which are less than 65.

3. State in words and then write in enumeration:

(a) A = { x : N | x2 = 4 }(b) B = { x : N | x % 2 = 5 }(c) C = { x : N | x > 0 ! x < 0 }(d) D = { x : N | x is a letter in the word “correct” }(e) { x : Z | 3 < x < 12 }(f) DecimalDigit = { x : N | 0 ' x ' 9 }(g) { x : Z | x + DecimalDigit }(h) { x : Z | x = 2 " x = 5 }.

4. Define each of the following at set comprehension terms:

(a) The set of integers between 0 and 100.

(b) The set of integer multiples of 10.

(c) The set of human fathers.

(d) The set of tautologies.

(e) The set of letters a,b, c,d , and e.

(f) The even numbers {2,4,6,8, . . .}.(g) The countries in the United Nations.

(h) The set of Prime Ministers Wilson,Callaghan,Thatcher , and Major .

5. Which sets are finite?(a) The months of the year. (b) {1,2,3, . . . ,99,100}.(c) The people living on the earth. (d) { x : N | x is even }.(e) {1,2,3, . . .}.

6. Which of these sets are equal?

(a) { x : Letter | x is in the word “follow” }.(b) The letters which appear in the word “wolf ”.

(c) { x : Letter | x is in the word “flow” }.(d) The letters which appear in the word “flower”.

(e) The letters f , l,o, and w .

(f) { x : Z | x is even and x2 is odd }(g) { x : Z | ()y : Z • x = 2, y) }(h) {1,2,3}

Page 53: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

49

(i) {0,2,%2,3,%3,4,%4, . . .}(j) { x : Z • 2, x }(k) {3,3,2,1,2}(l) { x : Z | x3 % 6, x2 % 7, x % 6 = 0 }

7. Which of these sets is the empty set?

(a) A = { x : Letter | x precedes a in the alphabet }.(b) B = { x : N | x2 = 9 and 2, x = 4 }.(c) C = { x : N | x # x }.(d) D = { x : N | x + 8 = 8 }.(e) {n : Z | n > 2 ! () x,y , z : N | x # 0 ! y # 0 ! z # 0 • xn + yn = zn) }.

8. List all the subsets of the following sets

(a) {1,2,3} (b) {1, {2,3}}(c) {{1, {2,3}}} (d) {.}(e) {., {.}} (f) {{1,2}, {2,1,1}, {2,1,1,2}}(g) {{.,2}, {2}}

9. Let the following sets of figures in the Euclidean plane be defined:

Q = { x : Euclidean | x is a quadrilateral }H = { x : Euclidean | x is a rhombus }R = { x : Euclidean | x is a rectangle }S = { x : Euclidean | x is a square }

Which of these sets are proper subsets of the others?

10. Does every set have a proper subset?

11. Prove that if A is a subset of the empty set ., then A =..

12. How does one prove that a set A is not a subset of a set B? Prove that A = {2,3,4,5} isnot a subset of B = { x : N | x is even }.

13. Let A,B, and C be sets. If A + B and B + C , is it possible that A + C . Give an examplein support of your assertion.

14. Let A,B, and C be sets. Prove or disprove the following assertion

A / B ! B $ C # A $ C .

15. Let V = {d},W = {c,d},X = {a,b, c},Y = {a,b},Z = {a,b,d}. Determine whether each

of the following statements is true or false:

(a) Y / X (b) Z -1 Z (c) W -1 V(d) V / X (e) W # Z (f) Y -/ Z(g) Z 1 V (h) X = W (i) V -/ Y(j) W / Y

16. Let A = {r , s, t ,u,v ,w},B = {u,v ,w, x,y , z},C = {s,u,y , z},D = {u,v},E = {s,u}, andF = {s}. Let X be an unknown set. Determine which sets A,B,C ,D,E , or F can equal X

in each of the following cases:(a) X / A and X / B. (b) X -/ B and X / C .(c) X -/ A and X -/ C . (d) X / B and X -/ C .

Page 54: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

50

17. Let A be a subset of B and let B be a subset of C ; suppose that a + A,b + B, c + C , and

suppose that d $ A, e $ B, f $ C . Which statements must be true?(a) a + C , (b) d + B, (c)(d) e $ A, (e) c + A, (f)

18. In the Venn diagrams below, shade the set A3 B:

A B

A

BA

B

A

B

19. Let A = {1,2,3,4},B = {2,4,6,8}, and C = {3,4,5,6}. Find(a) A3 B (b) A3 C (c) B(d) B 3 B (e) (A3 B)3 C (f) A

20. Prove that A and B are subsets of A3 B.

21. Prove that set union is idempotent, that is, that A = A3A.

22. Prove that A = A3..

23. Prove that if A3 B =., then both A and B are empty.

24. In the Venn diagrams below, shade the set A4 B:

A B

A

BA

B

A

B

25. Let A = {1,2,3,4},B = {2,4,6,8}, and C = {3,4,5,6}. Find(a) A4 B (b) A4 C (c) B(d) B 4 B (e) (A4 B)4 C (f) A

26. Prove that A4 B is a subset of A and of B.

27. Prove that set intersection is idempotent, that is, that A = A4A.

28. Prove that A4. =..

29. In the Venn diagrams below, shade the set A \ B:

A B

A

BA

B

A

B

30. Let A = {1,2,3,4},B = {2,4,6,8}, and C = {3,4,5,6}. Find(a) A \ B (b) C \A (c) B \(d) B \A (e) B \ B (f) (A(g) A \ (B \ C)

Page 55: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

51

31. Prove that A \ B is a subset of A.

32. Prove that (A \ B)4 B =..

33. Prove that if A \ B =., then A is a subset of B.

34. Prove that A \ B is a subset of A3 B.

35. Prove that A / B implies A4 B = A.

36. Prove that A / B implies A3 (B \A) = B.

37. (a) Prove that set di!erence is not commutative.

(b) Is it possible for that A \ B = B \A? Under what conditions could this occur?

(c) Is set di!erence associative? Prove your assertion.

38. Let A,B, and C be arbitrary sets. Express A3 B 3 C as a union of disjoint sets.

39. Let A,B, and C be arbitrary sets.

(a) Show that if C / A and C / B then C / A 4 B. (That is, A 4 B is the largest setcontained in both A and B.)

(b) Show that if C 1 A and C 1 B then C 1 A 3 B. (That is, A 3 B is the smallest setwhich contains both A and B.)

40. Suppose that A # . and that A 3 B = A 3 C . Show that it does not necessarily followthat B = C . Suppose in addition that A4 B = A4C ; can you now conclude that B = C?

41. Prove the absorption laws:

(a) A3 (A4 B) = A(b) A4 (A3 B) = A

42. In each of the following, find the generalised union and generalised intersection.(a) {.}(c) {{a}, {b}, {a,b}}

43. Specify the power sets of the following.

(a) {a,b, c}(b) {{a,b}, {c}}(c) {{a,b}, {b,a}, {a,b,b}}

44. Let Sn = {a0,a1, . . . ,an}, and Sn+1 = {a0,a1, . . . ,an,an+1}. Describe how P Sn and P Sn+1

are related.

45. Write a program that decides if two input sets are equal or if one is contained in theother. Assume that all input sets are finite subsets of N.

46. (Stanat) Programming Problems

(a) Write a program to generate the power set of {0,1,2, . . . ,n} for any natural numbern given as input.

(b) i. Write a program which accepts specifications of two finite subsets of the natu-ral numbers, A and B, and prints a nonredundant list of the elements of A3 Band A4 B.

ii. Write a program to determine for a given set A and an arbitrary n + N whetheror not n + A.

Page 56: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Chapter 4

Relations

We represent objects in the world by using sets; relations may be used to represent thestructure of these objects. Some relations describe comparisons between similar objects:“one box is heavier than another”; “one man is richer than another”; “one event occurredprior to another”. These relations speak of the structure within certain sets: they relate boxesto one another; they relate men; they relate events. Other relations speak of the structuresthat are built between sets: “Jim lives in Oxford”; “Kevin works for IBM”; “Foundations is aDiploma Course”. These relate people to cities; people to companies; and modules to courses.In this sense, “is heavier than” is a homogeneous relation, and “lives in” heterogeneous.

In Z, relations are simply sets of ordered pairs of objects, and we begin our discussionwith a description of such things.

4.1 Ordered Pairs

The use of an ordered pair (a,b) of real numbers to label a point in the plane in co-ordinategeometry will perhaps be familiar to readers. The value a represents the “x-coordinate”, andthe vale b represents the “y-coordinate”. This is depicted in the following graph:

a x

(a,b)

y

b

(0,0)

We say that (a,b) is an ordered pair because the order in which a and b appear is relevant.For example, (1,5) does not represent the same point in the plane as (5,1). This is capturedin the following important property of ordered pairs:

(a,b) = (c,d)! a = c ! b = d.

Thus, two ordered pairs are equal exactly when we have that their first components are equaland also that their second components are equal.

52

Page 57: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

53

Notice that this property means that the parentheses in the ordered pair notation are notassociative. If they were, then we could reason as follows

(1, (2,3)) = ((1,2),3)! 1 = (1,2) ! (2,3) = 3

Which is clearly nonsense. Thus, (1, (2,3)) is a pair whose first element is 1 and whosesecond element is the pair (2,3). Similarly, ((1,2),3) is a pair whose first element is the pair(1,2) and whose second element is 3.

4.2 Cartesian Products

The Cartesian product of two sets A and B is defined by

A 6 B = {a : A; b : B • (a,b) }.

This set comprehension term contains all the ordered pairs (a,b), such that a is drawn fromA and b is drawn from B. The notation “6” is used because the total number of elements inA 6 B is the size of A multiplied by the size of B.

When A and B are sets of real numbers, we can represent A 6 B as a set of points in theplane.

A B

a b( ),

x

(0,0) a x

A

B b

y

In this picture the set A is an interval of values on the x-axis, and B is an interval of valueson the y-axis. The set A 6 B is a rectangle in the plane.

The notion of Cartesian product is not restricted to the product of two sets. For example,the following set contains triples:

Cuboids == N 6 N 6 N.

We might choose the convention that in the Cuboid triple (w,h,d) that the first elementstands for the width, the second for the height, and the last for the depth.

In Z, the Cartesian product operator is not associative; that is, A 6 (B 6 C) # (A 6 B) 6 C .By definition, we have

A 6 (B 6 C) = {a : A; z : B 6 C • (a, z) }(A 6 B) 6 C = { x : A 6 B; c : C • (x, c) }

Page 58: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

54

Expanding these further we obtain

A 6 (B 6 C) = {a : A; b : B; c : C • (a, (b, c)) }(A 6 B) 6 C = {a : A; b : B; c : C • ((a,b), c) }

Since the ordered pair notation is not associative, these two sets contain objects of di!erentkinds, and they cannot be equal.

Example 44 Let A = {1,2},B = {m,n},C = {0}, and D =.. Then

1. A 6 B = {(1,m), (1,n), (2,m), (2,n)},2. A 6 C = {(1,0), (2,0)}, and

3. A 6 D =..

"

Example 45 Let A = {m : N | 1 ' m ' 3 } and B = {n : N | 1 ' n ' 2 }. Then

1. A 6 B = {m,n : N | 1 ' m ' 3 ! 1 ' n ' 2 • (m,n) }, and

2. B 6 A = {m,n : N | 1 ' m ' 3 ! 1 ' n ' 2 • (n,m) }.These two sets may be depicted as graphs.

y

x

1

2

3

1 2 3

A x B x AB

y

x

1

2

3

1 2 3

"

Theorem 8 The Cartesian product operator distributes over set union:

A 6 (B 3 C) = (A 6 B)3 (A 6 C).

Proof Let (x,y) be an arbitrary element of A 6 (B 3 C).

(x,y) + A 6 (B 3 C)

! by Cartesian product membership

x + A ! y + B 3 C

! by property of set union

x + A ! (y + B " y + C)

! since ! distributes over "

Page 59: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

55

(x + A ! y + B) " (x + A ! y + C)

! by Cartesian product membership

(x,y) + A 6 B " (x,y) + A 6 C

! by property of set union

(x,y) + (A 6 B)3 (A 6 C)

Thus, the two sets must be equal. "

4.3 Relations

Any subset R of A 6 B defines a relation between A and B. If (a,b) + R, then we say that therelation R holds between a and b, and we often write a R b. Sometimes we will write a% b,to mean the same as (a,b), to emphasise that we are considering a relationship between aand b.

y

A Bx

(0,0)

B

x

A

R

Example 46

1. Let A and B be the set of all human beings, and write a R b if and only if ‘a loves b’.We have

R = {a : A; b : B | a loves b }

2. Let’s define a relation that holds between two numbers just in case the first numberdivides the second exactly.

divides == {a,b : Z | ()m : Z • b = m , a) }

This is a good example of a specification of a relation. The relation divides has beengiven implicitly in terms of the multiplication operator.

3. When an assembler translates an assembly language program, it constructs a symboltable which contains the symbolic names which occur as labels in the program, andthe number of the program statement in which each name was defined. Thus, ifSymbol is the set of symbolic names, then the symbol table embodies a relationbetween Symbol and statement number.

4. (Stanat & McAllister) The relation “7” over the natural numbers can be defined in-ductively as follows:

Page 60: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

56

(a) (Basis) 0 7 1(b) (Induction)

If x 7 y , then

(i) x 7 y + 1(ii) x + 1 7 y + 1

(c) (Extremal) For all x,y + N, x 7 y only if it is required by the clauses 4a and 4b.

5. (Levy) In the relational model of databases n-ary relations are used as the stan-dard method for describing the relationships in the data. The theory of relationaldatabases is concerned with ways of representing data relations, and with the oper-ations needed to query and update the data base.

Module Lecturer Title1 Core Woodcock Foundations2 Core Woodcock Specification & Design3 Core Harvey-Jones Software Development Management4 Core Sufrin Functional Programming5 Core Davies Concurrency6 Core Woodcock Residential Week7 Optional Jackson Critical Systems8 Optional Jirotka Requirements Analysis

In Z, this database could be modelled as follows:

CO == {“C”, “O”}Diploma == N 6 CO 6 Lecturer 6 Title.

Each row of the table corresponds to an element in the Cartesian product Diploma:

(5, “C”,Davies,Concurrency) + Diploma.

"

4.4 Inverse Relations

Every relation from A to B has an inverse relation R8 from B to A which is defined by

R8 = {a : A; b : B | a R b • (b,a) }.In other words, the inverse relation R8 consists of those ordered pairs which, when reversed,belong to R. R8 is sometimes written R%1.

Example 47

1. Let A = {1,2,3} and B = {a,b}. Then

R = {(1,a), (1,b), (3,a)}is a relation from A to B. The inverse relation of R is

R8 = {(a,1), (b,1), (a,3)}.

2. Let W = {a,b, c}. Then

{(a,b), (a, c), (c, c), (c,b)}is a relation in W . The inverse relation of W is

W8 = {(b,a), (c,a), (c, c), (b, c)}.

"

Page 61: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

57

4.5 Identity Relation

The identity relation relates every element of a set to itself. We define the identity on a set Xas follows

id X == { x : X • (x, x) }.

4.6 Properties of Relations

Relations where the source and target are the same often possess useful properties.A relation is reflexive if every element is related to itself; if no element is related to itself,

then it is irreflexive.A relation R is symmetric if, whenever a R b, then b R a. It is asymmetric if, whenever

a R b, then ¬b R a. It is antisymmetric if, whenever a R b and b R a, then a = b.A relation R is transitive if, whenever a R b and b R c , then a R c .

Example 48 Let’s define the following relations:

R1 == {(1,1), (1,2), (2,2), (2,3)}R2 == {(1,2), (2,3), (1,3)}R3 == {(1,1), (2,2), (2,3), (3,2), (3,3)}.

R3

R2

R1

3

2

11

2

3

R2 is asymmetric, R1 and R3 are not. R1 and R2 are antisymmetric; R3 is not. R2 and R3are transitive; R1 is not. "

The way that we have defined a symmetric relation may be re-stated in terms of the inverserelation. Consider the following

(a : A; b : B • a R b ! b R a

Page 62: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

58

! (a : A; b : B • a R b ! a R8 b

! R = R8

Thus, a relation R is symmetric if and only if R = R8.A relation is antisymmetric if the only symmetric pairs are of the form (a,a). We can

use this insight to re-cast the definition of antisymmetry in terms of the identity relation.Suppose that R is a relation on A, then it is antisymmetric if and only if R4 R8 / id A.

Example 49

1. The relation of equality is reflexive on any set.

2. Consider the set set Z of integers. The relation “'” is reflexive and not irreflexive;the relation “<” is irreflexive and not reflexive.

3. In Euclidean geometry, the triangle A is similar to the triangle B providing that theyhave the same angles. “Is similar to” is a reflexive relation.

4. The relation “/” on sets is reflexive.

5. Consider the set of strings of characters. The relation “is the same length as” is re-flexive and not irreflexive; the relation “is longer than” is irreflexive and not reflexive.Let pre-su" be the relation that holds between two strings s and t provided that aproper prefix of s is a proper su"x of t . Examples of members of pre-su" include

“formal” pre-su" “platform”

“woodcock” pre-su" “sherwood”

“mathematics” pre-su" “doormat”

pre-su" is neither reflexive nor irreflexive, since we have

“tintin” pre-su" “tintin”

¬(“woodcock” pre-su" “woodcock”)

"

Example 50

1. The relation of equality is both symmetric and antisymmetric on any set.

2. Consider the set set Z of integers. The relations “'”and “<” are both antisymmetric;neither is symmetric. The relation between numbers that holds when their absolutevalues are equal is symmetric but not antisymmetric.

3. The relation “is similar to” between triangles in Euclidean geometry is symmetric.

4. The relation divides between numbers is not symmetric; it is, however, antisymmetric.

5. The relation “/” between sets is antisymmetric.

6. Consider the set of strings of characters. The relation “is a substring of” is antisym-metric but not symmetric. The relation that holds between two strings when theyhave a common nonempty prefix is symmetric but not antisymmetric.

"

Example 51

1. The relation of equality is transitive on any set.

2. Consider the set set Z of integers. The relations “'”and “<” are both transitive. Therelation x divides y , which holds providing x divides y exactly, is also transitive.

3. The relation x loves y is not transitive.

Page 63: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

59

4. The relation “/” between sets is transitive.

5. The relation “is similar to” between triangles in Euclidean geometry is transitive.

6. Consider the set of strings of characters. The relations “is a prefix of”, “is a properprefix of”, “is a substring of”, and “is the same length as” are all transitive relations.

"

Relations that possess combinations of these properties are interesting, and in the next sec-tion we consider an important class: equivalence relations.

4.7 Equivalence Relations

All abstractions are built on the idea of equivalence classes. For example, suppose that youwant to buy a new car, and that you are convinced that a diesel car is both more economicaland environmentally-friendly. In thinking about this you are dividing the set of available newcars into two sets: two ‘equivalence classes’. You have invented an equivalence relation withrespect to which all diesel cars are equivalent, regardless of make or model. We have metthis idea before in the chapters on logic. Two propositions were regarded as equivalent ifthey had the same truth value, regardless of their structure.

In mathematics, an equivalence relation R on a set A is defined to be a relation betweenthe set A and itself which satisfies the following properties for each a,b, and c in A:

1. a R a (reflexivity);

2. a R b ! b R a (symmetry); and

3. a R b ! b R c # a R c (transitivity).

Example 52

1. The relation SameMum is defined between two humans whenever they have the samemother. It is an equivalence relation.

2. Let’s write x 9k y to mean that x and y have exactly the same remainder when dividedby k. That is, we can find natural numbers m and n, and a number r between 0 andk % 1, such that

x = m , k + r ! y = n , k + r .

We can define this formally as a family of relations, (one for each natural number k):

9k == { x,y ,m,n : Z; r : 0 . . k % 1 |x = m , k + r ! y = n , k + r • (x,y) }.

Each of these relations is an equivalence relation.

3. “Is similar to” is an equivalence relation between Euclidean plane triangles.

4. Equality is an equivalence relation on any set.

"

Let R be an equivalence relation on A. Define A1 == {a : A | a R a1 }; we call A1 an equivalenceclass of R.

Theorem 9 Two distinct equivalence classes are disjoint (i.e. have no points in common).

Page 64: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

60

Proof Let R be an equivalence relation on a set A. If a1 + A and a2 + A, write A1 =={a : A | a R a1 } and A2 == {a : A | a R a2 }.Suppose that A1 and A2 are not disjoint. Then, they have a common element, say b. Wehave

AA1

A2a1b

a2

b R a1 ! b R a2 [since b + A1 and b + A2]

! a1 R b ! b R a2 [by symmetry (R is an equivalence relation)]

# a1 R a2 [by transitivity (R is an equivalence relation)]

Now, if we pick any c in A1, it must also lie in A2:

c + A1 ! c R a1 [by definition]

! c R a1 ! a1 R a2 [from above]

# c R a2 [by transitivity]

! c + A2 [by definition.]

So, we have that A1 / A2. By a similar reasoning, we also have that A2 / A1, and thusA1 = A2. "

A stronger way of stating this theorem is to say that when a relation R induces equivalenceclasses on a set A, those classes partition the set A. That is to say that they are disjoint, andtheir union is A.

Example 53 The relation 9k , defined above, induces k equivalence classes in N.

1. 92 gives two equivalence classes: they are best known as the sets of odd and evennumbers.

2. 93 produces three equivalence classes: {0,3,6,9, . . .}, {1,4,7,10, . . .} and {2,5,9,11, . . .}."

4.8 Source, Target, Domain, and Range

When we define a relation R between A and B, the set A is called the source of the relation,and the set B the target.

Page 65: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

61

The domain of R is the set comprising the first elements of each of the pairs in R, and therange of R is the set comprising the second elements of each of the pairs in R.

dom R == {a : A; b : B | a R b • a }ran R == {a : A; b : B | a R b • b }.

4.9 Orderings

A total ordering : on a set A is a relation between A and itself which satisfies the followingproperties, for each a,b and c in A:

1. a : b " b : a (totality);

2. a : b ! b : a # a = b (antisymmetry); and

3. a : b ! b : c # a : c (transitivity).

If the totality condition is replaced by reflexivity (i.e. a : a), then we call : a partial ordering.In such a partial ordering, certain pairs of elements in A may simply not be comparable.

Example 54

1. The set Z of integers is totally ordered by the relation ' of increasing magnitude.

2. If A is a set, then its powerset is partially ordered by /, the subset relation.

"

4.10 Composition

If R is a relation from A to B, and S is a relation from B to C , then we can compose the tworelations to form the relation which is denoted by R o

9 S . The composition contains pairs thathave been obtained from R and S in the following way. Suppose that a (R o

9 S) c ; it must bethe case that there exists a value b such that a R b and b S c . Formally,

R o9 S = {a : A; b : B; c : C | a R b ! b S c • (a, c) }.

This is most clearly seen when the graphs of two relations are considered.

Page 66: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

62

Michael

Jim

Jamie

Dave

Gordon

Citroen

Peugeot

NoddyCar

MGB

Skoda

Trabant

Diesel

FourStar

Unleaded

N20

2Stroke

owns uses

Car FuelPerson

4.11 Relational Restriction

It is sometimes useful to consider the result of restricting a relation to a particular subset ofits domain, or range. We write S"R to denote the relation R restricted only to those membersof S . Similarly, R# S is R, with only those arrows present which end at members of S .

S " R == {a : A; b : B | a% b + R ! a + S • a% b }R# S == {a : A; b : B | a% b + R ! b + S • a% b }

Example 55 In a database where earns is the relationship between names and salaries,Let D be the set of Company Directors, and S be the set of all salaries less than £30 000.

1. D " earns is the relationship between directors’ names and salaries.

2. earns#S is the relationship between names and salaries for those who earn less than£30 000.

3. dom earns # S is the set of names of those who earn less than £30 000.

"

The restriction operators have complements, too. Domain/range anti-restriction (domain/rangesubtraction) limits the relation to those objects which are not in the specified set.

S & R == {a : A; b : B | a% b + R ! a $ S • a% b }R' S == {a : A; b : B | a% b + R ! b $ S • a% b }

Example 56 Using the definitions in the previous example,

1. D & R is the relationship between non-directors and their salaries.

2. earns'S is the relationship between names and salaries for those who earn in excessof £30 000.

3. (D & R) # S is the relationship between names and salaries for those directors whoearn less than £30 000.

Page 67: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

63

"

In fact, the choice of where to put the parentheses in the last example is quite arbitrary, asdemonstrated by the following general law:

(S " R)# T = S " (R# T )

There are a range of other useful laws relating these operators:

S " (T " R) = (S 4 T )" RS & (T & R) = (S 3 T )" R(S " R)3 (S & R) = R

with similar laws for ' and #.

4.12 Relational Closure

If a relation is not transitive, we may construct a similar relation which is. For a relation R,R+ is its transitive closure, that is, the smallest relation which entirely contains R and is alsotransitive. Of course, if R is itself transitive, then R+ = R.

To define R+, we introduce another notion: that of an iterated relation. We have a relationR2, such that a R2 b exactly when there is a c such that a R c ! c R b. Likewise, a R3 b wheneverwe can find c and d such that a R c ! c R d ! d R b. In general, two objects will be related byRk if there is a chain of k instances of R relating the two objects. Now we can give a formaldefinition of R+:

R+ =%{n : N \ {0} • Rn }

A similar relation is the reflexive transitive closure—which has all the properties of R+, andis also reflexive. It can be defined in the same way, making use of the convention that R0 isthe identity relation.

R, =%{n : N • Rn }

Example 57 Write parentof for the relation ‘is a parent of’; so ‘John parentof Andrew ’describes the fact that John is a parent of Andrew. The relation parentof + then has anatural interpretation—it is the ‘is an ancestor of’ relationship. "

4.13 Problems

1. Show that the relation divides, which was introduced in Example 46.2, is a partial or-dering on N.

2. Explain why ! is an equivalence relation on the set of all propositions.

3. Let : be a total ordering on a set A. Define the associated ‘strict ordering’ 7 on A by

a 7 b ! a : b ! a # b.

Prove that 7 is a transitive relation. Is it total? Is it antisymmetric?

Page 68: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

64

4. Prove the following theorems.

A 6 (B 4 C) = (A 6 B)4 (A 6 C)

(A3 B) 6 C = (A 6 C)3 (B 6 C)

(A4 B) 6 C = (A 6 C)4 (B 6 C)

5. How many binary relations are there on the set {1,2,3}? If A has n elements, how manybinary relations are there on A?

6. What kind of properties do the following relations have?

(a) For the set of integers Z, x R y if and only if x and y are both positive or are bothnegative.

(b) For the set of integers Z, x R y if and only if

abs(x % y) = 4 " abs(x % y) = 8 " x = y ,

where abs(z) denotes the absolute value of z.

7. Consider the set of integers Z. Fill in the following table according to whether therelation possesses the property.

. Z 6 Z = < ' dividesReflexiveIrreflexiveSymmetricAntisymmetricTransitive

8. Find a nonempty set and a relation on it which is neither reflexive nor irreflexive. Choosethe set to be as small as possible. What if the set is empty?

9. Construct a binary relation on a nonempty set which is neither symmetric nor antisym-metric. Choose the set to be as small as possible. What if the set is permitted to beempty?

10. Fill in the following table according to whether the relation possesses the property; ineach row, you may assume that the relations R and S both possess the property indi-vidually. For each relation that does not possess the property, give a counterexample.

Union IntersectionR3 S R4 S

ReflexiveIrreflexiveSymmetricAntisymmetricTransitive

11. Sketch graphs of the following relations on the set of real numbers, and determine whatkinds of properties the relations have.

(a) { x,y : Real | x = y }.(b) { x,y : Real | x2 % 1 = 0 ! y > 0 }.(c) { x,y : Real | abs(x) ' 1 ! abs(y) & 1 }.

Page 69: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

65

12. Write a program which takes as input a relation described as a set of ordered pairs anddetermines whether it is reflexive, irreflexive, symmetric, antisymmetric, or transitive.

13. (Stanat & McAllister) Prove or disprove the following assertions.

(a) If R and S are reflexive, then R o9 S is reflexive.

(b) If R and S are irreflexive, then R o9 S is irreflexive.

(c) If R and S are symmetric, then R o9 S is symmetric.

(d) If R and S are antisymmetric, then R o9 S is antisymmetric.

(e) If R and S are transitive, then R o9 S is transitive.

14. Prove that dom distributes through 3; that is

dom(S 3 T ) = dom S 3 dom T

Does the same hold for ran? What about 4?.

15. Prove that dom(S " R) = S 4 (dom R).

16. Can (R+)+ be simplified?

Page 70: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Chapter 5

Functions

The graph of a binary relation in its most general form may contain both diverging andconverging arrows. For example, in the graph of the ‘less-than-or-equal-to’ relation on theintegers, there are many arrows emanating from the value 0, since 0 ' 0, 0 ' 1, 0 ' 2, etc.,and many arrows converging on the value 0, since 0 ' 0, %1 ' 0, %2 ' 0, etc.

.

.-3-2-10123..

.

.-3-2-10123..

If we forbid the presence of diverging arrows, then we get a special class of relations: func-tions.

Functions have no diverging arrows.

Example 58 The following are all examples of functions.

1. Suppose that f relates each integer to its square; then, f is a function since the squareof a number is unique.

2. Suppose that g relates each country in the world to its capital city; then, g is a functionsince no country has more than one capital.

3. Suppose that h is defined as

h = {a% b,b% c, c% c,d% b}then h is a function, since each member of its domain is mapped to exactly one value.

66

Page 71: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

67

"

Suppose that f is a function which maps elements of the set A to elements of the set B, thenwe write

f : A ;5 B

when we define f . The set A ;5 B is the set of all functions from A to B. Now, suppose thata is in the domain of f . The value a must be related by f to some value in B, but, since fis a function, a cannot be related to more than one value in B. We write f (a) to denote theunique element that a is related to by f . (This is often written without parentheses, thus:‘f a’.)

So, if we know that f is a function, and that a + dom f , then we have that

b = f a ! a% b + f

As f is a function, we know that it has the no-diverging-arrows property:

(a : A; b1,b2 : B | a% b1 + f ! a% b2 + f • b1 = b2

Example 59 The following are examples of functions

1. f : N ;5N

f x = 1 if x is oddf x = x div 2 if x is even

2. g : {1,2,3} ;5 {A,B,C}g(1) = Ag(2) = Bg(3) = C

3. h : Char ;5 Char

h = {‘a’% ‘b’, ‘b’% ‘c ’, ‘c ’% ‘d ’}

4. Suppose that A = ., then f : A ;5 B is a function. Every maplet in f must have itsfirst element in A and its second element in B; since A is empty, there can be no suchmaplets, and therefore f is itself empty; since there are no maplets in f , there can beno diverging arrows in f , and therefore f is a function.Similarly, if D =., then g : C ;5D is a function.

5. (Grimaldi) In storing a matrix in a one-dimensional array, many computer languagesuse the major row implementation. Here, if A is an n 6 n matrix

'(()

a1,1 · · · a1,n...

...an,1 · · · an,n

*++,

the first row of A is stored in locations 1,2,3, . . . ,n of the array (with a1,1 in the firstposition). The entry a2,1 is then stored in position n + 1, while entry a3,4 occupiesposition 2 , n + 4 in the array. In order to determine the location of any entry ai,j ,for i and j both between 1 and n, an access function f is defined that maps (i, j) toan array location. A suitable definition is that

f (i, j) = (i % 1), n + j

"

The following is not a function: the relation between a positive real number and its realsquare root (since there are two such relatives for every positive real number).

Page 72: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

68

5.1 Total and Partial Functions

Consider the predecessor relation ‘pred ’ on the natural numbers: m has the predecessor n ifand only if n = m%1. Is pred a function? The answer must be “yes”, since it clearly containsno diverging arrows:

m% n1 ! m% n2

! n1 = m % 1 ! n2 = m % 1

# n1 = n2

However, to what result does pred relate the value 0? There is no natural number that is thepredecessor of 0 (%1 is not a natural number), and we say that the function is not definedfor 0. In this sense, pred is not a total function on the natural numbers: it is not defined forall of them. A function which is not total is called a strictly partial function.

A total functions from A to B is thus any function from A to B whose domain is the wholeof A. Thus, f is a total function from A to B, written

f : A5 B

providing that

f + A ;5 B ! dom f = A

Example 60

1. The reciprocal relation that takes a real number x to the value 1/x is a strictly partialfunction, undefined for the value 0.

2. The positive square root relation that takes a real number x to the positive real num-ber y , such that y2 = x, is a strictly partial function, undefined for negative inputs.

3. The identity function

ident : N ;5N

(n : N • ident n = n

is a total function on the naturals.

4. Computer programs represent functions that may be partial. The input to a programis the argument of the function, and the output of the program is its result. If theprogram might not always terminate, or might terminate abnormally (with a runtimeerror, for example) then the function is strictly partial, undefined for that input.Using the output of one program as the input to another corresponds to (althoughis not identical to) composition.

"

5.2 Special Functions

Just as we placed a constraint on relations to yield functions, and a further constraint on func-tions to yield strictly partial functions, so we can add other constraints to yield specialisedfunctions which turn out to be of great interest in modelling (in particular) computing sys-tems.

Page 73: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

69

partial function A ;5 B { f : A< B | (a : A; b1,b2 : B |a% b1 + f ! a% b2 + f • b1 = b2 }

finite function A ; ;5 B { f : A ;5 B | dom f + FA }total function A5 B { f : A ;5 B | dom f = A }partial surjection A ;55 B { f : A ;5 B | ran f = B }total surjection A55 B A5 B 4A ;55 Bpartial injection A( B { f : A ;5 B | (a1,a2 : dom f • f a1 = f a2 # a1 = a2 }total injection A) B A5 B 4A( B(total) bijection A)5 B A) B 4A55 B

Table 5.1: Function arrows and their definitions

Suppose that the range of a function is the whole of its target, then the function is calledsurjective (a few years ago, it would have been known as an onto function). If f is a surjectivefunction from A to B, it is denoted by A ;55 B, and has the property that

f + A ;5 B ! ran f = B

Suppose that a function contains no converging arrows, then it is called injective ( a fewyears ago it would have been known as a one-to-one function). If f is an injective functionfrom A to B, it is denoted by A( B, and has the property that

f + A ;5 B !(a1,a2 : A | f a1 = f a2 • a1 = a2

The set of total surjections from A to B is denoted by A55 B, and the set of total injectionsfrom A to B by A) B.

A total, injective, surjective function is known as a bijection, and the set of all bijectivefunctions from A to B is denoted by A)5 B. Suppose that f : A5 A is a bijection; we canthink of f as giving us a permutation of A.

Suppose that f is a function in A ;5 B. Every element in dom f is the origin of exactly onearrow. If f is total, then every element of A is the origin of exactly one arrow. If f is surjective,then at least one arrow terminates at each element of B. If f is injective, no more than onearrow terminates at each element of B. If f is bijective, then exactly one arrow terminates ateach element of B.

Table 5.1 summarises the di!erent arrows used here, and the definitions of each.Example 61

1. Define the squaring function as

sqr : Z5 Z

(n : Z • sqr n = n , n

As we discussed above, sqr is a function; it is total, since every number has a square;it is not injective, since we have

sqr 3 = 9 = sqr % 3;

it is not surjective, since the range omits any number which is not a perfect square(like %9 and 5).

2. Define the cubing function as

cube : Z5 Z

(n : Z • cube n = n3

Now, cube is a total, injective function; it is not surjective.

Page 74: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

70

3. The function which assigns to each country its capital city is, arguably, not injective.This argument relies on recognising that both the United Kingdom and England arecountries; they both have the same capital city.

4. The identity function is a bijection.

5. A constant function is one which maps every element of its domain to the same result.If the domain contains only one element, then it is obviously an injective function; ifthere is more than one element in the domain, then there must be at least one pairof converging arrows, and the constant function cannot be injective.

6. Suppose that we have the successor relation

succ : Z< Z

(m,n : Z • m% n + succ ! n = m + 1

Clearly, succ is a function, since no number has more than one successor; it is total,since every number has a successor; it is surjective, since every number is the suc-cessor of some number; it is injective, since no number is the successor of more thanone number. Thus, succ is a bijection on the integers.

7. Consider

f : {1,2}5 {0}

This declaration has defined f fully: there is only one total function from the set{1,2} to the set {0}. Moreover, f is surjective; it is, however, not injective.

8. Define

g = {1% 2,2% 3}

The relation g is clearly a strictly partial function on the naturals (and on the integers).It is also injective, but not surjective.

9. . +.)N

10. . +.)5.11. Define

f : N ;5N

( x : N • f x = 2, x

f is a strictly partial injective function; it is not total, surjective, or bijective.

12. (Stanat & McAllister) In computer systems, records are often stored under keys infiles. Of the many methods that there are of assigning keys to records, one usesa hash function to compute the key from the record. For example, our universitydepartment’s car park attendant might keep a record of cars registered to use thecarpark. An appropriate key might be derived from the index number for the car.If the department has 400 car parking spaces (a wild, unrealistic dream), then theattendant could allow 400 owners to register their cars. A possible data structuremight have 500 entries, with the key being formed from the numerical part of theindex, modulo 500. If f is the hash function, then we would have

f K979XFC = 479f VSO940S = 440f 1BJO = 1f M440MJF = 440

Page 75: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

71

This hash function is, I believe, total on the set of British car index marks. It issurjective with respect to the set of numbers in the range 0 to 499. It is not aninjection.

The fact that the hash function is not an injection means that two keys have thesame hash-value (e.g., VSO940S and M440MJF above). When this happens, a collisionis said to occur, and some provision must be made to store, and subsequently tosearch for, collided records.

"

5.3 Relational Operations on Functions

Since a function is a special kind of relation, the relational operators may be applied tofunctions. For example, we can form the inverse of a function. The result is definitely arelation, but not necessarily a function. Since a function cannot contain any diverging arrows,if it contains converging arrows, then its inverse will contain diverging arrows, and thus theinverse will not be a function.

The consequence of this argument is that the inverse of an injective function will be afunction (also injective). Moreover, the inverse of a surjective function will be total, and theinverse of a total function will be surjective. Therefore, the inverse of a bijection is a bijection.

Example 62

1. Suppose that we have

A = {a,b, c}B = {x,y , z}f = {a% y ,b% x, c% z}

then, f is a bijection from A to B. The inverse of f , denoted by f8 is also a bijection,but this time from B to A:

f8 = {y% a, x% b, z% c}

2. Suppose further that we have

g = {a% y ,b% z, c% y}

then, g is a total function (it is neither surjective nor injective). The inverse of g isthe relation

g8 = {y% a, z% b,y% c}

It is not a function, since y is mapped to two di!erent values.

3. Suppose that we take the inverse of the cube function introduced above; its inverseis the cube-root function (functional because cube was injective):

cubert n = 3=n

4. The function succ (the function that gives the successor of its argument) on thenatural numbers N is total, injective, and not surjective (because nothing maps to 0).Its inverse is pred (the function which yields the predecessor of its argument), whichis partial, injective, and surjective.

"

Page 76: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

72

5.4 Relations and Functions

We have seen that functions are a special case of relations; those with no diverging arrows.Is there any way that an arbitrary relation can be used like a function?

Consider what happens when we consider the relation applied to a set of objects. We canform a new set; the set consisting of all those objects which are related to members of thefirst set. This is called the relational image of the first set (under the chosen relation), and isformally defined as follows:

R(| S |) == {a : A; b : B | a% b + R ! a + S • b }Notice that this could also be expressed as R(| S |) = ran(S " R).

In the case where S is a singleton, we have e!ectively found a way to apply a relationto an object, as if that relation were a function. The price we pay is that the result of theapplication is not a single object, but a set.

Example 63

1. Suppose a R b exactly whenever a ' b. Then R(| {n} |) is the set of all numbers lessthan or equal to n.

2. If studies is the relation between students’ names, and the titles of the courses theystudy, and class is the set of students on this week’s course, then studies(| class |) isthe set of all courses studied by any of the students on this week’s course.

"

5.5 Cardinality

Suppose that f is a function. Since f is also a relation, we can apply the dom operator to itto obtain its domain. Since f is a function, there are no diverging arrows in f , and thereforethe number of pairs in f is the same as the number of elements in the domain of f . That is,if we count the number of points in the graph which have arrows emanating from them, thenwe have counted all the arrows too.

This argument isn’t quite right, because if there are infinitely many pairs in the graph off , then we cannot count them and end up with a number.

A set A is finite if there is some natural number n + N, such that there is a bijection fromthe set A to the set {1,2,3, . . . ,n}. The number n is then called the cardinality of A, and isdenoted by #A. The bijection ensures that every element of A is counted (since it is total onthe set A); that no element is counted more than once (since it is functional, no element of Ahas two di!erent numbers assigned to it); that elements are counted one at a time (since itis injective, no number will be assigned to more than one element); and that the counting iscorrect (since it is surjective, no number between 1 and n is omitted).

The set of all finite subsets of a set A is denoted FA; this is a subset of PA; a propersubset if A is infinite.

Example 64

1. Suppose that A is the set {a,b, c}. The cardinality of A is 3; that is, #A = 3, since thefunction

f : {a,b, c}5 {1,2,3}f (a) = 1f (b) = 2f (c) = 3

is a bijection.

Page 77: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

73

2. Suppose that A is the empty set. The cardinality of A is 0, since the function

f : .5.

is a bijection, and the empty set really does contain all the numbers strictly between1 and 0: there aren’t any!

"

Though we will not consider such things on this course, cardinalities can be infinite. Someinfinite cardinalities are larger than others.

5.6 The Pigeonhole Principle

The pigeonhole principle states that

If m pigeons occupy n pigeonholes, then m > n if, and only if, there is at least onepigeonhole with two or more pigeons roosting in it.

More formally, if A and B are finite sets, with #A = m and #B = n, for m > n, then there isno injective function from A to B.

Example 65

1. In the Programming Research Group there are 13 University Lecturers, so there mustbe at least two of them who have birthdays during the same month of the year. (Herewe have 13 pigeons (University Lecturers) and 12 pigeonholes (months of the year).)

2. In the now-infamous Case of the Disappearing Sock, Sherlock Holmes returns fromthe Baker Street Laundromat with 17 pairs of socks, each pair a di!erent colour, inhis laundry bag. The following morning, in a frantic attempt to get dressed beforeMoriarty’s trail goes completely cold, he withdraws socks randomly from the bag. Hemust withdraw exactly 18 in order to be certain that he has a matched pair.

3. Any subset of size six drawn from the set

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

must contain two elements whose sum is 10.

(The pigeons this time are the numbers 1,2, . . . ,9, while the pigeonholes are the sets

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

whose elements sum to 10. Now, we choose six pigeons. the Pigeonhole Principletells us that at least two pigeons must roost in one of the holes.)

"

5.7 Functional Composition

We have already seen relational composition o9, where an arrow a%b is a member of relation

R o9 S exactly when we can find a c such that a R c and c S b.

Since functions are relations, this form of composition can be used between functions,too. For example, if d is the function which doubles its argument, and t is the function whichadds ten to its argument, then d o

9 t is the function which doubles its argument, and thenadds ten.

Page 78: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

74

Sometimes, however, it is useful to be able to do things in the opposite order. In theexample above, if we were to apply d o

9 t to, say, 45, we might calculate:

(d o9 t)45

= t(d 45)= t 90

= 100

This involves swapping the order of t and d , in moving from the first to the second line.Another form of composition, written > avoids this need. It is exactly the reverse of o

9:

(t > d)45

= t(d 45)= t 90

= 100

Whether > or o9 is used will depend greatly on the situation. Both can be used with both

functions and relations; the choice of which to use will be a matter of style and clarity.Notice that the order is important; do not get the two symbols confused!:

(d > t)45

= (t o9 d)45

= d(t 45)= d 55

= 110

5.8 Functional Overriding

It is easy to combine relations: we can just take their union. For functions, the situation isless straightforward: the union f 3 g of two functions may not be a function—it might havediverging arrows (one from f and one from g). How are we to choose which arrow to acceptand which to omit?

Instead of taking the union of two functions, we override one with another. f ?g denotesthe function obtained by combining f and g, choosing terms from g whenever there wouldotherwise be diverging arrows. Formally,

f ? g == ((dom g)& f )3 g

Example 66 Let date is the function which takes the name of a course and returns thedate when it will next take place. Thus, date Foundations = 22Jan96.

When the Course Administrator wants to update the course schedule, some courses mayneed to be rescheduled; other new ones may be added. This will entail an update of thedate function, so that it is the original calendar, with some ammendments:

date? {Foundations% 29Jan96,Management% 09Dec96,Surfing% 03Aug96}

"

Page 79: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

75

5.9 Problems

1. Draw diagrams to illustrate simple examples of the following classes of function:

(a) partial surjection (not injective)

(b) total surjection (not injective)

(c) partial injection (not surjective)

(d) total injection (not surjective)

(e) bijection

2. An important idea in mathematics is in the investigation of whether the combining oftwo entities with a common property yields a result with that property.

(a) Suppose that f and g are both functions. Is f o9 g a function? Prove that your

answer is correct.

(b) Suppose that f and g are both injective functions. Is f o9 g injective? Prove that

your answer is correct.

(c) Suppose that f and g are both surjective functions. Is f o9 g surjective? Prove that

your answer is correct.

(d) Suppose that f and g are both bijective functions. Is f o9 g bijective? Prove that

your answer is correct.

3. If f and g are functions, then are the following necessarily functions, too?

(a) f 4 g

(b) f 3 g

(c) f \ g

For any that are not necessarily functions, state necessary/su"cient conditions on fand g (maybe in terms of dom or ran for their combination to be a function).

4. If R : A< B is a relation, and f is defined by

f a = R(| {a} |)

then what is the type of f ? Is f partial or total? Surjective? Injective?

5. Give a su"cient condition on f and g such that f ? g = g ? f .

6. Prove this law on overriding and domain restriction:

S " (f ? g) = (S " f )? (S " g)

7. Prove

f + X ( Y # f (| S 4 T |) = f (| S |)4 f (| T |)

8. Let f : A5 B and g : C 5D. The product function h : A 6 C 5 B 6 D is defined as

h(a, c) = (f (a),g(c))

Prove that h is a bijective function if, and only if, f and g are bijective functions.

Page 80: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

76

9. The infamous “91-function” is defined recursively as follows:

f : N5N

f (x) = x % 10 if x > 100f (x) = f (f (x + 11)) if x ' 100

(a) Show that f (99) = 91.

(b) Prove that f (x) = 91 for all x from 0 to 100.

10. Assuming S and T are finite sets, find expressions for the following, involving #S and#T

(a) #(S 3 T )(b) #(S \ T )(c) #(P S)(d) #(S < T )

11. For finite sets A and B,

(a) How many functions are there between A and B?

(b) How many of these are total?

(c) How many are strictly partial?

(d) How many injections are there from A to B?

(e) How many surjections are there from A to B?

(f) How many bijections are there from A to B?

Explain all your answers.

12. The Ministry of Defence has eight di!erent contracts that deal with a high securityproject. Five companies can manufacture the distinct parts called for in each contract,and to keep the project as well protected as possible, it is best to have all five companiesworking on some part. In how many ways can the contracts be awarded so that everycompany is involved?

13. How many seven-digit quaternary numbers (that is, numbers which are made up onlyof the digits 0,1,2,3) have at least one occurrence of each of the digits 0,1,2,3?

14. An m 6 n zero-one matrix is a matrix A with m rows and n columns, such that in rowi and column j , the entry ai,j is either zero or one. How many 9 6 6 zero-one matriceshave exactly one 1 in each row and at least one 1 in each column?

15. How many times must we roll a single die in order to get the same score at least twice?

16. Show that if any 14 integers are selected from the set

{1,2,3, . . . ,25}q

there are at least two whose sum is 26.

Page 81: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Appendix A

Solutions to Chapter 1: PropositionalCalculus

Any exercise that involves expressing mathematical terms in ordinary prose will have a rangeof correct answers: we use mathematics precisely because it enables us to be clearer, moreprecise and less ambiguous than writing English prose. Only one example solution will begiven in such cases.

1. The weather.

(i) “It’s not cold.”

(ii) “It’s cold and it’s raining.”

(iii) “Either it’s cold, or it’s raining.”

(iv) “Either it’s raining, or it’s not cold.”

(v) “It’s neither raining nor cold.”

(vi) “It isn’t fine.”

2. The beauty contest.

(a) p ! q.

(b) p ! ¬q.

(c) ¬(¬p " q).(d) ¬(p " q).(e) ¬(¬p " ¬q).

3. Hamilton’s mathematical politics. Let

• J stand for “Jones is elected leader of the party”;

• W stand for “We shall win the election”;

• S stand for “Smith will leave the cabinet”;

• R stand for “Robinson will leave the cabinet”;

• Rat(x) stand for “x is a rational number”;

• Int(x) stand for “x is an integer”;

77

Page 82: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

78

• Real(x) stand for “x is a real number”;

• M stand for “The murderer has left the country”;

• H stand for “Somebody is harbouring him”;

• Even(x) stand for “x is an even number”;

• Odd(x) stand for “x is an odd number”;

(a) J # W ;

(b) ¬J # (S " R) ! ¬W ;

(c) Rat(x) ! Int(y)# ¬Real(z);(d) M " H ;

(e) ¬M # H ;

(f) Even(x + y)! (Even(x) ! Even(y)) " (Odd(x) ! Odd(y));(g) Rat(x)# (Int(y)# ¬Real(z)).

4. Stanat’s Christmas shopping.

(a) i. ¬p ! r # q.ii. q # r .

iii. ¬p.iv. p ! ¬q.

(b) i. “I will go to town if and only if I have time and it is not snowing”;ii. “I have time and I will go to town”;

iii. “I will go to town if and only if I have time”;iv. “Neither do I have time, nor will I go to town”.

5. Stanat’s converses and contrapositives.

Converses

(a) “If I’m not going, then it rains”;

(b) “You go only if I stay”;

(c) “If you can bake the cake, then you get 4lbs”;

(d) “If I can’t complete the task, then I don’t get more help”.

Contrapositives

(a) “If I’m going, then it won’t rain”;

(b) “You don’t go only if I don’t stay”;

(c) “If you cannot bake the cake, then you haven’t got 4lbs”;

(d) “If I can complete the task, then I do get more help”.

6. Grimaldi’s triangles.

(a) “If ABC is an equilateral triangle, then it is also an isosceles triangle”;

Page 83: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

79

(b) “If ABC is not an isosceles triangle, then it cannot be an equilateral triangle”;

(c) “ABC is an equilateral triangle i! an only if it is an equiangular triangle”;

(d) “ABC is an isosceles triangle, but not an equilateral triangle”;

(e) “If ABC is an equiangular triangle, then it is also an isosceles triangle”.

7. Grimaldi’s sizes of truth tables.

(a) There are five propositional variables, so we need 25 rows in the truth table; thatis, we need 32 rows.

(b) Since p contains n propositional variables, its truth table must require 2n rows.

8. Truth tables.

(a)

p q ¬p ! qt t f ft f f ff t t tf f t f

(b)

p q ¬ (p " q)t t f tt f f tf t f tf f t f

(c)

p q ¬ (p " ¬q)t t f t ft f f t tf t t f ff f f t t

9. Weather forecasting.

(a) Rain on Tuesday is a necessary condition for rain on Sunday: Sunday # Tuesday .

(b) If it rains on Tuesday, then it rains on Wednesday: Tuesday # Wednesday .

(c) But it rains on Wednesday only if it rains on Friday: Wednesday # Friday .

(d) Moreover, no rain on Monday means no rain on Friday: ¬Monday # ¬Friday .

(e) Finally, rain on Monday is a su"cient condition for rain on Saturday: Monday #Saturday .

First, notice that from ¬Monday # ¬Friday , we have by contraposition that Friday #Monday . Now, we can reason with a chain of implications:

Sunday # Tuesday# Wednesday# Friday# Monday# Saturday

Thus, If it rains on Sunday, it will rain on Saturday too.

10. Verify that the proposition p " ¬(p ! q) is a tautology.

Page 84: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

80

p q p " ¬ (p ! q)t t t f tt f t t ff t t t ff f t t f

11. Verify that the proposition (p ! q) ! ¬(p " q) is a contradiction.

p q (p ! q) ! ¬ (p " q)t t t f f tt f f f f tf t f f f tf f f f t f

12. Which of the following propositions are tautologies?

(a) p # (q # p) is a tautology, since

p # (q # p)

! by implication

¬p " (q # p)

! by implication

¬p " (¬q " p)

! by associativity and commutativity of "(p " ¬p) " q

! by excluded middle

true " q

! by commutativity of ", and since true is a zero for "true.

(b) q " r # (¬r # q)is a tautology, since

q " r # (¬r # q)

! by implication

¬(q " r) " (¬r # q)

! by implication

¬(q " r) " (¬¬r " q)

! by double negation

¬(q " r) " (r " q)

! by commutativity

(r " q) " ¬(q " r)

! by excluded middle

true

Page 85: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

81

(c) (p ! ¬q) " ((q ! ¬r) " (r ! ¬p)) is not a tautology, since it is false in the casethat p,q, and r are all true.

(d) (p # (q # r)) # ((p ! ¬q) " r) is not a tautology. Consider the cases where p isfalse: the antecedent is true (since false # (q # r)); the consequent reduces to r .Now, if r is false, then the proposition (p # (q # r))# ((p ! ¬q) " r) reduces totrue # false, which in turn is false.

13. Show that the following pairs of propositions are logically equivalent.

(a) p # q, ¬q # ¬p; consider the truth tables for the two propositions:

p q p # q ¬q # ¬pt t t f t ft f f t f ff t t f t tf f t t t t

Since they are identical, the two propositions are logically equivalent.(b) (p " q) ! r , (p ! r) " (q ! r);

p q r (p " q) ! r (p ! r) " (q ! r)t t t t t t t tt t f t f f f ft f t t t t t ft f f t f f f ff t t t t f t tf t f t f f f ff f t f f f f ff f f f f f f f

Since they are identical, the two propositions are logically equivalent.(c) ¬p ! ¬q # ¬r , r # q " p;

p q r ¬p ! ¬q # ¬r r # q " pt t t f f f t f t tt t f f f f t t t tt f t f f t t f t tt f f f f t t t t tf t t t f f t f t tf t f t f f t t t tf f t t t t f f f ff f f t t t t t t f

Since they are identical, the two propositions are logically equivalent.(d) ¬p " q # r , (p ! ¬q) " r .

p q r ¬p " q # r (p ! ¬q) " rt t t f t t f f tt t f f t f f f ft f t f f t t t tt f f f f t t t tf t t t t t f f tf t f t t f f f ff f t t t t f t tf f f t t f f t f

Page 86: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

82

Since they are identical, the two propositions are logically equivalent.

14. Show that the proposition (¬p # q)# (p # ¬q) is not a tautology.

Consider the proposition carefully. It is of the form$# %. If it is not a tautology, thenwe must be able the find some assignment to the propositional variables that makes$ # % false. Fortunately, this is only in the case that the antecedent is true, but theconsequent is false. The consequent is also an implication, and if it is to be false itmust be that its antecedent is true, but its consequent is false. So we have that p mustbe true, and ¬q false. The latter is better expressed by saying that q must be true. Sothis assignment also make the antecedent (that is $) true? Of course it does, since $’santecedent is ¬p which must be false if p is true: thus $ is true. To illustrate the valueof the proposition in the state where both p and q are true, we display just that row ofthe truth table:

p q (¬p # q) # (p # ¬q)t t f t f f f

Thus, the proposition has at least one f in its truth table, and so it cannot be a tautology.

15. Show that the following argument is valid: p # q,¬q $ ¬p.

First of all, we draw up the truth tables for the three propositions in the argument:

p q p # q ¬q ¬pt t t f ft f f t ff t t f tf f t t t @@

The argument is valid if, whenever both the premisses are true, then so is the conclu-sion. In fact, there is only one row in which both premisses are true, and this has beenindicated by the @@ mark; clearly, in this state, the conclusion is also true. Thus, theargument is valid.

16. Show that the following argument is valid: p ! q,q $ p.

p q p ! qt t t @@t f ff t ff f t

The argument is valid, since whenever both the premisses are true, then so is the con-clusion.

17. Show that the following argument is a fallacy: p # q $ ¬p # ¬q.

p q p # q ¬p # ¬qt t t f t ft f f f t tf t t t f f @@f f t t t t

Page 87: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

83

The argument is a fallacy, since there is a state in which both the premisses are true,but the conclusion is not.

18. Test the validity of the following argument:

If I study, then I will not fail mathematics.If I do not play Lemmings, then I will study.

But I failed mathematics.Therefore I played Lemmings.

Let’s symbolise this argument by letting S stand for “I study”; F stand for “I fail math-ematics”; L stand for “I played Lemmings”. The argument may now be restated as

S # ¬F ,¬L # S , F $ L.

The appropriate truth table is

S F L S # ¬F ¬L # St t t f f f tt t f f f t tt f t t t f tt f f t t t tf t t t f f t @@f t f t f t ff f t t t f tf f f t t t f

The argument is valid, since whenever all three of the premisses are true, then so is theconclusion.

19. What conclusion can be drawn from the truth of ¬p # p? Let’s calculate, starting fromthe proposition, and seeing where it takes us:

¬p # p

! by implication

¬¬p " p

! by double negation

p " p

! by idempotence of "p

So, we have calculated that ¬p # p is equivalent to p; thus, if ¬p # p is true, then so isp.

20. (Stanat) For each of the following expressions, use identities to find equivalent expres-sions which use only ! and ¬ and are as simple as possible.

(a)

p " q " ¬r

! by double negation (twice)

Page 88: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

84

¬¬p " ¬¬q " ¬r

! by De Morgan’s Law (2)

¬(¬p ! ¬q) " ¬r

! by De Morgan’s Law (2)

¬((¬p ! ¬q) ! r)

(b)

p " (¬q ! r # p)

! by implication

p " ¬(¬q ! r) " p

! by commutativity, associativity, and idempotence of "¬(¬q ! r) " p

! by double negation

¬(¬q ! r) " ¬¬p

! by De Morgan’s Law (2)

¬(¬q ! r ! ¬p)

(c)

p # (q # r)

! by implication

¬p " (q # r)

! by implication

¬p " ¬q " r

! by De Morgan’s Law (2)

¬(p ! q) " r

! by double negation

¬(p ! q) " ¬¬r

! by De Morgan’s Law (2)

¬(p ! q ! ¬r)

21. (Stanat) For each of the following expressions, use identities to find equivalent expres-sions which use only " and ¬ and are as simple as possible.

(a)

p ! q ! ¬r

! by double negation

¬¬(p ! q) ! ¬r

! by De Morgan’s Law (1)

¬(¬(p ! q) " r)

! by De Morgan’s Law (2)

¬(¬p " ¬q " r)

Page 89: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

85

(b)

(p # q " ¬r) ! ¬p ! q

! by implication

(¬p " q " ¬r) ! ¬p ! q

! by distributivity of ! over "(¬p ! ¬p ! q) "(q ! ¬p ! q) "(¬r ! ¬p ! q)

! by idempotence of !(¬p ! q) "(q ! ¬p ! q) "(¬r ! ¬p ! q)

! by idempotence of !(¬p ! q) "(¬p ! q) "(¬r ! ¬p ! q)

! by idempotence of "(¬p ! q) "(¬r ! ¬p ! q)

! since true is a unit for !(true ! ¬p ! q) "(¬r ! ¬p ! q)

! by distributivity of ! over "(true " ¬r) ! ¬p ! q

! since true is a zero for "¬p ! q

! by double negation

¬p ! ¬¬q

! by De Morgan’s Law (1)

¬(p " ¬q)

(c)

¬p ! ¬q ! (¬r # p)

! by implication

¬p ! ¬q ! (¬¬r " p)

! by double negation

¬p ! ¬q ! (r " p)

! by distributivity of ! over "

Page 90: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

86

(¬p ! ¬q ! r) " (¬p ! ¬q ! p)

! by excluded middle

(¬p ! ¬q ! r) " (false ! ¬q)

! since false is a zero for !(¬p ! ¬q ! r) " false

! since false is a unit for "¬p ! ¬q ! r

! by De Morgan’s Law (1)

¬(p " q) ! r

! by double negation

¬(p " q) ! ¬¬r

! by De Morgan’s Law (1)

¬(p " q " ¬r)

22. (Stanat) Establish the following tautologies by simplifying the left-hand side to the formof the right-hand side:

(a) (p ! q # p)! true;

p ! q # p

! by implication

¬(p ! q) " p

! by De Morgan’s Law

¬p " ¬q " p

! by associativity and commutativity of "p " ¬p " ¬q

! by excluded middle

true " ¬q

! since true is a zero for "true

(b) ¬(¬(p " q)# ¬p)! false;

¬(¬(p " q)# ¬p)

! by implication

¬(¬¬(p " q) " ¬p)

! by double negation

¬((p " q) " ¬p)

! by De Morgan’s Law

Page 91: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

87

¬(p " q) ! ¬¬p

! by double negation

¬(p " q) ! p

! by De Morgan’s Law

¬p ! ¬q ! p

! by associativity and commutativity of !p ! ¬p ! ¬q

! by contradiction

false ! ¬q

! since false is a zero !false

(c) ((q # p) ! (¬p # q) ! (q # q))! p;

(q # p) ! (¬p # q) ! (q # q)

! by implication, three times

(¬q " p) ! (¬¬p " q) ! (¬q " q)

! by commutativity and excluded middle

(¬q " p) ! (¬¬p " q) ! true

! since true is a unit for !(¬q " p) ! (¬¬p " q)

! by double negation

(¬q " p) ! (p " q)

! by commutativity of "(p " ¬q) ! (p " q)

! by distributivity of " over !p " (¬q ! q)

! by commutativity and contradiction

p " false

! since false is a unit for !p

(d) ((p # ¬p) ! (¬p # p))! false.

(p # ¬p) ! (¬p # p)

! by implication, twice

(¬p " ¬p) ! (¬¬p " p)

! by idempotence of "

Page 92: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

88

¬p ! (¬¬p " p)

! by double negation

¬p ! (p " p)

! by idempotence of "¬p ! p

! by commutativity and contradiction

false

23. (a) The nand operator (also known to logicians as the She"er stroke), is defined by thefollowing truth table:

p q pnandqt t ft f tf t tf f t

Of course, nand is a contraction of not-and; pnandq is logically equivalent to¬(p !q). Show that

i. (pnandp)! ¬p;

pnandp

! by definition

¬(p ! p)

! by idempotence of !¬p

ii. ((pnandp)nand(qnandq))! p " q;

(pnandp)nand(qnandq)

! using last result twice

¬pnand¬q

! by definition

¬(¬p ! ¬q)

! by De Morgan’s Law

¬¬p " ¬¬q

! by double negation, twice

p " q

iii. ((pnandq)nand(pnandq))! p ! q.

(pnandq)nand(pnandq)

! using first result

Page 93: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

89

¬(pnandq)

! by definition

¬¬(p ! q)

! by double negation

p ! q

(b) Find equivalent expressions for the following, using no connectives other thannand:

i. p # q;

p # q

! ¬p " q

! (pnandp) " q

! ((pnandp)nand(pnandp))nand(qnandq)

This seems really rather long winded, and the problem is that we have trans-lated p # q into a nand expression in an unreasonable way. Instead of trans-lating it literally, let’s massage the expression until we think it is more suitablefor translation.

p # q

! ¬p " q

! ¬(p ! ¬q)

! pnand¬q

! pnand(qnandq)

Now that’s better.ii. p ! q.

p ! q

! (p # q) ! (q # p)! (((pnandp)nand(pnandp))nand(qnandq)) !

(((qnandq)nand(qnandq))nand(pnandp))! (

(((pnandp)nand(pnandp))nand(qnandq))nand

(((qnandq)nand(qnandq))nand(pnandp)))nand(

(((pnandp)nand(pnandp))nand(qnandq))nand

(((qnandq)nand(qnandq))nand(pnandp)))

Page 94: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

90

This is breathtakingly complicated, and again we have proceeded in an unrea-sonable way. Let’s try again.

p ! q

! (p ! q) " (¬p ! ¬q)! ¬(¬(p ! q) ! ¬(¬p ! ¬q))! (¬(p ! q))nand(¬(¬p ! ¬q))! (pnandq)nand(¬(¬p ! ¬q))! (pnandq)nand((¬p)nand(¬q))! (pnandq)nand((pnandp)nand(qnandq))

(c) The nor operator (also known to logicians as the Pierce arrow), is defined by thefollowing truth table:

p q p nor qt t ft f ff t ff f t

For each of the following, find equivalent expressions which use only the nor op-erator.

i. ¬p;

¬p

! ¬(p " p)! pnorp

ii. p " q;

p " q

! ¬¬(p " q)! ¬(pnorq)! ¬((pnorq) " (pnorq))! (pnorq)nor(pnorq)

iii. p ! q.

p ! q

! ¬(¬p " ¬q)! ¬pnor¬q

! (pnorp)nor(qnorq)

24. Give an explanation of the second and third proofs in example 9.

Proof 2. Proof of the contrapositive:

x ' 0

# arithmetic

Page 95: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

91

x % 1 ' 0 ! x % 2 ' 0

# ‘a minus times a minus is a plus’

(x % 1)(x % 2) & 0

! multiplying out

x2 % 3x + 2 & 0

The proof of the real theorem follows easily:

x2 % 3x + 2 < 0 # x > 0

! contraposition

¬(x > 0)# ¬(x2 % 3x + 2 < 0)! negation of comparisons

x ' 0 # x2 % 3x + 2 & 0

! by the above

true

Proof 3. Demonstrate the contradiction:

x2 % 3x + 2 < 0 ! x ' 0

! multiplying second inequality by 3 both sides

x2 % 3x + 2 < 0 ! 3x ' 0

! subtracting 2 from both sides of second inequality

x2 % 3x + 2 < 0 ! 3x % 2 ' %2

! rearranging

x2 < 3x % 2 ! 3x % 2 ' %2

! since %2 < 0

x2 < 3x % 2 ! 3x % 2 < 0

# transitivity of <x2 < 0

# squares of real numbers are always positive

false

We may use this fact to establish the result we want:

(x2 % 3x + 2 < 0 ! x ' 0)# false

! by implication

¬(x2 % 3x + 2 < 0 ! x ' 0) " false

! by unit for "¬(x2 % 3x + 2 < 0 ! x ' 0)

! by De Morgan’s Law (2)

¬(x2 % 3x + 2 < 0) " ¬(x ' 0)! by implication

(x2 % 3x + 2 < 0)# ¬(x ' 0)

Page 96: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

92

! by rewriting negated inequality

(x2 % 3x + 2 < 0)# (x > 0)

Page 97: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Appendix B

Solutions to Chapter 2: PredicateCalculus

1.

(a) ( s : Snake • Reptile(s)(b) ) s : Snake • ¬Poisonous(s)(c) ) c : Person | Child(c) • Present(c)(d) ( e : Person | Executive(e) • HasSecretary(e)(e) ( e : Person | HasSecretary(e) • Executive(e)(f) (p : Person | Vote(p) • PollTax(p)(g) (p : Person; l : Lift | Employee(p) ! p UsesLift l • Goods(l)(h) (p : Person; l : Lift | p UsesLiift l ! Goods(l) • Employee(p)(i) ¬( t : Thing | Gisters(t) • Gold(t)(j) (p,q : Person | EstateAgent(p) ! EstateAgent(q) • p # q(k) ¬(p,q : Person | EstateAgent(p) ! EstateAgent(q) • p = q(l) (p : Person | ¬Brave(p) • ¬DeservesFair(p)

(m) ¬(p : Person | Visitor(p) • Dined(p)(n) ¬)p : Person | Visitor(p) • Dined(p)(o) ¬) t : Thing | InHouse(t) • EscapedKids(t)(p) ) s : Student • Intelligent(s) ! HardWorking(s)(q) ¬) c : Coat | Waterproof (c) • ¬Treated(c)(r) )m : Medicine • Dangerous(m)# TooMuch(m)(s) ( x : Food | Fruit(x) " Veg(x) • Wholesome(x) ! Nourishing(x)(t) ( t : Thing | Enjoyable(t) • Immoral(t) " Illegal(t) " Fattening(t)(u) ( l : Person | Lecturer(l) •

GoodTeacher(l)! WellInformed(l) ! Entertaining(l)(v) (p : Person | VastlyUnderpaid(p) ! Indispensible(p) •

Lecturer(p) " Fireman(p)(w) ¬(a : Actor | Famous(a) • Talented(a)(x) ¬(w : Watch • GoodTimekeeper(w)! RegularlyWound(w) ! ¬Abused(w)(y) ¬(p : Person | TalksALot(p) • SaysAGreatDeal(p)(z) ¬) c : Car | Age(c) > 10 ! SeverelyDamaged(c) • ToBeMended(c)

93

Page 98: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

94

2.

(a) ( e : Elephant | Neat(e) ! WellGroomed(e) • Attractive(e)(b) ) e : Elephant • Gentle(e) ! WellTrained(e)(c) ) e : Elephant • Gentle(e)# (( s : Student • s HasWellGroomed e)(d) ) e : Elephant | Jumbo(e) • WellTranied(e)# gentle(e)(e) ( e : Elephant | WellTrained(e) • Gentle(e)(f) ( e : Elephant | Jumbo(e) ! WellTrained(e) • Gentle(e)(g) ¬) e : Elephant | Gentle(e) • ¬WellTrained(e)(h) ( e : Elephant | WellTrained(e) • Gentle(e)(i) ( e : Elephant | Gentle(e) • WellTrained(e)(j) ( e : Elephant • Gentle(e)! WellTrained(e)(k) ( e : Elephant | Gentle(e) • WellTrained(e)(l) ( e : Elephant • Jumbo(e) " Dumbo(e)

(m) ( s : Student • () e : Elephant • s RidesToGraduationOn e)

3.

(a) ( t : Time • ()u : Time • u isbefore t)(b) ( t ,u : Time | t # u • t isbefore u " u isbefore t(c) ¬) t : Time • ((u : Time • t isbefore u)(d) ¬) t : Time • ((u : Time • u isbefore t)(e) ( t ,u : Time | u isafter t • t isbefore u

4.

(a) )n : Z • 3 < x < 5(b) (n : Z • ()m : Z • m < n)(c) ¬)n : Z • ((m : Z • m ' n)(d) ( x,y : Z • x + y = y + x(e) )m,n : Z • m , n < m + n(f) ¬) x,y , z : Z | x # 0 ! y # 0 ! z # 0 • x3 = y3 + z3

(g) (n : N | n > 2 • (¬) x,y , z : Z | x # 0 ! y # 0 ! z # 0 • xn = yn + zn)

5.

(a) (( bx: T • A(

bx))# ()

by : U • B(

fx,

by))

(b) A(fx,

fy) ! () b

x: T • B(fy))# ((

by : U ;

bz: V • C(

fx,

by ,

bz))

(c) (( bx: T • )

b1

y : U • A(b1

y ,bx) ! ((

b2

y : V • C(b2

y )))# B(fx,

fy)

(d) ( bx: T ;

by : U • A(

fz)# B(

fz)

(e) A(fx)# (B(

fy)# () b

x: T • C(fy)# ((

by : U • D(

bx))))

6. (a) (( x : T • A(x))# ()y : U • B(f (x, z),y)).(b) This substitution is not legal, since there would be variable capture.

(c) (( x : T • )y : U • A(y , x) ! ((y : V • C(y))# B(y , f (x,y)).(d) This substitution is not legal, since there would be variable capture.

Page 99: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

95

(e) This substitution is not legal, since there would be variable capture.

7.

(a) (n : Noise • AppalsMe(n)(b) ) t : Thing | Wicked(t) • ThisWayComes(t)(c) )a : A!rmity | Strange(a) • IHave(a)(d) ( c : TheirCandles • Out(c)(e) (p : Person | Child(p) • ¬His(p)(f) )m : Murder • Performed(m)(g) ) i : Person | Idiot(i) • i told x(h) (p : Person | OfWomanBorn(p) • ¬p ShallHarm Macbeth

8.

(a) )p : Person • ((q : Person | q # p • married(p,q))(b) ( x : Z • ()y : Z • x + y = 0)(c) )y : Z • (( x : Z • x + y = 0)(d) ¬) x : Z • x < 0

9. x # x

10. x = x

11.

(a) ) x : Z • E(x)(b) ( x : Z • E(x) " O(x)(c) ( x : N | P(x) • N (x)(d) ( x : N | E(x) ! P(x) • x = 2(e) ) x : N | E(x) ! P(x) • ((y : N | E(y) ! P(y) • y = x)(f) ¬( x : Z • O(x)(g) ¬( x : Z | P(x) • O(x)(h) ( x : Z | ¬E(x) • O(x)

12. Take p to be “x is even”, and q to be “x is odd”.

13. take p and q as in the answer to part 12.

14.

(a) ( i, j : N | 1 ' i ' 20 ! 1 ' j ' 30 • Ai,j & 0(b) ( j : N | 1 ' j ' 30 • A4,j > 0 ! A15,j > 0(c) ) i, j : N | 1 ' i ' 20 ! 1 ' j ' 30 • Ai,j = 0(d) ( i : N | 1 ' i ' 20 •

( j : N | 1 ' j < 29 •Ai,j ' Ai,j+1

( i : N | 1 ' i < 19 •( j : N | 1 ' j ' 30 •

Ai,j ' Ai+1,j

15. (a) ) x : s • p(x) ! ((y : s • p(y)# y = x)

Page 100: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

96

(b) It is a generalisation of exclusive-or.

16. (a)

) x : S • p # q

! implication

) x : S • ¬p " q

! ) %" distribution

() x : S • ¬p) " () x : S • q)! generalised De Morgan

¬(( x : S • p) " () x : S • q)! distribution

(( x : S • p)# () x : S • q)

(b) Let x be an arbitrary member of S , and consider first:

(( x : S • p # q) ! (( x : S • p)# specialisation

(p # q) ! (( x : S • p)# specialisation

(p # q) ! p

# propositional calculus

q

# generalisation

( x : S • q

We have proved something of the form (s ! t)# u, which is, by ‘exportation’,equivalentto (s # t)# u. Hence we have shown the required result.

(( x : S • p # q)#((( x : S • p)# (( x : S • q))

(c)

() x : S • p)# () x : S • q)! implication

¬() x : S • p) " () x : S • q)! generalised De Morgan

(( x : S • ¬p) " () x : S • q)# forall implies exists, with monotonicity

() x : S • ¬p) " () x : S • q)! ) %" distribution

) x : S • ¬p " q

! implication

) x : S • p # q

Page 101: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

97

(d)

( x : S • p # N

! implication

( x : S • ¬p " N

! no capture on "(( x : S • ¬p) " N

! generalised De Morgan

¬() x : S • p) " N

! implication

() x : S • p)# N

(e)

) x : S • N # p

! implication

) x : S • ¬N " p

! no capture on "¬N " ) x : S • p

! implication

N # ) x : S • p

(f)

) x : S • p # N

! implication

) x : S • ¬p " N

! no capture on "() x : S • ¬p) " N

! generalised De Morgan

¬(( x : S • p) " N

! implication

(( x : S • p)# N

Page 102: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Appendix C

Solutions to Chapter 3: Set Theory

1. Let M = {r , s, t}. State whether each of the following is correct or incorrect:(a) r + M Correct(c) {r} + M Does not type ch

2. Specify the following set explicitly:

(a) The set of nonnegative integers less than 5: {n : N | n < 5 }.(b) The set of positive multiples of 12 which are less than 65 {n : N | 0 < 12 , n <

65 • 12, n }.

3. State in words and then write in enumeration:

(a) A = { x : N | x2 = 4 } A is the set of all nonnegative numbers whose square is 4:{2}.

(b) B = { x : N | x % 2 = 5 } B is the set of all nonnegative numbers which are 2 greaterthan 5: {7}.

(c) C = { x : N | x > 0 ! x < 0 } C is the set of all nonnegative numbers which are bothgreater than zero and less than zero: ..

(d) D = { x : N | x is a letter in the word “correct” } D is the set of all nonnegativenumbers which are letters in the word “correct”: since numbers are not characters,this is meaningless.

(e) { x : Z | 3 < x < 12 } This is the set of all numbers which lie strictly between 3 and12: {4,5,6,7,8,9,10,11}.

(f) DecimalDigit = { x : N | 0 ' x ' 9 } DecimalDigit is the set of all nonnegativenumbers which lie between 0 and 9: {0,1,2,3,4,5,6,7,8,9}.

(g) { x : Z | x + DecimalDigit } This is the set of all numbers which are also in the setDecimalDigit : {0,1,2,3,4,5,6,7,8,9}.

(h) { x : Z | x = 2 " x = 5 } This is the set of all numbers which are either 2 or 5: {2,5}.

4. Define each of the following at set comprehension terms:

(a) The set of integers between 0 and 100: {n : Z | 0 ' n ' 100 }.(b) The set of integer multiples of 10: {n : Z • 10, n }.(c) The set of human fathers: {p : Person | ()q : Human • p fatherof q) }.

98

Page 103: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

99

(d) The set of tautologies: {p : Proposition | p + TruePropositions }. (This is rather avacuous solution, since it defines the set of tautologies in terms of an undefined setof TruePropositions. Not much progress has been made, and perhaps we shouldreturn to our definition of tautology. This says that a proposition is a tautologyif it evaluates to true in every state. A better set comprehension term might be:{p : Proposition | Eval(p) = True }. We could then go on to model propositions,and explain our method of evaluating a proposition.)

(e) The set of letters a,b, c,d , and e: { l : Letter | l = “a” " l = “b” " l = “c” " l =“d” " l = “e” }.

(f) The even numbers {2,4,6,8, . . .}: {n : N • 2, n }.(g) The countries in the United Nations. This set is not conveniently stated as a set

comprehension term, since there are many countries in the world, and no simplerule for determining membership of the United Nations.

(h) The set of Prime Ministers Wilson,Callaghan,Thatcher , and Major : {p : Person |p = Wilson " p = Callaghan " p = Thatcher " p = Major }.

5. Which sets are finite?(a) The months of the year. Finite. (b) {1,2,3, . . . ,99,100}. Finite.(c) The people living on the earth. Finite. (d) { x : N | x is even }. Infinite.(e) {1,2,3, . . .}. Infinite.

6. Which of these sets are equal?

(a) { x : Letter | x is in the word “follow” }.(b) The letters which appear in the word “wolf ”.

(c) { x : Letter | x is in the word “flow” }.(d) The letters which appear in the word “flower”.

(e) The letters f , l,o, and w .

(f) { x : Z | x is even and x2 is odd }(g) { x : Z | ()y : Z • x = 2, y) }(h) {1,2,3}(i) {0,2,%2,3,%3,4,%4, . . .}(j) { x : Z • 2, x }(k) {3,3,2,1,2}(l) { x : Z | x3 % 6, x2 % 7, x % 6 = 0 }

We have that

• 6a = 6b = 6c = 6e = {“f ”, “l”, “o”, “w”};• 6f = 6l = .;

• 6g = 6j = {n : Z | n is even }; and

• 6h = 6k = {1,2,3}.

7. Which of these sets is the empty set?

(a) A = { x : Letter | x precedes a in the alphabet }. Empty.

(b) B = { x : N | x2 = 9 and 2, x = 4 }. Empty.

Page 104: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

100

(c) C = { x : N | x # x }. Empty.

(d) D = { x : N | x + 8 = 8 }. Nonempty.

(e) {n : Z | n > 2 ! () x,y , z : N | x # 0 ! y # 0 ! z # 0 • xn+yn = zn) }. Empty. (Untilrecently, no one could answer this question. It relies on the (in)famous Fermat’sLast Theorem. This year, a Cambridge mathematician working in the U.S.A. claimedto have a lengthy proof.)

8. List all the subsets of the following sets

(a) {., {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}}(b) This set is ill-formed.

(c) Since this set contains the last, it too is ill-formed.

(d) {., {.}} Notice that this set is not ill-formed (consider the types of the empty setsinvolved).

(e) {., {.}, {{.}}, {., {.}}}(f) The required set has 2 elements: {., {{1,2}}}.(g) This set is ill-formed.

9. Let the following sets of figures in the Euclidean plane be defined:

Q = { x : Euclidean | x is a quadrilateral }H = { x : Euclidean | x is a rhombus }R = { x : Euclidean | x is a rectangle }S = { x : Euclidean | x is a square }

Which of these sets are proper subsets of the others?

S 2 R 2 Q

S 2 H 2 Q

10. Does every set have a proper subset? No—the empty set has no proper subsets.

11. Prove that if A is a subset of the empty set ., then A =..

Proof Remembering that nothing belongs to the empty set, we proceed as follows:

A / .! by the definition of subset

( x : X • x + A # x + .! Since nothing belongs to the mpty set

( x : X • x + A # false

! by the definition of implication

( x : X • ¬(x + A) " false

! since false is a unit for "( x : X • x $ A

! by the definition of empty set

A =.

Page 105: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

101

12. How does one prove that a set A is not a subset of a set B? One very simple way isto exhibit a member of A that does nbot belong to B. Prove that A = {2,3,4,5} is nota subset of B = { x : N | x is even }. 3 is an element of A that does not belong to B;therefore, A is not a subset of B.

13. Let A,B, and C be sets. If A + B and B + C , is it possible that A + C . This is impossible,since the three assertions would not typecheck simultaneously. If A is a set if numbers,then B must be a set of sets, and C must be a set of sets of sets.

14. Let A,B, and C be sets. Prove or disprove the following assertion

A / B ! B $ C # A $ C .

The assertion is false. Take A =.,B = {1}, and C = {.}.

15. Let V = {d},W = {c,d},X = {a,b, c},Y = {a,b},Z = {a,b,d}. Determine whether each

of the following statements is true or false:

(a) Y / X True. (b) Z -1 Z False. (c) W -1 V(d) V / X False. (e) W # Z True. (f) Y -/ Z(g) Z 1 V True. (h) X = W False. (i) V -/ Y(j) W / Y False.

16. Let A = {r , s, t ,u,v ,w},B = {u,v ,w, x,y , z},C = {s,u,y , z},D = {u,v},E = {s,u}, andF = {s}. Let X be an unknown set. Determine which sets A,B,C ,D,E , or F can equal X if

we are given the following information:(a) X / A and X / B. X = D (b) X -/ B and X / C . X = C(c) X -/ A and X -/ C . X = B (d) X / B and X -/ C . X = B

17. Let A be a subset of B and let B be a subset of C ; suppose that a + A,b + B, c + C , and

suppose that d $ A, e $ B, f $ C . Which statement must be true?(a) a + C , True (b) d + B, Can’t(d) e $ A, True (e) c + A, Can’t

18. In the Venn diagrams below, shade the set A3 B:

A B

A

BA

B

A

B

19. Let A = {1,2,3,4},B = {2,4,6,8}, and C = {3,4,5,6}. Find

(a) {1,2,3,4,6,8}(b) {1,2,3,4,5,6}(c) {2,3,4,5,6,8}(d) {2,4,6,8}(e) {1,2,3,4,5,6,8}(f) {1,2,3,4,5,6,8}

20. Prove that A and B are subsets of A3 B.

Page 106: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

102

Proof

A 2 A3 B

! by the definition of subset

( x : X • x + A # x + A3 B

! by the definition of set union

( x : X • x + A # x + A " x + B

! by propositional calculus

( x : X • true

! by predicate calculus

true

The other case is symmetrical.

21. Prove that set union is idempotent, that is, that A = A3A.

Proof

A = A3A

! by the definition of equality

( x : X • x + A ! x + A3A

! by the definition of set union

( x : X • x + A ! x + A " x + A

! by the idempotence of "( x : X • x + A ! x + A

! by predicate calculus

true

22. Prove that A = A3..

Proof

A = A3.! by the definition of equality

( x : X • x + A ! x + A3.! by the definition of set union

( x : X • x + A ! x + A " x + .! since nothing is in the empty set

( x : X • x + A ! x + A " false

! by propositional calculus (unit for ")

( x : X • x + A ! x + A

! by predicate calculus

true

23. Prove that if A3 B =., then both A and B are empty.

Page 107: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

103

Proof

A3 B =.

! by the definition of equality

( x : X • x + A3 B ! x + .

! since nothing is in the empty set

( x : X • x + A3 B ! false

! by predicate calculus

( x : X • ¬(x + A3 B)

! by the definition of set union

( x : X • ¬(x + A " x + B)

! DeMorgan’s Law

( x : X • x $ A ! x $ B

! by predicate calculus

(( x : X • x $ A) ! (( x : X • x $ B)

! by the definition of the empty set

A =. ! B =.

24. In the Venn diagrams below, shade the set A4 B:

A B

A

BA

B

A

B

25. Let A = {1,2,3,4},B = {2,4,6,8}, and C = {3,4,5,6}. Find

(a) {2,4}(b) {3,4}(c) {4,6}(d) {2,4,6,8}(e) {4}(f) {4}

26. Prove that A4 B is a subset of A and of B.

Page 108: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

104

Proof

A4 B / A

! by the definition of subset

( x : X • x + A4 B # x + A

! by the definition of intersection

( x : X • x + A ! x + B # x + A

! by propositional calculus

( x : X • true

! by predicate calculus

true

27. Prove that set intersection is idempotent, that is, that A = A4A.

Proof

A = A4A

! by the definition of equality

( x : X • x + A ! x + A4A

! by the definition of intersection

( x : X • x + A ! x + A ! x + A

! by the idempotence of !( x : X • x + A ! x + A

! by the idempotence of !( x : X • true

! by predicate calculus

true

28. Prove that A4. =..

Proof

A4. =.

! by the definition of equality

( x : X • x + A4.! x + .

! by the definition of empty set

( x : X • x + A4.! false

! by the propositional calculus

Page 109: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

105

( x : X • ¬(x + A4.)! by the definition of intersection

( x : X • ¬(x + A ! x + .)! by the definition of empty set

( x : X • ¬(x + A ! false)! since false is a zero for !( x : X • ¬false

! by propositional calculus

( x : X • true

! by predicate calculus

true

29. In the Venn diagrams below, shade the set A \ B:

A B

A

BA

B

A

B

30. Let A = {1,2,3,4},B = {2,4,6,8}, and C = {3,4,5,6}. Find

(a) {1,3}(b) {5,6}(c) {2,8}(d) {6,8}(e) .(f) {1}(g) {1,3,4}

31. Prove that A \ B is a subset of A.

Proof

A \ B / A

! by the definition of subset

( x : X • x + A \ B # x + A

! by the definition of \( x : X • x + A ! x $ B # x + A

! by propositional calculus

( x : X • true

! by predicate calculus

true

32. Prove that (A \ B)4 B =..

Page 110: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

106

Proof

(A \ B)4 B =.! by the definition of equality

( x : X • x + (A \ B)4 B ! x + .! by the definition of the empty set

( x : X • ¬(x + (A \ B)4 B)

! by the definition of intersection

( x : X • ¬(x + (A \ B) ! x + B)

! by the definition of \( x : X • ¬(x + A ! x $ B ! x + B)

! by contradiction

( x : X • ¬(x + A ! false)

! since false is a zero

( x : X • ¬false

! by propositional calculus

( x : X • true

! by predicate calculus

true

33. Prove that if A \ B =., then A is a subset of B.

Proof

A \ B =.! by the definition of equality

( x : X • x + A \ B ! x + .! by the definition of the empty set and propositional calculus

( x : X • ¬(x + A \ B)

! by the definition of \( x : X • ¬(x + A ! x $ B)

! by DeMorgan

( x : X • x $ A " x + B

! by propositional calculus

( x : X • x + A # x + B

! by the definition of subset

A / B

34. Prove that A \ B is a subset of A3 B.

Page 111: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

107

Proof

A \ B / A3 B

! by set theory

( x : X • x + A ! x $ B # x + A " x + B

! by propositional calculus

( x : X • true

! true

true

35. Prove that A / B implies A4 B = A.

Proof

A4 B = A

! by the definition of equality

( x : X • x + A4 B ! x + A

! by the definition of intersection

( x : X • x + A ! x + B ! x + A

! by propositional calculus

( x : X • (x + A ! x + B # x + A) ! (x + A # x + A ! x + B)

! by propositional calculus

( x : X • true ! (x + A # x + A ! x + B)

! by propositional calculus

( x : X • x + A # x + A ! x + B

! by propositional calculus

( x : X • x + A # x + B

! by set theory

A / B

36. Prove that A / B implies A3 (B \A) = B.

A / B

! by definition of /( x : X • x + A # x + B

! by propositional calculus

( x : X • x $ A " x + B

! by propositional calculus

Page 112: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

108

( x : X • (x $ A " x + B) ! (x $ B " x + B)

! by propositional calculus

( x : X • (x $ A ! x $ B) " x + B

! by propositional calculus

( x : X • (¬(x + A " x + B) " x + B) ! (x $ B " x + A " x + B)

! by propositional calculus

( x : X • ((x + A " x + B)# x + B) ! (x + B # (x + A " x + B))

! by propositional calculus

( x : X • (x + A " x + B)! x + B

! by propositional calculus

( x : X • (x + A " (x + B ! x $ A))! x + B

! by definition of \, 3, and equality

A3 (B \A) = B

37. (a) Prove that set di!erence is not commutative. Consider a counterexample: {1}\. #. \ {1}.

(b) Is it possible for that A \ B = B \A? Under what conditions could this occur?

A \ B = B \A

! by set theory

( x : X • x + A ! x $ B ! x + B ! x $ A

! by propositional calculus

( x : X • (x + A ! x $ B # x + B ! x $ A) ! (x + B ! x $ A # x + A ! x $ B)

! by propositional calculus

( x : X • (x $ A " x + B) ! (x $ B " x + A)

! by propositional calculus

( x : X • (x + A # x + B) ! (x + b # x + A)

! by propositional calculus

( x : X • x + A ! x + B

! by set theory

A = B

(c) Is set di!erence associative? Take the following as a counterexample:

{1,2} \ ({1} \ {1,2})= {1,2} \.= {1,2}({1,2} \ {1}) \ {1,2}= {2} \ {1,2}=.

Page 113: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

109

38. Let A,B, and C be arbitrary sets. Express A3 B 3 C as a union of disjoint sets.

((A \ B) \ C)3 ((B \A) \ C)3 ((C \A) \ B)3 (A4 B 4 C)

39. Let A,B, and C be arbitrary sets.

(a) Show that if C / A and C / B then C / A 4 B. (That is, A 4 B is the largest setcontained in both A and B.)

C / A ! C / B

! (( x : X • x + C # x + A) ! (( x : X • x + C # x + B)! ( x : X • x + C # x + A ! x + C # x + B

! ( x : X • (x $ C " x + A) ! (x $ C " x + B)! ( x : X • x $ C " (x + A ! x + B)! ( x : X • x + C # (x + A ! x + B)! ( x : X • x + C # x + A4 B

! C / A4 B

(b) Show that if C 1 A and C 1 B then C 1 A 3 B. (That is, A 3 B is the smallest setwhich contains both A and B.)

C 1 A ! C 1 B

! (( x : X • x + A # x + C) ! (( x : X • x + B # x + C)! ( x : X • (x + A # x + C) ! (x + B # x + C)! ( x : X • (x $ A " x + C) ! (x $ B " x + C)! ( x : X • (x $ A ! x $ B) " x + C

! ( x : X • ¬(x + A " x + B) " x + C

! ( x : X • (x + A " x + B)# x + C

! ( x : X • x + A3 B # x + C

! C 1 A3 B

40. Suppose that A # . and that A 3 B = A 3 C . Show that it does not necessarily followthat B = C . Consider the case where B and C are di!erent subsets of A. For example,choose A = {1,2}, B = {1}, and C = {2}. Suppose in addition that A 4 B = A 4 C ; canyou now conclude that B = C? Consider what would happen if we could find x suchthat x + B but x $ C . Since x + B, we clearly have x + A4B. Now, this is equal to A4C ,so x + A or x + C . We know that the latter is false, so we have x + A. So x + A4 B, andbecause A4B = A4C we know that x + A4C . Therefore x + A and x + C . Now we havea contradiction, so we know that there is no such x. Therefore B / C . By symmetryC / B, so B = C .

41. Prove the absorption laws:

(a) A3 (A4 B) = A

( x : X • x + (A3 (A4 B))! ( x : X • x + A " (x + A ! x + B)! ( x : X • (x + A ! true) " (x + A ! x + B)

Page 114: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

110

! ( x : X • x + A ! (true " x + B)! ( x : X • x + A ! true

! ( x : X • x + A

(b) A4 (A3 B) = B

( x : X • x + (A4 (A3 B))! ( x : X • x + A ! (x + A " x + B)! ( x : X • (x + A " false) ! (x + A " x + B)! ( x : X • x + A " (false ! x + B)! ( x : X • x + A " false

! ( x : X • x + A

42. In each of the following, find the generalised union and generalised intersection.

(a) {.}&{.} =.,

%{.} =.

(b) {., {1}}&{., {1}} =.,

%{., {1}} = {1}

(c) {{a}, {b}, {a,b}}&{{a}, {b}, {a,b}} =.,

%{{a}, {b}, {a,b}} = {a,b}

(d) { i : N • {i} }&{ i : N • {i} } =.,

%{ i : N • {i} } = N

43. Specify the power sets of the following.

(a) P{a,b, c} = {., {a}, {b}, {c}, {a,b}, {b, c}, {a, c}, {a,b, c}}(b) P{{a,b}, {c}} = {., {{a,b}}, {{c}}, {{a,b}, {c}}}(c) P{{a,b}, {b,a}, {a,b,b}} = {., {{a,b}}}

44. Let Sn = {a0,a1, . . . ,an}, and Sn+1 = {a0,a1, . . . ,an,an+1}. Describe how P Sn and P Sn+1

are related. P Sn+1 contains all the members of P Sn, together with all the sets obtainedby taking the union of each member of P Sn with {an+1}.

45. Write a program that decides if two input sets are equal or if one is contained in theother. Assume that all input sets are finite subsets of N.

46. (Stanat) Programming Problems

(a) Write a program to generate the power set of {0,1,2, . . . ,n} for any natural numbern given as input.

(b) i. Write a program which accepts specifications of two finite subsets of the natu-ral numbers, A and B, and prints a nonredundant list of the elements of A3 Band A4 B.

ii. Write a program to determine for a given set A and an arbitrary n + N whetheror not n + A.

Page 115: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Appendix D

Solutions to Chapter 4: Relations

1. Show that the relation divides, which was introduced in Example 46.2, is a partial or-dering on N. Recall the definition of divides:

divides == {a,b : Z | ()m : Z • b = m , a) }

and the notion of a partial ordering:

(a) a : a (reflexivity);

(b) a : b ! b : a # a = b (antisymmetry); and

(c) a : b ! b : c # a : c (transitivity).

Now, divides is reflexive, since

a divides a

! by definition of divides

)m : Z • a = m , a

A by existential introduction

1 + Z ! a = 1, a

! since 1 is an integer

true ! a = 1, a

! since true is a unit for !a = 1, a

! by arithmetic

a = a

! by reflection

true

The argument for antisymmetry is as follows. First, notice that if we have the twoequations b = m , a and a = n , b, then m and n are both 1.

b = m , a ! a = n , b

# rewriting the first equation using the second

111

Page 116: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

112

b = m , n , b

# by arithmetic

m , n = 1

! by arithmetic

m = 1 ! n = 1

Now, we can use the definition of divides to prove our result:

a divides b ! b divides a

! by definition of divides

()m : Z • b = m , a) ! ()m : Z • a = m , b)

! by changing the bound variable

()m : Z • b = m , a) ! ()n : Z • a = n , b)

! by predicate calculus

)m,n : Z • b = m , a ! a = n , b

# using previous result

)m,n : Z • b = m , a ! a = n , b ! m = 1 ! n = 1

! by using the one-point rule twice

1 + Z ! b = 1, a ! a = 1, b

# by arithmetic and propositional calculus

a = b

Finally, the argument for transitivity goes like this. If a divides b, then b is some multipleof a, say m , a; if b divides c , then c is some multiple of b, say n , b. Putting thesetogether, we have c is a multiple of a, namely n ,m , a. Formally,

a divides b ! b divides c

! by definition of divides

()m : Z • b = m , a) ! ()m : Z • c = m , b)

! by changing the bound variable

()m : Z • b = m , a) ! ()n : Z • c = n , b)

! by predicate calculus

)m,n : Z • b = m , a ! c = n , b

! rewriting the second equation using the first

)m,n : Z • b = m , a ! c = n ,m , a

# by predicate calculus

)m,n : Z • c = n ,m , a

# by predicate calculus

)m,n : Z • )p : Z • c = p , a

! by predicate calculus

Page 117: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

113

)p : Z • c = p , a

! by changing the bound variable

)m : Z • c = m , a

! by definition of divides

a divides c

2. Explain why ! is an equivalence relation on the set of all propositions. If ! is anequivalence relation, then it must be reflexive, symmetric, and transitive. It has each ofthese properties, since the following are theorems of the propositional calculus:

p ! p

(p ! q)! (q ! p)(p ! q) ! (q ! r)# (p ! r)

Each may be verified using a truth table.

3. Let : be a total ordering on a set A. Define the associated ‘strict ordering’ 7 on A by

a 7 b ! a : b ! a # b.

Prove that 7 is a transitive relation. First, consider a,b, and c which are such that a 7 band b 7 c . Suppose that a = c .

a 7 b ! b 7 c ! a = c

# rewriting the first predicate with the equation

c 7 b ! b 7 c

! by the definition of 7c : b ! c # b ! b : c ! b # c

! rearranging

c : b ! b : c ! b # c

! by antisymmetry of : (it’s a total order)

b = c ! b # c

! by contradiction

false

So, the assumption that a = c leads to a contradiction, so we can conclude that

a 7 b ! b 7 c # a # c.

Transitivity now follows easily.

a 7 b ! b 7 c

! by the previous argument

a 7 b ! b 7 c ! a # c

! by the definition of 7

Page 118: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

114

a : b ! a # b ! b : c ! b # c ! a # c

# by propositional calculus

a : b ! b : c ! a # c

! by transitivity of : (it’s a total order)

a : c ! a # c

! by the definition of 7a 7 c

Is it total? The relation 7 is irreflexive, since we have from its definition that a 7 b #a # b; thus it cannot be a total order. Is it antisymmetric? It is antisymmetric, but onlyin a degenerate way: since we cannot have both a 7 b and b 7 a (since it is irreflexive),the antecedent is false in the predicate that defines the property of antisymmetry:

a 7 b ! b 7 a # a = b,

and so the property holds.

4. Prove the following theorems.

A 6 (B 4 C) = (A 6 B)4 (A 6 C)

(A3 B) 6 C = (A 6 C)3 (B 6 C)

(A4 B) 6 C = (A 6 C)4 (B 6 C)

We prove only the first of these three.

A 6 (B 4 C) = (A 6 B)4 (A 6 C).

Proof Let (x,y) be an arbitrary element of A 6 (B 4 C).

(x,y) + A 6 (B 4 C)

! by Cartesian product membership

x + A ! y + B 4 C

! by property of set intersection

x + A ! (y + B ! y + C)

! since ! distributes over itself

(x + A ! y + B) ! (x + A ! y + C)

! by Cartesian product membership

(x,y) + A 6 B ! (x,y) + A 6 C

! by property of set union

(x,y) + (A 6 B)4 (A 6 C)

Thus, the two sets must be equal.

Page 119: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

115

5. How many binary relations are there on the set {1,2,3}? The set has three members,so there are nine members of the Cartesian product {1,2,3} 6 {1,2,3}. Every memberof the power set of this Cartesian product is a binary relation on the original set; thepower set has 29 elements. Therefore, there are 512 binary relations on the set {1,2,3}.If A has n elements, how many binary relations are there on A? By the same reasoningas in the first part of the question, we have 2n2

binary relations.

6. What kind of properties do the following relations have?

(a) For the set of integers Z, x R y if and only if x and y are both positive or are bothnegative. This is reflexive, symmetric, and transitive (and therefore an equivalencerelation).

(b) For the set of integers Z, x R y if and only if

abs(x % y) = 4 " abs(x % y) = 8 " x = y ,

where abs(z) denotes the absolute value of z. This is reflexive and symmetric. Itis not transitive. Consider as a counterexample the numbers 16, 8, and 4.

7. Consider the set of integers Z. Fill in the following table according to whether therelation possesses the property. A relation is reflexive if every element in the source ofthe relation is related to itself. Thus, the empty relation on the integers is not reflexive,since, for example, (0,0) $ .. However, the Cartesian product Z 6 Z contains everypair of integers; in particular, we have that idZ / Z 6 Z. Thus, the Cartesian product onZ is reflexive. From the Law of Reflexivity, every number is self-identical, so equality isreflexive. The strict inequality “<” is clearly not reflexive, but the non-strict inequality“'” is. We addressed the reflexivity of divides in Question 1. A relation is irreflexive ifno element of the source is related to itself. The empty relation and the strict inequalityare therefore irreflexive. A relation is symmetric if, whenever it relates a to b, it alsorelates b to a. The empty relation is symmetric, but in a rather trivial way, since itrelates nothing. The Cartesian product is the full relation: it relates everything, andso is symmetric. Equality is obviously symmetric, and so therefore is the non-strictinequality, since it contains equality. The strict inequality is not symmetric. A relationis antisymmetric if the only symmetric pairs are of the form (a,a). Again, the emptyrelation trivially satisfies this property. The Cartesian product is not antisymmetric, butequality is. The strict inequality is antisymmetric, but only trivially so. The non-strictinequality and divides are both antisymmetric. A relation is transitive if, whenever a isrelated to b and b to c , then a is related to c . The empty relation is trivially transitive;all the other relations are transitive.

. Z 6 Z = < ' dividesReflexive no yes yes no yes yesIrreflexive yes no no yes no noSymmetric yes yes yes no yes noAntisymmetric yes no yes yes yes yesTransitive yes yes yes yes yes yes

8. Find a nonempty set and a relation on it which is neither reflexive nor irreflexive. Choosethe set to be as small as possible. Take {1,2} as the set, and {1% 1,2% 1}. This isnot reflexive with respect to the set {1,2}, since it does not relate 2 to itself. It is notirreflexive, since 1 is related to itself. What if the set is empty? In Solution 7, we hadthat the empty relation on the set Z is not reflexive, but that is with respect to Z. Ifwe consider the empty relation with respect to the empty set, then it is reflexive, sinceevery element in the empty set is related to itself trivially. Also, it is irreflexive, since noelement is related to itself. If this sounds contradictory, then consider the formalisationof the two statements:

( x : . • x% x + .- ) x : . • x% x + ..

Page 120: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

116

These are not actually contradictions.

9. Construct a binary relation on a nonempty set which is neither symmetric nor anti-symmetric. Choose the set to be as small as possible. Take {1,2,3} as the set, and{1% 2,2% 1,3% 1} as the relation. It is not symmetric, since it contains 3% 1, butnot 1% 3. It is not antisymmetric, since it cotains the pairs 1% 2 and 2% 1. What ifthe set is permitted to be empty? It is both symmetric and antisymmetric.

10. Fill in the following table according to whether the relation possesses the property; ineach row, you may assume that the relations R and S both possess the property indi-vidually. For each relation that does not possess the property, give a counterexample.A relation is reflexive if it contains the identity on the source. So, if R is reflexive, thenany relation which includes R is also reflexive, since it must also contain the identity.R3 S is one such larger relation. If the identity is a subset of both R and S , then it is asubset of their intersection. A relation is irreflexive if it is disjoint from the identity onthe source. If both R and S are disjoint from the identity, then so are R3 S and R4 S .A relation is symmetric if it is its own inverse. Consider the following.

(x,y) + (R3 S)8

! from the definition of relational inverse

(y , x) + R3 S

! from the definition of set union

(y , x) + R " (y , x) + S

! from the definition of relational inverse

(x,y) + R8 " (x,y) + S8

! from the definition of set union

(x,y) + (R8 3 S8)

Thus,

(R3 S)8

= from the previous argument

R8 3 S8

= since both R and S are symmetric

R3 S

So, if R and S are both symmetric, then so is R3 S , since it is its own inverse. A similarargument su"ces to show that R4S is symmetric also. A relation R is antisymmetric ifwe have that R4R8 / id A, for source A. Supposing that both R and S are antisymmetric,

(R3 S)4 (R3 S)8

= from the previous argument

(R3 S)4 (R8 3 S8)

= by the distribution law

(R4 R8)3 (S 4 S8)3 (R4 S8)3 (S 4 R8)

Page 121: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

117

We know that the first two terms are subsets of id A, so in order for the relation R3 Sto be antisymmetric, we need to show that

R4 S8 / id A

and

S 4 R8 / id A.

There is no reason to suppose that either of these is true in the general case. As anexample of two antisymmetric relations whose union is not antisymmetric, take R tobe {1,2} and S to be {2,1}. There are no symmetric pairs in either, so they are bothantisymmetric by default. However, the union has a symmetric pair, namely 1% 2 and2% 1, and thus is clearly not antisymmetric. If we consider the intersection, then weare in a happier position. Again, supposing that both R and S are antisymmetric,

R4 S 4 (R4 S)8

= by the previous argument

R4 S 4 R8 4 S8

= by rearranging

R4 R8 4 S 4 S8

/ since A4 B / A

R4 R8

/ since R is antisymmetric

id A

Notice that we did not use the assumption that both relations were antisymmetric.It seems unlikely that the union of two transitive relations is itself transitive, and acounterexample is not hard to find. Consider {1% 2} for R and {2% 3} for S . Clearly,R3S is not transitive. The intersection of two transitive relations is, however, transitive,as is shown by the following argument.

a% b + R4 S ! b% c + R4 S

! from the definition of intersection

a% b + R ! a% b + S ! b% c + R ! b% c + S

! rearranging

a% b + R ! b% c + R ! a% b + S ! b% c + S

# since R and S are both transitive

a% c + R ! a% c + S

! from the definition of intersection

a% c + R4 S

Union IntersectionR3 S R4 S

Reflexive yes yesIrreflexive yes yesSymmetric yes yesAntisymmetric no yesTransitive no yes

Page 122: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

118

11. Sketch graphs of the following relations on the set of real numbers, and determine whatkinds of properties the relations have.

(a) { x,y : Real | x = y }.(b) { x,y : Real | x2 % 1 = 0 ! y > 0 }.(c) { x,y : Real | abs(x) ' 1 ! abs(y) & 1 }.

-1

y

1

(c)(b)(a)

1-11-1 xx

y

x

y

(a) (b) (c)Reflexive yes no noIrreflexive no no noSymmetric yes no noAntisymmetric yes yes yesTransitive yes yes yes

12. Write a program which takes as input a relation described as a set of ordered pairs anddetermines whether it is reflexive, irreflexive, symmetric, antisymmetric, or transitive.

13. (Stanat & McAllister) Prove or disprove the following assertions.

(a) If R and S are reflexive, then R o9 S is reflexive. R o

9 S is reflexive, providing that itcontains the identity on its source. It is su"cient to prove that (x, x) + R o

9 S , forall x.

(x, x) + R o9 S

! by the definition of composition

)y : A • (x,y) + R ! (y , x) + S

But of course, a good candidate for y is x itself, and since both R and S are reflexive,the resulting predicate

(x, x) + R ! (x, x) + S

is true.

(b) If R and S are irreflexive, then R o9 S is irreflexive. This assertion is not true, and

we o!er a counterexample:

{1% 2} o9 {2% 1} = {1% 1}.

The two relations being composed are irreflexive, but the result is not.

(c) If R and S are symmetric, then R o9 S is symmetric. A relation is symmetric if it is

its own inverse. Consider the inverse of R o9 S .

(x, z) + (R o9 S)8

! by the definition of inverse

Page 123: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

119

(z, x) + R o9 S

! by the definition of composition

)y : A • (z,y) + R ! (y , x) + S

! by the definition of inverse

)y : A • (y , z) + R8 ! (x,y) + S8

! by rearranging

)y : A • (x,y) + S8 ! (y , z) + R8

! by the definition of composition

(x, z) + S8 o9 R8

There is no reason to conclude that (R o9 S)8 = S8 o

9 R8, and so the composition isnot in general symmetric. As a counterexample, consider the following

R = {a% b,b% a}S = {b% c, c% b}

R o9 S = {a% c}

(d) If R and S are antisymmetric, then R o9 S is antisymmetric. This assertion is not

true. Take as the relation R the antisymmetric relation {1% 3,2% 3}, and for Sthe antisymmetric relation {3% 1,3% 2}. Now the composition is

{1% 2,2% 1}

which is not antisymmetric.

(e) If R and S are transitive, then R o9 S is transitive. This assertion is not true, as the

following counterexample shows.

{a% c,b% c} o9 {c% b, c% d} = {a% b,b% d}

14. Prove that dom distributes through 3; that is

dom(R3Q ) = dom R3 dom Q

Does the same hold for ran? What about4?. Let x be an arbitrary member of dom(R3Q ).

x + dom(R3Q )! definition of dom

)y : B • x (R3Q )y

! union of relations

)y : B • x R y " x Q y

! ) %" distribution

()y : B • x R y) " ()y : B • x Q y)! definition of dom

x + dom R " x + dom Q

! definition of 3

Page 124: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

120

x + (dom R3 dom Q )

We have shown that an arbitrary member of dom(R3Q ) is also a member of dom R3dom Q ; hence the sets are equal. A very similar proof can be demonstrated for ran. For4, we cannot establish equality, but can prove inclusion:

dom(R4Q ) / dom S 4 dom Q

15. Prove that dom(S " R) = S 4 (dom R). Let x be an arbitrary member of dom(S " R).

x + dom(S " R)! definition of dom

)y : B • x (S " R)y

! definition of ")y : B • x R y ! x + S

! conjunction-) non-capture

()y : B • x R y) ! x + S

! definition of dom

x + dom R ! x + S

! definition of 4x + (dom R4 S)

Hence, dom(S " R) = S 4 (dom R).

16. Can (R+)+ be simplified?

Yes: R+ is transitive, so taking its transitive closure leaves it unchanged. (R+)+ = R+.

Page 125: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

Appendix E

Solutions to Chapter 5: Functions

1. Draw diagrams to illustrate simple examples of the following classes of function:

(a) partial surjection (not injective)

(b) total surjection (not injective)

(c) partial injection (not surjective)

(d) total injection (not surjective)

(e) bijection

(a) (b)

(c) (d)

(e)

121

Page 126: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

122

2. An important idea in mathematics is in the investigation of whether the combining oftwo entities with a common property yields a result with that property.

(a) Suppose that f and g are both functions. Is f o9 g a function? Prove that your

answer is correct. f o9 g is a function. Suppose it is not. Then, we can find x, y1

and y2 such that x% y1 + f o9 g and x% y2 + f o

9 g, and y1 # y2. Since these arrowsbelong to these relational compositions, we have the existence of mid-points z1

and z2, with

x% z1 + f ! x% z2 + f !z1% y1 + g ! z2% y2 + g

Now, since f is a function, we must have that z1 = z2. Since we now have thatz1 % y1 + g and z1 % y2 + g, and g is a function, we must conclude that y1 = y2.This is a contradiction, hence f o

9 g is a function.

(b) Suppose that f and g are both injective functions. Is f o9 g injective? Prove that

your answer is correct. f o9 g is injective. Otherwise, we have distinct x1 and x2,

with some y such that (f o9 g)x1 = y and (f o

9 g)x2 = y . That is, g(f x1) = g(f x2).In this case, either f x1 = f x2—a contradiction, since f is injective—or, if they arenot equal, then g maps distinct values to the same value y—a contradiction, sinceg is injective. Therefore f o

9 g is injective.

(c) Suppose that f and g are both surjective functions. Is f o9 g surjective? Prove that

your answer is correct. f o9 g is surjective provided the target of f and the source

of g are identical. Otherwise, if the former is a subset of the latter, then there maybe elements in the target of g which cannot be reached from the source of f .

(d) Suppose that f and g are both bijective functions. Is f o9 g bijective? Prove that

your answer is correct. This follows from the previous two answers—with the samecaveat as for surjections.

3. If f and g are functions, then are the following necessarily functions, too?

(a) f 4 g

(b) f 3 g

(c) f \ g

For any that are not necessarily functions, state necessary/su"cient conditions on fand g (maybe in terms of dom or ran for their combination to be a function). f 4 g is afunction, because intersection can only reduce the collection of arrows, so no divergingarrows can be introduced. The same applies to f \ g. f 3 g need not be a function,because there may be some x for which f x = y1 and g x = y2, with y1 # y2. A su"cientcondition for the union of f and g to be a function, then, is that their domains aredisjoint—i.e. that there is no x like the one above:

dom f 4 dom g =.

In fact, this condition is stronger than is necessary. A weaker condition which is stillsu"cient is that where the domains of f and g overlap, they must yield the same results.That is,

( x : dom f 4 dom g • f x = g x

Page 127: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

123

4. If R : A< B is a relation, and f is defined by

f a = R(| {a} |)

then what is the type of f ? Is f partial or total? Surjective? Injective? f : A5 PB. fis total because its value is defined for every member of A (if a is not in dom A, thenf a =.). In general, it will not be surjective or injective.

5. Give a su"cient condition on f and g such that f ? g = g ? f . One condition is thatf ? g = f 3 g, and hence the same conditions apply as those necessary for f 3 g to be afunction (above).

6. Prove this law on overriding and domain restriction:

S " (f ? g) = (S " f )? (S " g)

Consider an arbitrary member of (S " f )? (S " g), say x% y .

x% y + (S " f )? (S " g)! definition of function overriding

x% y + ((dom(S " g))& (S " f ))3 (S " g)! definition of 3

x% y + ((dom(S " g))& (S " f )) " x% y + (S " g)! definition of " and &

(x% y + (S " f ) ! x $ dom(S " g)) " (x% y + g ! x + S)! definition of ", and dom(S " g) = S 4 dom g

(x% y + f ! x + S ! x $ (S 4 dom g)) " (x% y + g ! x + S)! propositional calculus, and definition of 4

(x% y + f ! x + S ! (x $ S " x $ dom g)) " (x% y + g ! x + S)! propositional calculus

(x% y + f ! x + S ! x $ dom g) " (x% y + g ! x + S)! propositional calculus

((x% y + f ! x $ dom g) " x% y + g) ! x + S

! definition of &(x% y + ((dom g)& f ) " x% y + g) ! x + S

! definition of 3x% y + (((dom g)& f )3 g) ! x + S

! definition of ?x% y + (f ? g) ! x + S

! definition of "x% y + S " (f ? g)

This is rather long-winded. Can we improve on it? Yes; we have made use of one identitythat we proved earlier: dom(S " g) = S 4 dom g; we can use others, too:

S " (f ? g)= definition of ?

Page 128: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

124

S " (((dom g)& f )3 g)= distribution of " over 3

(S " ((dom g)& f ))3 (S " g)= property of " and &

((S \ dom g)" f )3 (S " g)= property of ", \, & and 4

((S 4 dom g)& (S " f ))3 (S " g)= property of dom and "

(dom(S " g)& (S " f ))3 (S " g)= definition of ?

(S " f )? (S " f )

7. Prove

f + X ( Y # f (| S 4 T |) = f (| S |)4 f (| T |)

The crucial step in the proof below is to observe that not only do we have

() x : X • x + S ! f x = y ! x + T ! f x = y)# (() x : X • x + S ! f x = y) ! () x : X • x + T ! f x = y))

by the partial distribution of ) over !, but also, we have the converse—under the as-sumption that f + X(Y : since there are no converging arrows, the xs identified by thetwo quantifiers must be the same. Consider, then, an arbitrary member of f (| S 4 T |):

y + f (| S 4 T |)! definition of (| |)

) x : X • x + S 4 T ! f x = y

! definition of 4, and propositional calculus

) x : X • x + S ! f x = y ! x + T ! f x = y

! see above, assuming f + X ( Y

() x : X • x + S ! f x = y) ! () x : X • x + T ! f x = y)! definition of (| |)

y + f (| S |) ! y + f (| T |)! definition of 4

y + f (| S |)4 f (| T |)

Therefore, we have shown

f + X ( T #(y : Y • y + f (| S 4 T |)# y + f (| S |)4 f (| T |)

This is su"cient to prove the result.

8. Let f : A5 B and g : C 5D. The product function h : A 6 C 5 B 6 D is defined as

h(a, c) = (f (a),g(c)).

Prove that h is a bijective function if, and only if, f and g are bijective functions.

Page 129: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

125

9. The infamous “91-function” is defined recursively as follows:

f : N5N

f (x) = x % 10 if x > 100f (x) = f (f (x + 11)) if x ' 100

(a) Show that f (99) = 91.

(b) Prove that f (x) = 91 for all x from 0 to 100.

10. Assuming S and T are finite sets, find expressions for the following, involving #S and#T

(a) #(S 3 T ) = #S + #T % #(S 4 T )(b) #(S \ T ) = #S % #(S 4 T )(c) #(S 6 T ) = #S , #T

(d) #(P S) = 2#S

(e) #(S < T ) = 2#S,#T

There are 2#S,#T relations between S and T . This is because every relation is a subsetof the Cartesian product S 6 T ; there are 2n elements in the powerset of an n-elementset; and there are #S , #T elements in the Cartesian product.

11. For finite sets A and B,

(a) How many functions are there between A and B? The sum of the number of totalfunctions and the number of strictly partial functions—see below.

(b) How many of these are total? #B#A Each member of A must be mapped to some(any) member of B.

(c) How many are strictly partial? The partial functions from A to B are total functionswhen restricted to various subsets of B. The number of such functions, then, isthe sum of the number of total functions to B for each of those subsets.

2#A%1-

i=0

#Bi

(d) How many injections are there from A to B? #BP#A, i.e. (#B)!(#B%#A)! . There are as many

injections as there are ways of choosing (#A) elements of B.

(e) How many surjections are there from A to B? Since it is the target that holds thekey to the definition of a surjection, we can calculate the number of surjections byinduction on the cardinality of the target. Here’s a likely basis. Suppose that A hascardinality m and B has cardinality n. If n = 1, then there is exactly one surjectionfrom A to B: namely, the constant function. If n > 1, then we have

#(A55 B) = #(A5 B)% #NS

where NS = {f : A 5 B | ran f # B}. NS is interesting, because although thefunctions in it are non-surjective w.r.t. B, they are surjective w.r.t. a subset of B.Thus, we have an inductive definition of the size of A55 B. Take C to be a proper

Page 130: Discrete Mathematics - PBworksbilalbajwa.pbworks.com/w/file/fetch/48531985/Text.pdf · Discrete Mathematics ... 1.7 Propositions and Truth Tables ... 2 6 3 Set Theory 30 3.1 Sets

126

subset of B. There are s = #(A55C) surjections to C; there are n!/(#C !,(n%#C)!)subsets of B of the same size; thus, there are

n!/(#C !, (n % #C)!), s

surjections of this size. If we sum this from 1 to n % 1, we get all those functionswhich are not surjections to B. Subtract this from the number of functions fromA to B (which is nm), and we’re done. This this is summarised as follows:

#(A55 B) = S(#A,#B),

where

S(m,1) = 1

S(m,n) = nm %n%1-

j=1

n!/(j !, (n % j)!), S(m, j)

(f) How many bijections are there from A to B? In order to set up a (total) bijection,we must have that #A = #B. The number of distinct bijections will be the numberof ways of choosing all the elements of A; that is (#A)!.

12. The Ministry of Defence has eight di!erent contracts that deal with a high securityproject. Five companies can manufacture the distinct parts called for in each contract,and to keep the project as well protected as possible, it is best to have all five companiesworking on some part. In how many ways can the contracts be awarded so that everycompany is involved? This is simply a matter of counting the total surjections from theset of contracts to the set of companies. i.e. it is S(8,5) = 126 000,