You are on page 1of 130

Discrete Mathematics

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

Contents
1 Propositional Calculus 1.1 Propositions . . . . . . . . . . . . . 1.2 Conjunction . . . . . . . . . . . . . 1.3 Disjunction . . . . . . . . . . . . . 1.4 Negation . . . . . . . . . . . . . . . 1.5 Implication . . . . . . . . . . . . . 1.6 Equivalence . . . . . . . . . . . . . 1.7 Propositions and Truth Tables . 1.8 Tautologies and Contradictions . 1.9 Arguments . . . . . . . . . . . . . 1.10 Problems . . . . . . . . . . . . . . . 2 Predicate Calculus 2.1 Substitution . . . . . . . . 2.2 Validity and Satisability 2.3 Properties of Quantiers 2.4 Multiple Quantiers . . . 2.5 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 . 1 . 2 . 2 . 3 . 3 . 4 . 5 . 7 . 9 . 12 . . . . . . . . . . . . . . . . . . . . . . . 16 20 21 21 25 26 30 30 31 33 34 34 35 37 38 38 38 39 40 40 41 42 43 43 44

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3 Set Theory 3.1 Sets . . . . . . . . . . . . . . . 3.2 Notation . . . . . . . . . . . . 3.3 Finite and Innite Sets . . . 3.4 Equality of Sets . . . . . . . . 3.5 Empty Set . . . . . . . . . . . 3.6 Subsets . . . . . . . . . . . . . 3.7 Proper Subset . . . . . . . . . 3.8 Sets of Sets . . . . . . . . . . 3.9 Power Set . . . . . . . . . . . 3.10 Disjoint Sets . . . . . . . . . . 3.11 Venns Diagrams . . . . . . . 3.12 Union . . . . . . . . . . . . . . 3.13 Intersection . . . . . . . . . . 3.14 Dierence . . . . . . . . . . . 3.15 Properties of Set Operations 3.16 Generalised Operations . . . 3.17 Axiomatic Set Theory . . . . 3.17.1 Axiomatics . . . . . .

3.17.2 Cantors and Russells Paradoxes . . . . . . . . . . . . . . . . . . . . . . . . . 44 3.17.3 The Zermelo-Fraenkel Axioms for Set Theory . . . . . . . . . . . . . . . . . . 45 3.18 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 4 Relations 4.1 Ordered Pairs . . . . . . . . . 4.2 Cartesian Products . . . . . . 4.3 Relations . . . . . . . . . . . . 4.4 Inverse Relations . . . . . . . 4.5 Identity Relation . . . . . . . 4.6 Properties of Relations . . . 4.7 Equivalence Relations . . . . 4.8 Source, Target, Domain, and 4.9 Orderings . . . . . . . . . . . 4.10 Composition . . . . . . . . . 4.11 Relational Restriction . . . . 4.12 Relational Closure . . . . . . 4.13 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 52 53 55 56 57 57 59 60 61 61 62 63 63 66 68 68 71 72 72 73 73 74 75 77 93 98 111 121

5 Functions 5.1 Total and Partial Functions . . . . . 5.2 Special Functions . . . . . . . . . . . 5.3 Relational Operations on Functions 5.4 Relations and Functions . . . . . . . 5.5 Cardinality . . . . . . . . . . . . . . . . 5.6 The Pigeonhole Principle . . . . . . . 5.7 Functional Composition . . . . . . . 5.8 Functional Overriding . . . . . . . . . 5.9 Problems . . . . . . . . . . . . . . . . .

A Solutions to Chapter 1: Propositional Calculus B Solutions to Chapter 2: Predicate Calculus C Solutions to Chapter 3: Set Theory D Solutions to Chapter 4: Relations E Solutions to Chapter 5: Functions

ii

Chapter 1

Propositional Calculus
1.1
1. 2. 3. 4.

Propositions
4 is a prime number. 3 + 3 = 6. 2 is an even integer, but 3 is not. My most recently written program always halts, if its allowed to run for long enough.

A proposition is some statement such as

As we shall see, a fundamental property of a proposition is that it is either true or false, but not both. In the example, the rst proposition is false, and the second and third are true. The last may well be rather dicult to determine, and its truth depends on important results in the theory of computation. However dicult it may be to determine, the last proposition is denitely either true or false, but not both. This truthfulness or falsity of a proposition is called its truth value. Compound propositions are composed of subpropositions and various connectives. A fundamental property of a compound proposition is that its truth value is completely determined by the truth values of its subpropositions and their connectives. A propositional variable denotes an arbitrary proposition with an unspecied truth value. We will use the letters p, q, r , with or without subscripts, for these variables. Sometimes we use other, upper-case letters to denote specic propositions, such as H for the proposition My most recently written program always halts, if its allowed to run for long enough. Propositions may be connected in various ways. The following table describes one unary and four binary connectives, arranged in descending order of operator precedence: negation conjunction disjunction implication equivalence not and or implies if and only if is equivalent to

The table gives the connectives symbol, its name, and how it is pronounced.1 Using the notion of precedence, we can see that the proposition p q r
1 Note:

qpr

p and q or p conjoined with q; not p and-ed with q.

is equivalent to the parenthesised version (((p) q) r ) (q (p r ))

Example 1 Using these connectives, we can build up compound propositions: Jaa 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 compound proposition called the conjunction of the original propositions; for example, Roses are red and 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 compound proposition called the disjunction of the original propositions; for example, The bridge is safe, 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. In this way, it is inclusive or.
Example 2 A lawyer might well use the term and/or to denote inclusive or. What if we wanted to describe exclusive or? For example, For example, a bar-room lawyer might take the sentence You may have a beer or you may have a whisky to mean You may have a beer or you may have a whisky, but not both. How should we formalise this? Using B to symbolise 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 constituent parts. The major break occurs at but, which in this context signals a conjunction: ( B or W ) (not both B and W ). The rst 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 ).

The phrase both B and W is simply a stylistic way of saying B and W . Thus, You may have 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 is using the unary connective not; for example, It is not the case that roses are red and violets are blue. The negation is written symbolically as p and is read not p. It is true exactly when 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 for the rst time, and yet it is perhaps the most important connective from the point of view of deductive techniques. In modelling, it is used to formalise sentences of the form If p, then q; for example, If I eat Jaa cakes, then I shall get fat is formalised as I eat Jaa cakes I get fat. However, it does have the property that anything follows from a contradiction, and at rst sight that is slightly surprising. Thus, the sentence If Napoleon is German, then Im a Dutchman, when translated into Napoleon is German Im a Dutchman, becomes a proposition that expresses a fact, even though Napoleon isnt German and Im not Dutch. I have found it best to think of it as an ordering between the truth values: p q should be read as p implies q, or p is stronger than q. This relation on the two truth values is very simple: false is stronger than true, and true is weaker than false. Furthermore, each truth value is as strong as itself. This gives us the observation about implication that p q is true, except in the case that p is true but q is false. It is in this case that we are asking the question Is true stronger than false?; the answer is, by denition, no.2 In the proposition p q, the proposition p is called the antecedent, and the proposition q is called the consequent.
Example 3 For example, the sentence If the wind is not too strong and the thunderstorm has nished, then we can sail the boat may be rendered into symbols as (with obvious abbreviations): W T S And the sentence If you are right, then I apologise, but I think that you are wrong may be rendered as (R A) W
2 It is easy to remember which truth value is stronger, if you consider them as two program specications. A program specication may be regarded, in the simplest case, as a predicate that must be satised (made true) by any program that is claimed to implement it. If you are asked to implement a program that satises the specication 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 satises the specication false, then no program you can devise will be satisfactory. Thus, true is a very weak specication, and false a very strong one.

And nally, the sentence You will nd him, if you look under the desk may be rendered as DF

The last example shows the importance of identifying the antecedent and the consequent correctly. This can be harder than you might imagine at rst 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 the sentence, we can see that your having a ticket is necessary in order for you to enter; however, it may not be sucient.3 After all, we might want to let your sort in, even if you do have a ticket. Therefore, If you enter, then (at least) you have a ticket is closer in meaning to our original sentence. Thus, we formalise p only if q as pq and p if q as qp The converse of p q is the proposition q p, and the contrapositive of p q is the proposition q p.

1.6

Equivalence

The nal propositional connective that we shall consider is equivalence. The proposition p q should be read as p is equivalent to q, or p if and only if q (the latter is often q is true if and only if p and q have the same abbreviated to p i q).4 The equivalence p truth value.
Example 4 For example, the sentence A pass in Foundations is equivalent to a pass in Management is formalised as F M

And the sentence If and only if the time is right, will the revolution succeed is formalised as T R

The fact that equivalence is used to formalise a sentence of the form p if and only if q gives a clue as to the relation should between equivalence and implication. Indeed, the equivalence connective is sometimes called the biconditional, as is explained in the following example. The sentence You will pass the Diploma if and only if you pass the assessment means
3 People sometimes read implications in this way. Thus, p q may be read as p is a sucient condition for q, or equivalently as q is a necessary condition for p. 4 Some people also read the equivalence p q as p is a necessary and sucient condition for q.

5 p t t f f p t t f f q t f t f q t f t f pq t f f f p t t f f q t f t f p t t f f p t f f t q t f t f q pq t t t f p t f p f t

pq t f t 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 only if 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 complicated compound propositions. As we said above, the truth value of these compound propositions depends 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 use the 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 tables are presented in Figure 1.1. Since we wish to be quite general about this, the truth tables do not use actual propositions which 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 possible situations regarding two propositional variables: they are both true, or one of them is true and one is false, or they are both false. In order to make the table easier to read, the truth values have been abbreviated as t and f . There are 22 combinations; if there were three propositional 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 by the conjunction in each of these situations: the conjunction p q is true exactly when both p and q are true, and false otherwise. These basic truth tables may be used to compute the truth values of compound propositions. There should be as many propositional variables in the left-most columns as occur in the compound proposition, and some consistent policy should be adopted for the assignment of the truth values, such as counting down in binary notation.
Example 5 The truth table, for example, of the proposition (p q) may be constructed as follows:

6
p t t f f q t f t f q f t f t p q f t f f (p q) t f t t

The rst two columns set out the various combinations of the values of the propositional variables, as before. There are further columns for progressively more complicated subpropositions, the truth values at each step being determined by the rules embodied in the truth tables. Finally, at the right-hand side of the table there is the truth value of the compound proposition, with one entry for each of the possible combinations of values for p and q. The third and fourth columns contain intermediate results, and do not form part of the nished truth table for (p q). Another way of constructing the truth table is as follows. First draw out a table with sucient rows for every combination of values for p and q, and sucient columns for p, q, and every propositional variable and connective in (p q): p t t f f q t f t f (p q)

Truth values are now entered into the table in the following steps. First, the empty columns headed with the propositional variables are lled in: p t t f f q t f t f (p t t f f q) t f t f

Now the table is completed by progressively lling in columns for connectives which are being applied to subpropositions whose entries are already lled in. At this point, there is only one such column, namely the inner-most negation: p t t f f q t f t f (p t t f f f t f t q) t f t f

Next, the conjunctions column can be lled in: p t t f f q t f t f (p t t f f f t f f f t f t q) t f t f

And nally, the outer-most negation: p t t f f q t f t f t f t t (p t t f f f t f f f t f t q) t f t f

The truth table of the proposition consists of the original two columns for the propositional variables p and q, and the nal column.

7
p t t f f q t f t f (p q) t f t t

This is the same truth table as that for p q. Thus, we have proved the equivalence of two propositions.

1.8

Tautologies and Contradictions

Propositions which evaluate to true in every combination of their propositional variables are known as tautologies: they are always true. If, on the other hand, they evaluate to false everywhere, then they are known as contradictions. Of course, the negation of a contradiction is a tautology, and vice versa. A proposition which is neither a tautology nor a contradiction is 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 truth table: p p p t t t f t f f t t t It is a contradiction that a proposition can be both true and false. Again, we symbolise this and construct a truth table: p p p t t f f t f f f t t

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

Two propositions p and q are said to be logically equivalent if the proposition p q is a tautologythis amounts to the same as saying that both have the same truth table. If two propositions are logically equivalent, then one may be substituted for the other in any proposition in which they occur. Thus, since p is logically equivalent to p p, it follows that p q is logically equivalent to (p p) q. Figure 1.2 contains various useful identities. We have tried to give the logical identities meaningful names, so that they can be more easily referred to. Notice that conjunction and disjunction are said to be associative: that is, it doesnt matter where we put the parentheses in an expression such as p q r , since we have 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 )

8 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. p pp p pp pq qp pq qp (p q) r p (q r ) (p q) r p (q r ) (p q) p q (p q) p q (p q) (p r ) p (q r ) p (q r ) (p q) (p r ) p true true p true p p false p p false false p p true p p false p p p q (p q) (p q) (p q) (q p) (p q r ) (p (q r )) (p q) (p q) p (p q) (q p) idempotence of idempotence of commutativity of commutativity of associativity of associativity of De Morgans Law (1) De Morgans Law (2) distributivity of over distributivity of over zero for unit for unit for zero for excluded middle contradiction double negation implication equivalence exportation absurdity 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 Morgans Law (1) (p (q r )) (q r ) by double negation (p (q r )) (q r ) by commutativity of (q r ) (p (q r )) ((q r ) p) ((q r ) (q r ))

by distributivity of over by excluded middle

9 1. 2. 3. 4. 5. 6. 7. ppq pqp p (p q) q (p q) q p p (p q) q (p q) (q r ) (p r ) (p q) (q r ) (p r) addition simplication modus ponens modus tollens disjunctive syllogism hypothetical syllogism 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, and gure 1.3 contains some of these.
Example 8 5 A man who was captured by savages was promised his freedom if he could determine with a single yes or no question the colour of the tribes idol. He knew the idol 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 truth tellers, 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 following table: Colour of Idol White Black Yes No Yes No

Liars Truth-tellers

However, since a liar always gave the wrong answer, he realised that he must ask a question whose correct answers could be tabulated as follows: Colour of Idol White Black No Yes Yes No

Liars Truth-tellers

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

1.9

Arguments

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

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

10

p t t f f

q t f t f

pq t f t t

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

There is only one situation, and in it q is true. We have proved the validity of an argument known as modus ponens. Compare this argument with the logical implication with same name in gure 1.3. Formally, an argument is an assertion that a given set of propositions P1 , P2 , . . . , Pn , called the premisses, entails another proposition Q , called the conclusion. Such an argument is denoted 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 whenever all the premisses P1 , P2 , . . . , Pn are true. This was what we were doing in the example concerning modus ponens: we examined all those situations in which the antecedents were true, and then checked to see if the consequent was true also. An argument which isnt 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 dierent proofs of the fact that, if x 2 3x + 2 < 0, then x > 0.

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


3x > x 2 + 2 2 Hence x>
2 3

since x 2 0.

>0

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

Proof 2 The contrapositive statement is that if x 0, then x 2 3x + 2 0. We assume


therefore that x 0. Then x 1 0 and Hence x 2 3x + 2 = (x 1)(x 2) 0 It follows that if x 0, then x 2 3x + 2 0, and hence that if x 2 3x + 2 < 0, then x > 0.
6 This

x 20

fallacy has been called modus morons by Binmore.

11

Proof 3 Assume x 2 3x + 2 < 0 and x 0. Then


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

In example 9, the proofs are quite informal; they can be formalised, however. Consider the rst proof, we can see that it is of the following form: x 2 3x + 2 < 0 by rearranging 3x > x 2 + 2 since x 2 0, we have that x 2 + 2 0 + 2 3x > x 2 + 2 x 2 + 2 2 by the meaning of

3x > x 2 + 2 (x 2 + 2 > 2 x 2 + 2 = 2) (3x > x 2 + 2 x 2 + 2 > 2) (3x > x 2 + 2 x 2 + 2 = 2)

by distributivity of over by transitivity of >

(3x > 2) (3x > x 2 + 2 x 2 + 2 = 2) (3x > 2) (3x > 2) 3x > 2 x>
2 3 2 3

using the equality in the second disjunct by idempotence of dividing both sides by 3

since

> 0, and > is transitive

x > 0.

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

12

1.10 Problems
1. Let p be it is cold and let q be it is raining. Give a simple verbal sentence which describes 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 symbolise the 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 leave the 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 or both 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 to town. Let r be the proposition I have time. (a) Using propositional connectives, write a proposition which symbolises each of the following: i. ii. iii. iv. i. ii. iii. iv. . If it is not snowing and I have time, then I will go to town. I will go to town only if I have time. It isnt snowing. It is snowing, and I will not go to town. q r p; r q; (q r ) (r q); (r q).

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

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

13

(a) If it rains, Im not going. (b) I will stay only if you go. (c) If you get 4lbs, you can bake the cake. (d) I cant complete the task if I dont 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; (c) q

(b) p 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 contains at least one occurrence of each propositional variable pi , how many rows are needed 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, then it 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 sucient condition 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 Saturdays 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);

14 (c) (p q) ((q r ) (r p));

(d) (p (q r )) ((p q) r ). (a) p q, q p;

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

(b) (p q) r ,

(d) p q r ,

(c) p q r ,

(p r ) (q r ); (p q) r . r q p;

14. Show that the proposition (p q) (p q) is not a tautology. 15. Show that the following argument is valid: p q, q 16. Show that the following argument is valid: p q, q 17. Show that the following argument is a fallacy: 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 nd equivalent expressions which use only and and are as simple as possible. (b) p (q r p); (c) p (q r ). 21. (Stanat) For each of the following expressions, use identities to nd equivalent expressions which use only and and are as simple as possible. (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 form of the right-hand side: (a) (p q p) true; false; p; false. (a) p q r ; (a) p q r ; p. p. p q.

(b) ((p q) p)

(d) ((p p) (p p)) 23.

(c) ((q p) (p q) (q q))

(a) The nand operator (also known to logicians as the Sheer stroke), is dened by the following truth table:

15 p t t f f q t f t f p nand q f t t 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)) iii. ((p nand q) nand (p nand q)) p q; p q.

(b) Find equivalent expressions for the following, using no connectives other than nand: i. p q; ii. p q. (c) The nor operator (also known to logicians as the Pierce arrow), is dened by the following truth table: p t t f f q t f t f p nor q f f f t

For each of the following, nd equivalent expressions which use only the nor operator. 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.

Chapter 2

Predicate Calculus
The language of propositions allows us to model a great variety of properties about specic objects; however, it doesnt allow us to state general properties, such as Every cloud has a silver lining. These general properties are known as universal properties, since they describe properties that must be satised by every individual in some universe of discourse. In our little example, we are considering the set of all clouds, and saying that every one of them has a 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 doesnt know anybody who can sign his bail application.

Sometimes we want to express the fact that at least one thing (without necessarily knowing which thing) has a particular property. This is known as an existential property.
Example 12 The following are all examples of existential properties: 1. Somethings 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 quantier, and is read for all; is the existential quantier, and is read there exists. The quantier symbols are used to build predicates; a predicate is like a proposition with various slots to be lled in by objects of various kinds. In this section we introduce the syntax of predicates, leaving their formal properties until a little later.
Example 13 x : N x > 5 is an existentially quantied predicate.

16

17 The phrase x > 5 is not a proposition, because we cannot tell whether it is true or false without knowing what x is. In fact, x is one of those slots we mentioned above. We can turn it 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 to state our more interesting properties. In the example, we stated that there is an x, which is a natural number, such that x > 5. We call this an existentially quantied predicate, and we call the expression there is an a quantier. In mathematics, the symbol is used to denote 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 greater than ve as y : N y > 5 The dierence is that we have used a dierent name for the local variable. The existentially quantied 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 commonly in 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 the assertion x > 3 is determined using the current value of the variable x; the assertion is assigned either the value 1 (representing true) or 0 (representing false). However, the coding of truth values as integers is sometimes exploited in strange ways in programming languages. For example, in PL/1, A=X>3 is a legitimate assignment statement; execution of this statement causes the numeric variable A to be assigned the value of 1 if X > 3 is true and 0 if X 3. Such a language is not strongly typed. I nd this example surprising because it permits the programmer to interfere with the internal representation of Boolean values, thus violating many software engineering 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 silver lining. 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 hand in 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 )

18

6. Let Person be the set of all people, and let x Knows y mean that x knows y, and x CanVouchFor y mean that x can sign ys 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. do : MadDog do 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 quantication 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 universal quantier : x : N x > 5 Again, this is the same as y : N y > 5 This universally quantied predicate is false, since not every natural number x is greater than 5. Consider the value 3: it is a natural number, and it is less than 5. The universal quantier may be thought of as a generalised conjunction: x : N x > 5 (0 > 5) (1 > 5) (2 > 5) (3 > 5) . . .

19

It must be true for every natural number. In Z, the quantiers share a similar syntax:1 x : s | p q where is the quantier ; 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 is a shorthand for x : s p q

x : s | p q

x : s p q

The existentially quantied predicate x : s | p q is pronounced there exists an x in s satisfying p, such that q. The universally quantied predicate x : s | p q is pronounced for all x in s satisfying p, q holds. Each quantier introduces a bound variable, which is analogous to a local variable in a block-structured programming language. In the quantied predicate x : s | p q, the bound variable has a scope that is exactly the constraint p and predicate q: x : s | p q
scope of x

The quantiers 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 quantier: namely, x. Such yet-to-be-bound variables are called free variables.
Example 17 The following predicates are formed by universal quantication: 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.
1 Do not take this example too literally: there is no quantier called . Rather, there are three logical quantiers: (for all), (there exists), and 1 (there is an unique), and stands here for one of the them.

20

The rst predicate is true, but the second isnt. Example 18 If A is an integer array with 50 entries, A1 , A2 , . . . , A50 , then we can assert that 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 quantied 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 to connectives and reasoning about them is useless for the quantiers, since the sets that bound variables may range over are simply too large.

2.1

Substitution

Suppose that p is a predicate containing the free variable x. The quantied predicate x : S p asserts that p is true for every assignment of a value to x. Each theorem that follows from x : S p is obtained by substituting a term t for x in p. The notion of substitution is 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 dened on terms themselves: u[t /x] is the term that results from substituting t for x in u. A bound variable must sometimes be renamed prior to substitution. For example, the following is a theorem about numbers: x : Z y : Z x y This is true for all numbers, so why not specialise it? Lets take advantage of its being true of the specic number y. This allows us to conclude that y : Z y y Thus, we have concluded that there is a number that is dierent from itself: nonsense! What has gone wrong? The problem is the capture of a free variable: the free variable y comes into the 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 occurrences of x in p.

21

2.2

Validity and Satisability

Any predicate has n arguments; if it has no arguments, then it is a proposition. If p is an n-place predicate, and values c1 , c2 , . . . , cn are assigned to each of the individual variables, the result 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 said to be satisable, and the values c1 , c2 , . . . , cn which make p true are said to satisfy p. Valid, satisable, and unsatisable predicates are the analogues of tautologies, contingencies, 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 satisable 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 unsatisable predicate is y : N y < x y > x For no natural number can we nd a second one which is both larger and smaller than it.

2.3

Properties of Quantiers

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 fundamental identities that answer questions such as these. First, what can be learned from a quantied 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 can choose 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)

22 The negation of the predicate x : N x > 3 is simply x : N x > 3. Can this be simplied at all? Regarding the universally quantied predicate as a generalised conjunction is instructive: x : N x > 3 universal quantication as conjunction (0 > 3 1 > 3 2 > 3 3 > 3 . . .) by De Morgans Law (0 > 3) (1 > 3) (2 > 3) (3 > 3) . . . existential quantication as disjunction x : N (x > 3) Thus, we have a generalised form of De Morgans Laws for the generalisation of the conjunction 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 dont love someone, then you hate them. Now, is it true that there is no one who loves everybody? It is dicult to say whether such a warm-hearted individual really doesnt exist, but we can 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 denition x : Person y : Person x hates y. So, our sentence means the same as everybody hates someone. A depressing reection on human nature. Example 23 For every pair of integers x and y, there exists a z such that x + z = y. This can 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 we need to show that the following predicate is true: x, y : N z : N x + z = y

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 denition x, y : N z : N x + z y Notice how the application of De Morgans Law to the multiple quantier worked. The predicate is now in a form where we can more easily prove that it is true. If we select 1 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 quantied 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 x 2 + x 2 > 0) by propositional calculus x : Z ((x N) x 2 + x 2 > 0) by De Morgan x : Z (x N) x 2 + 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 quantied predicate, the range of the quantication remains unchanged. To prove a predicate of the type x : S p can be quite demanding. One has to give an argument which demonstrates the truth of p whatever the value of x. It is certainly not enough 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 as proving x : S p, and to do this one need nd only a single y for which p is false. We say that such a y provides a counterexample to the statement that x : S p.

24

Example 24 Show that the statement x : Z | x > 0 x2 3 x + 2 0 is false. A single counterexample will suce, and an appropriate value is 2 . We have that ( 2 )2 3 ( 2 ) + 2
3 3 3

1 4

<

If a predicate occurs in a disjunction or conjunction within the scope of a quantier, and none of its variables are bound by the quantier, then it can be removed from the scope of the quantier. Let N stand for a predicate in which the variable x does not occur free. We have the following 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 quantier occurs in both predicates of a disjunction or conjunction. There are laws for the quantiers that are analogous to the associativity laws for disjunction and conjunction, and form the distributivity laws for the quantiers. ( x : S p q) ( x : S p q) (( x : S p) ( x : S q)) (( x : S p) ( x : S q))
(( x : S p) ( x : S q))

Example 25 The universal quantier does not distribute over disjunction: ( x : S p q)

The left-hand side states that, whichever value of x we choose, either p is true or q is true for that value. The right-hand side states that either p is true for every value of x, or q is true for every value of x. An example should suce to convince. It is certainly true that every number is either even or odd. It is not true that either every number is even, or every number is odd. Similarly, existential quantication does not distribute through conjunction. It is certainly true 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 quantication does not distribute through disjunction to yield an equivalent predicate, it does yield a stronger one: ( x : S p) ( x : S q) ( x : S p q) Similarly, although existential quantication does not distribute through conjunction to yield an equivalent predicate, it does yield a weaker one: ( x : S p q) ( x : S p) ( x : S q)

25 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. ( x : S p(x)) p(c) p(c) ( x : S p(x)) ( x : S p) ( x : S p) ( x : S p) ( x : S p) ( x : S p) ( x : S p) ( x : S p N ) ( x : S p) N ( x : S p N ) ( x : S p) N ( x : S p) ( x : S q) ( x : S p q) ( x : S p) ( x : S q) ( x : S p q) ( x : S p N ) ( x : S p) N ( x : S p N ) ( x : S p) N ( x : S p q) ( x : S p) ( x : S q) ( x : S p) ( x : S q) ( x : S p q)

Figure 2.1: Logical relationships between quantiers

2.4

Multiple Quantiers
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 this quantier sequence, since y is chosen after x, the value of y may depend on the value of x. 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 be chosen so that no matter what value x in S is chosen, In this case, since y is bound rst, the value of y must be specied independently of the value of x. For example, there is a number 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 quantiers has been reversed. Of course, the rst of the predicates is true, and the second is false. This is a good illustration that the order is important.

If universal and existential quantiers are mixed, then their order is signicant.

Since it doesnt matter which order we choose for a sequence which contains all universal or all existential quantiers, there is a simplied notation. Instead of writing x : S y : T p we write x : S; y : T p There is a similar simplied notation for the existential quantier.

26

2.5

Problems
(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 entertaining. (v) Only university lecturers and remen are both vastly underpaid and indispensible. (w) Not every actor who is famous is talented. (x) It simply isnt true that every watch will keep good time if and only if it is wound regularly 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.

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

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.

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 rst. 4. Symbolise the following predicates about the numbers. (a) Theres a number between 3 and 5. (b) Given any number theres a smaller one. (c) Theres 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 of the three numbers is zero). (g) If n > 2, the equation x n + y n = z n cannot be solved in integers x, y, z, with x, y, z all non-zero. 5. (Korfhage) Identify the free and bound variables in each of the following. (b) A(x, y) ( x : T B(y)) ( y : U ; z : V C(x, y, z)). (d) x : T ; y : U A(z) B(z). (a) ( x : T A(x)) ( y : U B(x, y)).

(c) ( x : T y : U A(y, x) ( y : V C(y))) B(x, y).

(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 predicates 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.

28

7. (Macbeth & Hodges) Express the following as faithfully as possible, using a predicate that starts with a universal or existential quantier. (a) Every noise appals me. (b) Something wicked this way comes. (c) I have a strange armity. (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 be formalised 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 both false. 10. Find a predicate p in which x occurs, and for which x : N p and x : N p are both true. 11. Let the following be dened: N (x) E (x) O(x) P (x) x x x x is is is is nonnegative even odd 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 isnt even, then its odd. 12. Give a counterexample to the assertion ( x : N p) ( x : N q) x : N p q

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), and 30 columns (indexed from 1 to 30). Using the predicate calculus, make the following assertions: (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 order within rows, and every entry of the ith row is less than or equal to every entry of the (i + 1)th row. 15. There is another quantier 1 x : s p which means there is a unique x in s, such that p holds. (a) Dene this quantier in terms of universal and existential quantication. (b) Universal quantication is a generalisation of conjunction; existential quantication is a generalisation of disjunction. Of what combinator of propositions is the unique quantier a generalisation? 16. Prove the following laws about quantiers: (a) ( x : S p q) ( x : S p) ( x : S q)

(b) ( x : S p q) (( x : S p) ( x : S q)) (d) ( x : S p N ) (e) ( x : S N p) (f) ( x : S p N ) (c) (( x : S p) ( x : S q)) ( x : S p q) N ( x : S p) ( x : S p) N

( x : S p) N

Chapter 3

Set Theory
3.1 Sets

A fundamental concept in all branches of mathematics is that of a set. Most mathematicians believe 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 engineering also. In this chapter, we look at the basic ideas and the language of set theory. This chapter draws on material from Lipschutz, Stanat, and Woodcock. Section 3.17 contains a brief description of Axiomatic Set Theory; this may be skipped at a rst reading without any loss. Intuitively, a set is any well-dened list, collection, or class of objects. The objects in sets, as we shall see from our examples, can be anything: numbers, people, letters, rivers, even sets 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 particular examples of sets. 1. The numbers 1, 3, 7, 4 and 10. 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. 2. The solutions of the equation x 2 3 x 2 = 0.

Notice that the sets in the odd examples are dened by listing their members; and the sets in the even examples are dened by stating properties, that is by specifying a predicate that characterises when an object is a member of the set. Since we enumerate the sets in the odd examples, we call that style of specication set extension; since we use a rule to understand which elements are in the sets in the even examples, we call that style of specication set comprehension.

30

31

3.2

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

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

The elements in our sets will usually be represented by lower case letters a, b, x, y, . . . We can dene a particular set in extension by listing its members, separated by commas and enclosed 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 dene 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 comprehension term. The fact that the elements of this set are numbers may be inferred from the fact that the elements must be even. However, this informality wont 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 our example. We denote the sets by A1 , A2 , . . . , A10 , respectively. 1. A1 = {1, 3, 7, 10}. 2. A2 = { x : N | x 2 3 x 2 = 0 } 4. A4 = { x : Person | x is living on the earth }

3. A3 = {a, e, i, o, u}.

5. A5 = {Robert , Catherine, Jonathan}. 7. A7 = {England, France, Denmark}. 9. A9 = {2, 4, 6, 8, . . .}.

6. A6 = { x : Student | x is absent from class }. 8. A8 = { x : CapitalCity | x is in Europe }.

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 we write xA which is read x belongs to A, or x is in A. If on the other hand, an object x is not a member of a set A, that is, A does not contain x as one of its elements, then we write xA

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 denition of a set, or a basis for deciding when an object is a member of a set. Any mathematical theory must ultimately rest on some primitve or undened notions; the notion of set and the relation is an element of are the primitive concepts of set theory. As a consequence of not having denitions of these concepts, we have no formal test to determine whether or not something is a set, or whether or not a given object is an element of a specied set. Because there is no test, we must rely on a common understanding of the meaning of the terms. We shall return to this point later in this chapter.
Example 30 Almost anything which would be called a set in ordinary conversation is an acceptable set in the mathematical sense. 1. The set of nonnegative integers less than 4. This is a nite 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 dicult to list the members of this set because of the constant ux in the librarys collection; the diculties are practical rather than theoretical. 3. The set consisting of people who spoke to Bertrand Russell on the 7 June 1906. This set is nite and probably contains at least one element. It has the alarming characteristic that there is probably no way of determining its membership; this does not detract from its acceptability as a set. 4. The set of live dinosaurs in the Pitt-Rivers Museum. Assuming that there have been no sinister experiments in the Pitt-Rivers Museum, this set has the property that it has no members: it is called the null or empty set. 5. The set of integers greater than 3. Even though this set is innite, there is no diculty in in determining whether or not a specied 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 nite; a correctly operating C++ compiler can determine 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 sucient time on a computer with unbounded storage. This set is not nite, because no matter how large a program we write, it is possible to write a longer program by inserting another statement (the statement need not perform any useful task). Although there is a maximum size of program that can be run on any particular computer, there is nothing inherent in the C++ language that limits the size of a program. Computability theory has established that there is no algorithm that can exist which determines whether an 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 innite set, as we can easily demonstrate by considering propositions of the form 3 + 1 = 4. Furthermore, there are propositions that are conjectured to be true, but which have never been proved or disproved. 9. The set with two members, one of which is the set of even integers, and other the set of odd integers. Thus, sets can have other sets as members.

33

Sometimes, we will want to construct sets with more complicated terms than the comprehension notation above allows. In this case, we add a fat dot followed by an extra expression to the comprehension term. Thus, for example, the set of squares of even numbers might be written { x : N | x is even x 2 } For further examples of this form of comprehension term, see Chapter 4.

3.3

Finite and Innite Sets

Sets can be nite or innite. Intuitively, a set is nite if it consists of a specic number of dierent elements, that is, if in counting the dierent members of the set the counting process can come to an end. Otherwise the set is innite. Later, we can dene this more precisely.
Example 31 1. Let M be the set of the days of the week. Then M is nite. 2. Let N = {2, 4, 6, 8, . . .}. Then N is innite. 3. Let P = { x : River | x is on Earth }. Although it may be dicult to count the number of rivers in the world, P is still a nite set. 4. Suppose that statement labels in a (rather old-fashioned) programming language must be either a single alphabetic symbol or a single decimal digit. The rst set is {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 either an 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 is painted in one of four dierent colours. The puzzle is to stack the cubes in such a way that each vertical side of the stack contains squares of all four colours. The order of the cubes in the stack is clearly unimportant, and we do not wish to distinguish between arrangements which are identical except for rotations. We can count the number of signicantly dierent arrangements as follows: (a) The rst cube can be positioned in any of three dierent ways, because there are three 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 gives 24 dierent ways to position each of the last three cubes in the stack. Thus, there are 3 24 24 24 = 41 472 dierent arrangements. (You might care to write a program that solves the four cubes puzzle.)

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 element which belongs to A also belongs to B and if every element which belongs to B also belongs to 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 elements 3, 1, 4, 2 of B belongs to A. Note therefore that a set does not change if its elements are 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 that a set does not change if its elements are repeated. Also, the set {5, 6, 7} equals C and D. 3. Let E = { x : N | x 2 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 quantication 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 denitions: Zeroes = { x : N | x 2 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 quantication. Actually, both sets contain only natural numbers, although this is perhaps not immediately 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 no elements. 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 of my knowledge, A is the empty set. 2. Let B = { x : N | x 2 = 4 x is odd }. Then B is the empty set.

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. More specically, A is a subset of B if x in A implies x in B. We denote this relationship by writing AB 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 5 belonging 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 6 belonging 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 F is 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 denition of subset more formally:1 AB ( 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 and only 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 member of 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 ABBA by denition
1 The

universal quantication may also be written as

x : X | x A x B, or even in the rather succinct form as x : A x B.

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 xB

Thus, A and B have exactly the same elements. Theorem 2 The subset relationship is reexive, in that for any set A, we have that A A. Proof AA by denition x : X x A x A x : X true true Theorem 3 Since the empty set has no members, it is trivially a subset of every other set. Proof A by denition x : X x x A x : X false x A 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 set unique? The fact that we have a type system in our language means that the empty set of cars is dierent from the empty set of elephants, if cars and elephants are dierent types. However, could there be two dierent 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 that the two dierent empty sets are and . Now, from our previous theorem, we have that the but x must be false by propositional calculus since P P is a tautology

by predicate calculus

37

empty set is a subset of every other set; in particular we have that . But we must also have the same property for . Thus we have . Thus, we can conclude that = . 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 implication 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 follows that x : X x A x C, and so A C. If A is a subset of B, then we can also write BA 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, rst, B is a subset of A and, secondly, if B is not equal to A. More briey, B is a proper subset of A if BABA We will sometimes write B 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.

38

3.8

Sets of Sets

It sometimes will happen that the objects of a set are sets themselves; for example, the set of 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 which arent. In fact, the type system will make sure that all the members of a set are the same kind of 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 power set of S by P S.
Example 38 1. Let M = {a, b}, then P M = {{a, b}, {a}, {b}, }. 3. Let A = , then P A = {}. 2. Let T = {4, 7, 8}, then P T = {T , {4, 7}, {4, 8}, {7, 8}, {4}, {7}, {8}, }. 4. Let A = {1}, then P A = {, {1}}.

6. If A is any (nite or innite) set of natural numbers, then A P N. If A is nite, then P A is also nite; otherwise, P A is innite.

5. Let A = {1, 2}, then P A = {, {1}, {2}, {1, 2}}.

If a set is nite, 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 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 element of 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 in both 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 are disjoint, 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.

39

3.11 Venns Diagrams


A simple but instructive way of illustrating the relationships between sets is in the use of Venns diagrams. Here we represent a set by a simple plane area, usually bounded by a circle or an ellipse.
Example 40 1. Suppose that A B. Then A and B can be described by the diagram:

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

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

a b c f d

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. We denote the union of A with B by AB 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 point marked:

a b c f d

2. Let S = {a, b, c, d} and T = {f , b, d, g}, then S 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 Q consists of all the real numbers except zero.

The union of A with B may be dened concisely by A B = {x : X | x A x B } Now, it follows directly from the denition of the union of two sets that union is a commutative operator, and that both A and B are subsets of A 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 AB
Example 42 1. In the following Venn diagram, the intersection of the two sets A and B contains only the points c and d:

41

a b c f d

2. Let S = {a, b, c, d} and T = {f , b, d, g}. Then S T = {b, d} 3. Let V = {2, 4, 6, . . .}, and let W = {3, 6, 9, . . .}, then V W = {6, 12, 18, . . .}

Now, it follows directly from the denition of the intersection of two sets that A B and B A are the same. Furthermore, each of the sets A and B contain s A B as a subset. If A and B have no elements in common, then they are disjoint. This may be formalised by saying that their intersection is empty. The intersection of A and B may be dened formally: A B = {x : X | x A x B }

3.14 Dierence
The dierence between two sets A and B is the set of elements which belong to A but not to B; we denote it by A\B

which is read A minus B.


Example 43 1. The dierence between the two sets A and B contains only the points a and b:

a b c f d

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 \ Q consists of the irrational numbers.

The dierence of A and B may be dened 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; that is, for arbitrary sets A, B, and C, 1. A B = B A 2. A B = B A 3. (A B) C = A (B C) 4. (A B) C = A (B C) Proof The proofs of these assertions rely on the commutativity and associativity of disjunction and conjunction. We give two proofs (1) Let x be an arbitrary element of the set X . Then x AB xAxB denition of commutativity of denition of

xBxA x BA

Thus, since x is arbitrary, we have proved that x : X x A B x B A,

and hence that A B = B A. (3) Let x be an arbitrary element. Then x A (B C) denition of

43

x Ax BC x A (x B x C) (x A x B) x C x AB x C x (A B) C denition of denition of associativity of denition of

Since x was arbitrary, it follows that and hence that A (B C) = (A B) C. x : X x A (B C) x (A B) C,

Theorem 7 The set operations of union and intersection distribute over each other; that is, for arbitrary sets A, B, and C, 2. A (B C) = (A B) (A C) 1. A (B C) = (A B) (A C)

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

3.16 Generalised Operations


The binary operations of union and intersection may be regarded as special cases of more general operations which form unions and intersections of any number of sets. These more general operations are dened 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 the generalised intersection of A: it contains those objects which are members of all member sof A. 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 rst reading without any loss. It contains a brief account of 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 set is any collection of objects, mathematical or otherwise. Actually, the development of set theory 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 circumscribed in 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 consider the famous (or infamous) paradoxes.

44

(a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) (m) (n) (o) (p)

AA=A AA=A A=A A= A\B A AB C D AC BD AB C D AC BD AAB AB A AB AB =B AB AB =B A\=A A (B \ A) = A (B \ A) = A B A \ (B C) = (A \ B) (A \ C) A \ (B C) = (A \ B) (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: undened terms; undened relations; axioms relating the undened terms and undened relations. Then, one develops theorems based upon the axioms and denitions. For example, in Plane Euclidean Geometry, the undened terms are points and lines; the undened relation is point on a line; and two of the axioms are 1. Two dierent points are on one and only one line. 2. Two dierent lines cannot contain more than one point in common.

3.17.2 Cantors and Russells Paradoxes


Suppose that we allow ourselves the luxury of using sets just as we please. Consider the set of 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 any set X , the set of all subsets of X is the power set of X , denoted P X . Thus, we have that PU U

45

because each subset of U is a member of U. On the other hand, it is a general fact about sets that the power set of X is always bigger than X itself. This is a contradiction, and forms Cantors paradox. Some sets are members of themselves (for instance, the set M of all mathematical concepts: this is itself a mathematical concept, and hence is a member of M itself) and some sets sre mot members of themselves (for instance, the set of natural numbers less than or equal to 10 is not itself a natural number less than or equal to 10). We dene 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 a member of itself, and hence lies in the set of all such sets, that is, in R: thus R R. In either case, we reach a contradiction: Russells contradiction.2

3.17.3 The Zermelo-Fraenkel Axioms for Set Theory


These paradoxes arise because we have allowed ourselves too much freedom in dening sets. In the following axiom system for set theory, we shall give various conditions under which we can dene a set: unless the axioms permit it, a set is not properly dened. In particular, we shall not be able to talk about the set of all sets, or the set of all sets which do not belong to themselves. In this way, both Cantors and Russells paradoxes are avoided. There is no guarantee that other paradoxes will not arise; however, none has been found to date. The axioms dene a certain universe of sets, which consists of sets and nothing else. The elements of a set are always other specied sets in the universe. So, if we wish to describe any mathematical concept in terms of the universe, then that concept must be represented by a genuine set. In the axiomatic development of set theory, we have that element and set are the undened terms; membership is the undened 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 belongs to 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 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 of sets.
2A

There is a set with no members, that is,

nice interpretation of Russells paradox is the man who asserts

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

46

Axiom of Union Given any set A, then there is a set the members of the members of A. More formally, xA ( Y : A x Y ).

A which has as its members precisely

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 A B. We can unravel the denition 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 set comprehension term, and there is no axiom yet that allows us to do that. The next axiom permits us to specify a subset of a given set, and it is the most important axiom, in that it provides the main method of constructing new sets from old ones. Axiom of Specication set 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 diculty is that we have failed to supply the set from which to draw the elements in the comprehension term. We have to write something of 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 the implication R R R A R R. These two implications are contradictory, but we have not found a paradox, since we havent considered that our assumption that R A might be false. In the case that R A, we have that R R R A R R, which is entirely consistent with the rst deduction. The axioms now allow us to write down many nite sets, but as yet no innite ones. Let P (x) be any predicate and let A be any set. Then there exists a

47

Axiom of Innity There is an innite set. The next two axioms allow us to write down many innite sets. Axiom of Power Sets of A; that is X PA X A. Given any set A there is a set P A whose members are all the subsets

One way to construct new innite sets is to write down a set whose elements are labelled by an existing set. Axiom of Replacement Suppose that A is any set, and that f is any rule that species a denite 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 the Axiom 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 controversial. The rst 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 : A 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 nite 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, however big 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 dene more and more sets. The nal axiom restricts the notion. Axiom of Foundation Given any nonempty set A, there is an element X A such that X A = . This axiom rules out the possibility of having an innite descending sequence of elements such as . . . Xn+1 Xn . . . X2 X1 , for then the set { i : N Xi } would contradict the axiom. It also rules out the possibility of a set A being a member of itself: consider A = {A}. There are other axioms which are not listed here.

48

3.18 Problems
1. Let M = {r , s, t }. State whether each of the following is correct or incorrect: 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 | x 2 = 4 } (a) (c) r M {r } M (b) (d)

r M {r }

(b) B = { x : N | x 2 = 5 }

(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 }

(c) C = { x : N | x > 0 x < 0 }

(h) { x : Z | x = 2 x = 5 }.

(g) { x : Z | x DecimalDigit }

4. Dene 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. (g) The countries in the United Nations. (h) The set of Prime Ministers Wilson, Callaghan, Thatcher , and Major . 5. Which sets are nite? (a) (c) (e) The months of the year. The people living on the earth. {1, 2, 3, . . .}. (b) (d) {1, 2, 3, . . . , 99, 100}. { x : N | x is even }. (f) The even numbers {2, 4, 6, 8, . . .}.

6. Which of these sets are equal? (a) { x : Letter | x is in the word follow }. (c) { x : Letter | x is in the word ow }.

(b) The letters which appear in the word wolf . (d) The letters which appear in the word ower . (e) The letters f , l, o, and w. (g) { x : Z | ( y : Z x = 2 y) } (f) { x : Z | x is even and x 2 is odd }

(h) {1, 2, 3}

49 (i) {0, 2, 2, 3, 3, 4, 4, . . .}

(k) {3, 3, 2, 1, 2}

(j) { x : Z 2 x }

(l) { x : Z | x 3 6 x 2 7 x 6 = 0 }

7. Which of these sets is the empty set? (a) A = { x : Letter | x precedes a in the alphabet }. (c) C = { x : N | x x }.

(b) B = { x : N | x 2 = 9 and 2 x = 4 }. (d) D = { x : N | x + 8 = 8 }.

(e) { n : Z | n > 2 ( x, y, z : N | x 0 y 0 z 0 x n + y n = z n ) }. {1, 2, 3} {{1, {2, 3}}} {, {}} {{, 2}, {2}} (b) (d) (f) {1, {2, 3}} {} {{1, 2}, {2, 1, 1}, {2, 1, 1, 2}}

(a) (c) 8. List all the subsets of the following sets (e) (g)

9. Let the following sets of gures in the Euclidean plane be dened: Q = { x : Euclidean | x H = { x : Euclidean | x R = { x : Euclidean | x S = { x : Euclidean | x is a quadrilateral } is a rhombus } is a rectangle } 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} is not 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 example in 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}. (a) Y X (d) V X of the following statements is true or false: (g) Z V (j) W Y Determine whether each (b) Z Z (c) W V (e) W Z (f) Y Z (h) X = W (i) V 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}, and F = {s}. Let X be an unknown set. Determine which sets A, B, C, D, E , or F can equal X (a) X A and X B. (b) X B and X C. in each of the following cases: (c) X A and X C. (d) X B and X C.

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 (a) a C, (b) suppose that d A, e B, f C. Which statements must be true? (d) e A, (e) 18. In the Venn diagrams below, shade the set A B:

d B, c A,

(c) (f)

B B A A

B A

19. Let A = {1, 2, 3, 4}, B = {2, 4, 6, 8}, and C = {3, 4, 5, 6}. Find 20. Prove that A and B are subsets of A B. 21. Prove that set union is idempotent, that is, that A = A A. 22. Prove that A = A . 23. Prove that if A B = , then both A and B are empty. 24. In the Venn diagrams below, shade the set A B:

(a) (d)

AB BB

(b) (e)

AC (A B) C

(c) (f)

B A

B B A A

B A

25. Let A = {1, 2, 3, 4}, B = {2, 4, 6, 8}, and C = {3, 4, 5, 6}. Find 26. Prove that A B is a subset of A and of B.

(a) (d)

AB BB

(b) (e)

AC (A B) C

(c) (f)

B A

27. Prove that set intersection is idempotent, that is, that A = A A. 28. Prove that A = . 29. In the Venn diagrams below, shade the set A \ B:

B B A A

B A

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

A\B B\A A \ (B \ C)

(b) (e)

C \A B\B

(c) (f)

B\ (A

51

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

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

33. Prove that if A \ B = , then A is a subset of B. 34. Prove that A \ B is a subset of A B. 36. Prove that A B implies A (B \ A) = B. 37. (a) Prove that set dierence is not commutative. (b) Is it possible for that A \ B = B \ A? Under what conditions could this occur? (c) Is set dierence associative? Prove your assertion. 38. Let A, B, and C be arbitrary sets. Express A B 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 B. (That is, A B is the largest set contained in both A and B.) (b) Show that if C A and C B then C A B. (That is, A B is the smallest set which contains both A and B.) 40. Suppose that A and that A B = A C. Show that it does not necessarily follow that B = C. Suppose in addition that A B = A C; can you now conclude that B = C? 41. Prove the absorption laws: (a) (b) A (A B) = A A (A B) = A (a) (c) {} {{a}, {b}, {a, b}} 35. Prove that A B implies A B = A.

42. In each of the following, nd the generalised union and generalised intersection. 43. Specify the power sets of the following. (a) (b) (c) {a, b, c} {{a, b}, {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 the other. Assume that all input sets are nite subsets of N. 46. (Stanat) Programming Problems (a) Write a program to generate the power set of {0, 1, 2, . . . , n} for any natural number n given as input. (b) i. Write a program which accepts specications of two nite subsets of the natural numbers, A and B, and prints a nonredundant list of the elements of A B and A B. ii. Write a program to determine for a given set A and an arbitrary n N whether or not n A.

Chapter 4

Relations
We represent objects in the world by using sets; relations may be used to represent the structure of these objects. Some relations describe comparisons between similar objects: one box is heavier than another; one man is richer than another; one event occurred prior to another. These relations speak of the structure within certain sets: they relate boxes to one another; they relate men; they relate events. Other relations speak of the structures that are built between sets: Jim lives in Oxford; Kevin works for IBM; Foundations is a Diploma 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 discussion with 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-ordinate geometry will perhaps be familiar to readers. The value a represents the x-coordinate, and the vale b represents the y-coordinate. This is depicted in the following graph:
y b (a,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 captured in 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 rst components are equal and also that their second components are equal.

52

53

Notice that this property means that the parentheses in the ordered pair notation are not associative. 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 rst element is 1 and whose second element is the pair (2, 3). Similarly, ((1, 2), 3) is a pair whose rst element is the pair (1, 2) and whose second element is 3.

4.2

Cartesian Products
A B = { a : A; b : B (a, b) }.

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

This set comprehension term contains all the ordered pairs (a, b), such that a is drawn from A and b is drawn from B. The notation is used because the total number of elements in A 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 B as a set of points in the plane.
y

Ax B B b (a, b)

(0,0)

a A

In this picture the set A is an interval of values on the x-axis, and B is an interval of values on the y-axis. The set A 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 N N. We might choose the convention that in the Cuboid triple (w, h, d) that the rst element stands 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 (B C) (A B) C. By denition, we have A (B C) = { a : A; z : B C (a, z) } (A B) C = { x : A B; c : C (x, c) }

54

Expanding these further we obtain A (B C) = { a : A; b : B; c : C (a, (b, c)) }

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

Since the ordered pair notation is not associative, these two sets contain objects of dierent kinds, and they cannot be equal.
Example 44 Let A = {1, 2}, B = {m, n}, C = {0}, and D = . Then 1. A B = {(1, m), (1, n), (2, m), (2, n)}, 2. A C = {(1, 0), (2, 0)}, and 3. A D = .

Example 45 Let A = { m : N | 1 m 3 } and B = { n : N | 1 n 2 }. Then 2. B A = { m, n : N | 1 m 3 1 n 2 (n, m) }. These two sets may be depicted as graphs.
y 3 2 1 3 2 1 y

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

A x B

B x A

Theorem 8 The Cartesian product operator distributes over set union: A (B C) = (A B) (A C).

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


(x, y) A (B C) by Cartesian product membership x Ay BC by property of set union x A (y B y C) since distributes over

55

(x A y B) (x A y C) by Cartesian product membership (x, y) A B (x, y) A C by property of set union (x, y) (A B) (A C) Thus, the two sets must be equal.

4.3

Relations

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

AxB B R

(0,0) A

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. Lets dene a relation that holds between two numbers just in case the rst number divides the second exactly. divides == { a, b : Z | ( m : Z b = m a) } This is a good example of a specication of a relation. The relation divides has been given implicitly in terms of the multiplication operator. 3. When an assembler translates an assembly language program, it constructs a symbol table which contains the symbolic names which occur as labels in the program, and the number of the program statement in which each name was dened. Thus, if Symbol is the set of symbolic names, then the symbol table embodies a relation between Symbol and statement number. 4. (Stanat & McAllister) The relation over the natural numbers can be dened inductively as follows:

56

(a) (Basis) 0 1 (b) (Induction) If x (i) (ii) y, then x y +1 x +1 y +1 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 standard method for describing the relationships in the data. The theory of relational databases is concerned with ways of representing data relations, and with the operations needed to query and update the data base. Module 1 2 3 4 5 6 7 8 Core Core Core Core Core Core Optional Optional Lecturer Woodcock Woodcock Harvey-Jones Sufrin Davies Woodcock Jackson Jirotka Title Foundations Specication & Design Software Development Management Functional Programming Concurrency Residential Week Critical Systems Requirements Analysis

(c) (Extremal) For all x, y N, x

In Z, this database could be modelled as follows: CO == {C, O} Diploma == N CO Lecturer Title. (5, C, Davies, Concurrency) Diploma.

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

4.4

Inverse Relations
R = { a : A; b : B | a R b (b, a) }.

Every relation from A to B has an inverse relation R from B to A which is dened by In other words, the inverse relation R consists of those ordered pairs which, when reversed, belong to R. R is sometimes written R1 .
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 R = {(a, 1), (b, 1), (a, 3)}. 2. Let W = {a, b, c}. Then {(a, b), (a, c), (c, c), (c, b)} W = {(b, a), (c, a), (c, c), (b, c)}.

is a relation in W . The inverse relation of W is

57

4.5

Identity Relation

The identity relation relates every element of a set to itself. We dene the identity on a set X as 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 reexive if every element is related to itself; if no element is related to itself, then it is irreexive. 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 Lets dene 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)}.

1 2 3 2

R1 R2 R3

R2 is asymmetric, R1 and R3 are not. R1 and R2 are antisymmetric; R3 is not. R2 and R3 are transitive; R1 is not.

The way that we have dened a symmetric relation may be re-stated in terms of the inverse relation. Consider the following a : A; b : B a R b b Ra

58 a R b

a : A; b : B a R b R = R

Thus, a relation R is symmetric if and only if R = R . A relation is antisymmetric if the only symmetric pairs are of the form (a, a). We can use this insight to re-cast the denition of antisymmetry in terms of the identity relation. Suppose that R is a relation on A, then it is antisymmetric if and only if R R id A.
Example 49 1. The relation of equality is reexive on any set. 2. Consider the set set Z of integers. The relation is reexive and not irreexive; the relation < is irreexive and not reexive. 3. In Euclidean geometry, the triangle A is similar to the triangle B providing that they have the same angles. Is similar to is a reexive relation. 4. The relation on sets is reexive. 5. Consider the set of strings of characters. The relation is the same length as is reexive and not irreexive; the relation is longer than is irreexive and not reexive. Let pre-su be the relation that holds between two strings s and t provided that a proper prex of s is a proper sux 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 reexive nor irreexive, 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 absolute values 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 antisymmetric but not symmetric. The relation that holds between two strings when they have a common nonempty prex 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. The relation x divides y, which holds providing x divides y exactly, is also transitive. 3. The relation x loves y is not transitive.

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 prex of, is a proper prex 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 section 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 you want to buy a new car, and that you are convinced that a diesel car is both more economical and environmentally-friendly. In thinking about this you are dividing the set of available new cars into two sets: two equivalence classes. You have invented an equivalence relation with respect to which all diesel cars are equivalent, regardless of make or model. We have met this idea before in the chapters on logic. Two propositions were regarded as equivalent if they had the same truth value, regardless of their structure. In mathematics, an equivalence relation R on a set A is dened to be a relation between the set A and itself which satises the following properties for each a, b, and c in A: 1. a R a (reexivity); 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 dened between two humans whenever they have the same mother. It is an equivalence relation. 2. Lets write x k y to mean that x and y have exactly the same remainder when divided by k. That is, we can nd natural numbers m and n, and a number r between 0 and k 1, such that x = m k + r y = n k + r. We can dene this formally as a family of relations, (one for each natural number k):
k

== { 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. Dene A1 == { a : A | a R a1 }; we call A1 an equivalence class of R.


Theorem 9 Two distinct equivalence classes are disjoint (i.e. have no points in common).

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. We have

A A1 a1 b a2 A2

b R a1 b R a2 a1 R a2

a1 R b b R a2

[by symmetry (R is an equivalence relation)]

[since b A1 and b 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 denition] [from above] [by transitivity] [by denition.]

c R a2

c R a1 a1 R a2 c A2

A stronger way of stating this theorem is to say that when a relation R induces equivalence classes on a set A, those classes partition the set A. That is to say that they are disjoint, and their union is A.
Example 53 The relation 1. 2.
k,

So, we have that A1 A2. By a similar reasoning, we also have that A2 A1, and thus A1 = A2.

dened above, induces k equivalence classes in N.

2 gives two equivalence classes: they are best known as the sets of odd and even numbers. 3

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 dene a relation R between A and B, the set A is called the source of the relation, and the set B the target.

61

The domain of R is the set comprising the rst elements of each of the pairs in R, and the range 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 satises the following properties, for each a, b and c in A: 1. a 2. a 3. a bb bb bb a (totality); a a = b (antisymmetry); and ca c (transitivity).

If the totality condition is replaced by reexivity (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 two relations to form the relation which is denoted by R o S . The composition contains pairs that 9 have been obtained from R and S in the following way. Suppose that a (R o S ) c; it must be 9 the case that there exists a value b such that a R b and b S c. Formally, R o S = { a : A; b : B; c : C | a R b b S c (a, c) }. 9 This is most clearly seen when the graphs of two relations are considered.

62

Person

Car

Fuel

Citroen Michael Peugeot Jim NoddyCar Jamie MGB Dave Skoda Gordon Trabant

Diesel

FourStar Unleaded N20 2Stroke

owns

uses

4.11 Relational Restriction


It is sometimes useful to consider the result of restricting a relation to a particular subset of its domain, or range. We write S R to denote the relation R restricted only to those members of S . Similarly, R S is R, with only those arrows present which end at members of S . S R R == { a : A; b : B | a bRaS a b}

S == { a : A; b : B | a

bRbS 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/range subtraction) limits the relation to those objects which are not in the specied set. S R R == { a : A; b : B | a S == { a : A; b : B | a bRaS a b}

bRbS a

b}

Example 56 Using the denitions 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 excess of 30 000. 3. (D R) S is the relationship between names and salaries for those directors who earn less than 30 000.

63

In fact, the choice of where to put the parentheses in the last example is quite arbitrary, as demonstrated 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 T ) S (T R) = (S T ) (S R) (S R) = R with similar laws for and R R .

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 also transitive. Of course, if R is itself transitive, then R+ = R. To dene R+ , we introduce another notion: that of an iterated relation. We have a relation 2 R , such that a R2 b exactly when there is a c such that a R c c R b. Likewise, a R3 b whenever we can nd c and d such that a R c c R d d R b. In general, two objects will be related by Rk if there is a chain of k instances of R relating the two objects. Now we can give a formal denition of R+ : R+ = { n : N \ {0} Rn }

A similar relation is the reexive transitive closurewhich has all the properties of R+ , and is also reexive. It can be dened in the same way, making use of the convention that R0 is the 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 a natural interpretationit 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 ordering on N. 2. Explain why 3. Let is an equivalence relation on the set of all propositions. on A by

be a total ordering on a set A. Dene the associated strict ordering a b a b a b.

Prove that

is a transitive relation. Is it total? Is it antisymmetric?

64

4. Prove the following theorems. A (B C) = (A B) (A C)

(A B) C = (A C) (B C)

(A B) C = (A C) (B C)

5. How many binary relations are there on the set {1, 2, 3}? If A has n elements, how many binary 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 both negative. (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 the relation possesses the property.
Reexive Irreexive Symmetric Antisymmetric Transitive ZZ = < divides

8. Find a nonempty set and a relation on it which is neither reexive nor irreexive. Choose the 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 antisymmetric. Choose the set to be as small as possible. What if the set is permitted to be empty? 10. Fill in the following table according to whether the relation possesses the property; in each row, you may assume that the relations R and S both possess the property individually. For each relation that does not possess the property, give a counterexample.
Union RS Intersection RS

Reexive Irreexive Symmetric Antisymmetric Transitive

11. Sketch graphs of the following relations on the set of real numbers, and determine what kinds of properties the relations have. (a) { x, y : Real | x = y }.

(b) { x, y : Real | x 2 1 = 0 y > 0 }.

(c) { x, y : Real | abs(x) 1 abs(y) 1 }.

65

12. Write a program which takes as input a relation described as a set of ordered pairs and determines whether it is reexive, irreexive, symmetric, antisymmetric, or transitive. 13. (Stanat & McAllister) Prove or disprove the following assertions. (a) If R and S are reexive, then R o S is reexive. 9 (b) If R and S are irreexive, then R o S is irreexive. 9 (c) If R and S are symmetric, then R o S is symmetric. 9 (d) If R and S are antisymmetric, then R o S is antisymmetric. 9 (e) If R and S are transitive, then R o S is transitive. 9 14. Prove that dom distributes through ; that is dom(S T ) = dom S dom T Does the same hold for ran? What about ?. 15. Prove that dom(S R) = S (dom R). 16. Can (R+ )+ be simplied?

Chapter 5

Functions
The graph of a binary relation in its most general form may contain both diverging and converging arrows. For example, in the graph of the less-than-or-equal-to relation on the integers, 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 -1 0 1 2 3 . .

. . -3 -2 -1 0 1 2 3 . .

If we forbid the presence of diverging arrows, then we get a special class of relations: functions. 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 square of a number is unique. 2. Suppose that g relates each country in the world to its capital city; then, g is a function since no country has more than one capital. 3. Suppose that h is dened 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

67

Suppose that f is a function which maps elements of the set A to elements of the set B, then we write f :AB

when we dene f . The set A B is the set of all functions from A to B. Now, suppose that a is in the domain of f . The value a must be related by f to some value in B, but, since f is a function, a cannot be related to more than one value in B. We write f (a) to denote the unique 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 bf b1 f a b2 f b1 = b2 As f is a function, we know that it has the no-diverging-arrows property: a : A; b1 , b2 : B | a
1. f : N N

Example 59 The following are examples of functions

2. g : {1, 2, 3} {A, B, C} g(1) = A g(2) = B g(3) = C

f x=1 f x = x div 2

if x is odd if x is even

3. h : Char

5. (Grimaldi) In storing a matrix in a one-dimensional array, many computer languages use the major row implementation. Here, if A is an n n matrix a1,1 a1,n . . . . . . an,1 an,n

4. Suppose that A = , then f : A B is a function. Every maplet in f must have its rst element in A and its second element in B; since A is empty, there can be no such maplets, and therefore f is itself empty; since there are no maplets in f , there can be no diverging arrows in f , and therefore f is a function. Similarly, if D = , then g : C D is a function.

h = {a

Char

b, b

c, c

d}

the rst row of A is stored in locations 1, 2, 3, . . . , n of the array (with a1,1 in the rst position). The entry a2,1 is then stored in position n + 1, while entry a3,4 occupies position 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 dened that maps (i, j) to an array location. A suitable denition is that f (i, j) = (i 1) n + j

The following is not a function: the relation between a positive real number and its real square root (since there are two such relatives for every positive real number).

68

5.1

Total and Partial Functions

Consider the predecessor relation pred on the natural numbers: m has the predecessor n if and only if n = m 1. Is pred a function? The answer must be yes, since it clearly contains no diverging arrows: m n1 m n2

n 1 = n2

n1 = m 1 n2 = m 1

However, to what result does pred relate the value 0? There is no natural number that is the predecessor of 0 (1 is not a natural number), and we say that the function is not dened for 0. In this sense, pred is not a total function on the natural numbers: it is not dened for all 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 whole of A. Thus, f is a total function from A to B, written f :AB providing that f A B dom f = A
Example 60 1. The reciprocal relation that takes a real number x to the value 1/x is a strictly partial function, undened for the value 0. 2. The positive square root relation that takes a real number x to the positive real number y, such that y 2 = x, is a strictly partial function, undened for negative inputs. 3. The identity function ident : N N

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 program is the argument of the function, and the output of the program is its result. If the program might not always terminate, or might terminate abnormally (with a runtime error, for example) then the function is strictly partial, undened for that input. Using the output of one program as the input to another corresponds to (although is not identical to) composition.

5.2

Special Functions

Just as we placed a constraint on relations to yield functions, and a further constraint on functions to yield strictly partial functions, so we can add other constraints to yield specialised functions which turn out to be of great interest in modelling (in particular) computing systems.

69
partial function nite function total function partial surjection total surjection partial injection total injection (total) bijection AB { f : A B | a : A; b1 , b2 : B | a b1 f a b2 f b1 = b2 } { f : A B | dom f F A } { f : A B | dom f = A } { f : A B | ran f = B } ABA B { f : A B | a1 , a2 : dom f f a1 = f a2 a1 = a2 } ABA B A BA B

AB AB A B A B A B A B A B

Table 5.1: Function arrows and their denitions

Suppose that the range of a function is the whole of its target, then the function is called surjective (a few years ago, it would have been known as an onto function). If f is a surjective function from A to B, it is denoted by A B, and has the property that Suppose that a function contains no converging arrows, then it is called injective ( a few years ago it would have been known as a one-to-one function). If f is an injective function B, and has the property that from A to B, it is denoted by A f AB a1 , a2 : A | f a1 = f a2 a1 = a2 f A B ran f = B

The set of total surjections from A to B is denoted by A B, and the set of total injections B. from A to B by A A total, injective, surjective function is known as a bijection, and the set of all bijective functions from A to B is denoted by A B. Suppose that f : A A is a bijection; we can think of f as giving us a permutation of A. Suppose that f is a function in A B. Every element in dom f is the origin of exactly one arrow. 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 one arrow terminates at each element of B. If f is bijective, then exactly one arrow terminates at each element of B. Table 5.1 summarises the dierent arrows used here, and the denitions of each.
Example 61 1. Dene the squaring function as 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). cube : Z Z sqr : Z Z

2. Dene the cubing function as n : Z cube n = n 3

Now, cube is a total, injective function; it is not surjective.

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 are countries; 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; if there is more than one element in the domain, then there must be at least one pair of 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 successor of some number; it is injective, since no number is the successor of more than one number. Thus, succ is a bijection on the integers. 7. Consider f : {1, 2} {0} This declaration has dened 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. g = {1 2, 2 3}

8. Dene

The relation g is clearly a strictly partial function on the naturals (and on the integers). It is also injective, but not surjective. 10. 11. Dene 9. N

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 in les. Of the many methods that there are of assigning keys to records, one uses a hash function to compute the key from the record. For example, our university departments car park attendant might keep a record of cars registered to use the carpark. 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 the attendant could allow 400 owners to register their cars. A possible data structure might have 500 entries, with the key being formed from the numerical part of the index, modulo 500. If f is the hash function, then we would have f f f f K979XFC = 479 VSO940S = 440 1BJO = 1 M440MJF = 440

f :NN

71

This hash function is, I believe, total on the set of British car index marks. It is surjective with respect to the set of numbers in the range 0 to 499. It is not an injection. The fact that the hash function is not an injection means that two keys have the same hash-value (e.g., VSO940S and M440MJF above). When this happens, a collision is said to occur, and some provision must be made to store, and subsequently to search for, collided records.

5.3

Relational Operations on Functions

Since a function is a special kind of relation, the relational operators may be applied to functions. For example, we can form the inverse of a function. The result is denitely a relation, 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 the inverse will not be a function. The consequence of this argument is that the inverse of an injective function will be a function (also injective). Moreover, the inverse of a surjective function will be total, and the inverse 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 f is also a bijection, but this time from B to A: f = {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 is the relation g = {y a, z b, y c}

It is not a function, since y is mapped to two dierent values. 3. Suppose that we take the inverse of the cube function introduced above; its inverse is 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 the natural 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), which is partial, injective, and surjective.

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 can form a new set; the set consisting of all those objects which are related to members of the rst set. This is called the relational image of the rst set (under the chosen relation), and is formally dened as follows: R( S | == { a : A; b : B | a | ) b Ra 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 eectively found a way to apply a relation to an object, as if that relation were a function. The price we pay is that the result of the application 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 less | ) than or equal to n. 2. If studies is the relation between students names, and the titles of the courses they study, and class is the set of students on this weeks course, then studies( class | is | ) the set of all courses studied by any of the students on this weeks course.

5.5

Cardinality

Suppose that f is a function. Since f is also a relation, we can apply the dom operator to it to obtain its domain. Since f is a function, there are no diverging arrows in f , and therefore the 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, then we have counted all the arrows too. This argument isnt quite right, because if there are innitely many pairs in the graph of f , then we cannot count them and end up with a number. A set A is nite if there is some natural number n N, such that there is a bijection from the set A to the set {1, 2, 3, . . . , n}. The number n is then called the cardinality of A, and is denoted by #A. The bijection ensures that every element of A is counted (since it is total on the set A); that no element is counted more than once (since it is functional, no element of A has two dierent numbers assigned to it); that elements are counted one at a time (since it is injective, no number will be assigned to more than one element); and that the counting is correct (since it is surjective, no number between 1 and n is omitted). The set of all nite subsets of a set A is denoted F A; this is a subset of P A; a proper subset if A is innite.
Example 64 1. Suppose that A is the set {a, b, c}. The cardinality of A is 3; that is, #A = 3, since the function f (a) = 1 f (b) = 2 f (c) = 3 is a bijection. f : {a, b, c} {1, 2, 3}

73

2. Suppose that A is the empty set. The cardinality of A is 0, since the function f : is a bijection, and the empty set really does contain all the numbers strictly between 1 and 0: there arent any!

Though we will not consider such things on this course, cardinalities can be innite. Some innite cardinalities are larger than others.

5.6

The Pigeonhole Principle


If m pigeons occupy n pigeonholes, then m > n if, and only if, there is at least one pigeonhole with two or more pigeons roosting in it.

The pigeonhole principle states that

More formally, if A and B are nite sets, with #A = m and #B = n, for m > n, then there is no injective function from A to B.
Example 65 1. In the Programming Research Group there are 13 University Lecturers, so there must be at least two of them who have birthdays during the same month of the year. (Here we 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 from the Baker Street Laundromat with 17 pairs of socks, each pair a dierent colour, in his laundry bag. The following morning, in a frantic attempt to get dressed before Moriartys trail goes completely cold, he withdraws socks randomly from the bag. He must 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 Principle tells us that at least two pigeons must roost in one of the holes.)

5.7

Functional Composition

We have already seen relational composition o, where an arrow a b is a member of relation 9 R o S exactly when we can nd a c such that a R c and c S b. 9 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 which adds ten to its argument, then d o t is the function which doubles its argument, and then 9 adds ten.

74

Sometimes, however, it is useful to be able to do things in the opposite order. In the example above, if we were to apply d o t to, say, 45, we might calculate: 9 (d o t ) 45 9 = t (d 45) = 100 = t 90

This involves swapping the order of t and d, in moving from the rst to the second line. Another form of composition, written avoids this need. It is exactly the reverse of o: 9 = t (d 45) = 100 = t 90 (t d) 45

Whether or o is used will depend greatly on the situation. Both can be used with both 9 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 o d) 45 9 = d(t 45) = 110 = d 55

5.8

Functional Overriding

It is easy to combine relations: we can just take their union. For functions, the situation is less straightforward: the union f g of two functions may not be a functionit might have diverging arrows (one from f and one from g). How are we to choose which arrow to accept and which to omit? Instead of taking the union of two functions, we override one with another. f g denotes the function obtained by combining f and g, choosing terms from g whenever there would otherwise be diverging arrows. Formally, f g == ((dom g) f)g

When the Course Administrator wants to update the course schedule, some courses may need to be rescheduled; other new ones may be added. This will entail an update of the date function, so that it is the original calendar, with some ammendments: date {Foundations 29Jan96, Management 09Dec96, Surng 03Aug96}

Example 66 Let date is the function which takes the name of a course and returns the date when it will next take place. Thus, date Foundations = 22Jan96.

75

5.9

Problems
(a) partial surjection (not injective) (b) total surjection (not injective) (c) partial injection (not surjective) (d) total injection (not surjective) (e) bijection

1. Draw diagrams to illustrate simple examples of the following classes of function:

2. An important idea in mathematics is in the investigation of whether the combining of two entities with a common property yields a result with that property. (a) Suppose that f and g are both functions. Is f answer is correct.
o 9

g a function? Prove that your


o 9

(b) Suppose that f and g are both injective functions. Is f your answer is correct. (c) Suppose that f and g are both surjective functions. Is f your answer is correct. (d) Suppose that f and g are both bijective functions. Is f your answer is correct.

g injective? Prove that g surjective? Prove that g bijective? Prove that

o 9

o 9

3. If f and g are functions, then are the following necessarily functions, too? (a) f g (c) f \ g

(b) f g

For any that are not necessarily functions, state necessary/sucient conditions on f and 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 dened by f a = R( {a} | | ) then what is the type of f ? Is f partial or total? Surjective? Injective? 5. Give a sucient condition on f and g such that f g = g f . 6. Prove this law on overriding and domain restriction: S 7. Prove f X Y f( S T | = f( S | f( T | | ) | ) | ) (f g) = (S f ) (S g)

8. Let f : A B and g : C D. The product function h : A C B D is dened 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.

76

9. The infamous 91-function is dened recursively as follows: f :NN

f (x) = x 10 f (x) = f (f (x + 11)) (a) Show that f (99) = 91.

if x > 100 if x 100

(b) Prove that f (x) = 91 for all x from 0 to 100. 10. Assuming S and T are nite sets, nd expressions for the following, involving #S and #T (a) #(S T ) (c) #(P S )

(b) #(S \ T )

(d) #(S T ) 11. For nite 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 dierent contracts that deal with a high security project. 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 ve companies working on some part. In how many ways can the contracts be awarded so that every company is involved? 13. How many seven-digit quaternary numbers (that is, numbers which are made up only of the digits 0, 1, 2, 3) have at least one occurrence of each of the digits 0, 1, 2, 3? 14. An m n zero-one matrix is a matrix A with m rows and n columns, such that in row i and column j, the entry ai,j is either zero or one. How many 9 6 zero-one matrices have 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.

Appendix A

Solutions to Chapter 1: Propositional Calculus


Any exercise that involves expressing mathematical terms in ordinary prose will have a range of correct answers: we use mathematics precisely because it enables us to be clearer, more precise and less ambiguous than writing English prose. Only one example solution will be given in such cases. 1. The weather. (i) Its not cold. (ii) Its cold and its raining. (iii) Either its cold, or its raining. (iv) Either its raining, or its not cold. (v) Its neither raining nor cold. (vi) It isnt ne. 2. The beauty contest. (a) p q.

(b) p q.

(d) (p q).

(c) (p q).

(e) (p q). 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;

3. Hamiltons mathematical politics. Let

R stand for Robinson will leave the cabinet; Int (x) stand for x is an integer; Rat (x) stand for x is a rational number;

77

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;

(b) J (S R) W ; (d) M H ;

(a) J W ;

(c) Rat (x) Int (y) Real(z);

(e) M H ;

(g) Rat (x) (Int (y) Real(z)). 4. Stanats Christmas shopping. (a) i. ii. iii. iv. i. ii. iii. iv. p r q. q r. p. p q.

(f) Even(x + y)

(Even(x) Even(y)) (Odd(x) Odd(y));

(b)

I will go to town if and only if I have time and it is not snowing; I have time and I will go to town; I will go to town if and only if I have time; Neither do I have time, nor will I go to town.

5. Stanats converses and contrapositives. Converses (a) If Im 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 cant complete the task, then I dont get more help. Contrapositives (a) If Im going, then it wont rain; (b) You dont go only if I dont stay; (c) If you cannot bake the cake, then you havent got 4lbs; (d) If I can complete the task, then I do get more help. 6. Grimaldis triangles. (a) If ABC is an equilateral triangle, then it is also an isosceles triangle;

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. Grimaldis sizes of truth tables. (a) There are ve propositional variables, so we need 25 rows in the truth table; that is, we need 32 rows. (b) Since p contains n propositional variables, its truth table must require 2n rows. 8. Truth tables. p t t f f p t t f f p t t f f q t f t f q t f t f q t f t f f f t f p f f t t f f f t q f f t f (p q) t t t f (p t t f t q) f t f t

(a)

(b)

(c)

9. Weather forecasting. (a) Rain on Tuesday is a necessary condition for rain on Sunday: Sunday Tuesday. (c) But it rains on Wednesday only if it rains on Friday: Wednesday Friday.

(b) If it rains on Tuesday, then it rains on Wednesday: Tuesday Wednesday.

(d) Moreover, no rain on Monday means no rain on Friday: Monday Friday.

(e) Finally, rain on Monday is a sucient 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.

80 p t t f f q t f t f p t t t t f t t t (p q) t f f f

11. Verify that the proposition (p q) (p q) is a contradiction. p t t f f q t f t f (p q) t f f f f f f f f f f t (p q) t t 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 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 by excluded middle

81 (c) (p q) ((q r ) (r p)) is not a tautology, since it is false in the case that p, q, and r are all true. (d) (p (q r )) ((p q) r ) is not a tautology. Consider the cases where p is false: 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 to true 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 t t f f q t f t f pq t f t t q f t f t t f t t p f f t t

Since they are identical, the two propositions are logically equivalent. (b) (p q) r , (p r ) (q r ); p t t t t f f f f q t t f f t t f f r t f t f t f t f (p q) t t t t t t f f r t f t f t f f f (p r ) t f t f f f f f t f t f t f f f (q r ) t f f f t f f f

Since they are identical, the two propositions are logically equivalent. (c) p q r , r q p; p t t t t f f f f q t t f f t t f f r t f t f t f t f p f f f f t t t t f f f f f f t t q f f t t f f t t t t t t t t f t r f t f t f t f t r t t t t t t f t qp t t t t t t f f

Since they are identical, the two propositions are logically equivalent. (d) p q r , (p q) r . p t t t t f f f f q t t f f t t f f r t f t f t f t f p f f f f t t t t q t t f f t t t t r t f t t t f t f (p f f t t f f f f q) f f t t f f t t r t f t t t f t f

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, then we must be able the nd some assignment to the propositional variables that makes false. Fortunately, this is only in the case that the antecedent is true, but the consequent is false. The consequent is also an implication, and if it is to be false it must be that its antecedent is true, but its consequent is false. So we have that p must be true, and q false. The latter is better expressed by saying that q must be true. So this assignment also make the antecedent (that is ) true? Of course it does, since s antecedent is p which must be false if p is true: thus is true. To illustrate the value of the proposition in the state where both p and q are true, we display just that row of the truth table: p t q t (p f q) t f (p f q) 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 t t f f q t f t f pq t f t t q f t f t p f f t t p.

First of all, we draw up the truth tables for the three propositions in the argument:

The argument is valid if, whenever both the premisses are true, then so is the conclusion. In fact, there is only one row in which both premisses are true, and this has been indicated by the mark; clearly, in this state, the conclusion is also true. Thus, the argument is valid. 16. Show that the following argument is valid: p p t t f f q t f t f p t f f t q q, q p.

The argument is valid, since whenever both the premisses are true, then so is the conclusion. 17. Show that the following argument is a fallacy: p q p t t f f q t f t f pq t f t t p f f t t t t f t q f t f t p q.

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. Lets symbolise this argument by letting S stand for I study; F stand for I fail mathematics; 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 t t t t f f f f F t t f f t t f f L t f t f t f t f S f f t t t t t t F f f t t f f t t L f t f t f t f t S t t t t t f t f

The argument is valid, since whenever all three of the premisses are true, then so is the conclusion. 19. What conclusion can be drawn from the truth of p p? Lets calculate, starting from the proposition, and seeing where it takes us: p p by implication p p by double negation pp by idempotence of p So, we have calculated that p p is equivalent to p; thus, if p p is true, then so is p. 20. (Stanat) For each of the following expressions, use identities to nd equivalent expressions which use only and and are as simple as possible. (a) p q r by double negation (twice)

84

by De Morgans Law (2) by De Morgans Law (2) ((p q) r ) (b) p (q r p) by implication p (q r ) p (q r ) p (p q) r

p q r

by commutativity, associativity, and idempotence of by double negation by De Morgans Law (2) (q r p) (c) p (q r ) (q r ) p

by implication by implication p q r p (q r )

by De Morgans Law (2) by double negation by De Morgans Law (2) (p q r ) 21. (Stanat) For each of the following expressions, use identities to nd equivalent expressions which use only and and are as simple as possible. (a) p q r (p q) r (p q) r

by double negation by De Morgans Law (1) by De Morgans Law (2) (p q r ) ((p q) r ) (p q) r

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) (p q) (q p q) (r p q) (p q) (p q) (r p q)

by idempotence of

by idempotence of

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 p q since true is a zero for by double negation p q by De Morgans 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

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 p q r since false is a unit for by De Morgans Law (1) (p q) r by double negation (p q) r by De Morgans Law (1) (p q r ) 22. (Stanat) Establish the following tautologies by simplifying the left-hand side to the form of the right-hand side: (a) (p q p) pqp by implication (p q) p by De Morgans Law p q p by associativity and commutativity of p p q true q since true is a zero for true (b) ((p q) p) false; by excluded middle true;

((p q) p) by implication ((p q) p) by double negation ((p q) p) by De Morgans Law

87

(p q) p by double negation (p q) p by De Morgans Law p q p by associativity and commutativity of p p q false q since false is a zero false (c) ((q p) (p q) (q q)) (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) (q p) (p q) by commutativity of (p q) (p q) p (q q) p false since false is a unit for p (d) ((p p) (p p)) (p p) (p p) by implication, twice (p p) (p p) by idempotence of false. by distributivity of over by commutativity and contradiction by double negation p; by contradiction

88 p (p p) by double negation p (p p) by idempotence of p p false 23. (a) The nand operator (also known to logicians as the Sheer stroke), is dened by the following truth table: p t t f f q t f t f pnandq f t t t by commutativity and contradiction

Of course, nand is a contraction of not-and; pnandq is logically equivalent to (p q). Show that i. (pnandp) pnandp by denition (p p) by idempotence of p ii. ((pnandp)nand(qnandq)) (pnandp)nand(qnandq) using last result twice pnandq by denition (p q) by De Morgans Law p q by double negation, twice pq iii. ((pnandq)nand(pnandq)) (pnandq)nand(pnandq) using rst result p q. p q; p;

89

(pnandq) by denition (p q) by double negation pq (b) Find equivalent expressions for the following, using no connectives other than nand: i. p q; pq p q (pnandp) q ((pnandp)nand(pnandp))nand(qnandq) This seems really rather long winded, and the problem is that we have translated p q into a nand expression in an unreasonable way. Instead of translating it literally, lets massage the expression until we think it is more suitable for translation. pq p q (p q) pnandq pnand(qnandq) Now thats better. q. ii. p p q (p q) (q p) ( nand ) nand ( nand ) (((qnandq)nand(qnandq))nand(pnandp)) (((qnandq)nand(qnandq))nand(pnandp)) (((pnandp)nand(pnandp))nand(qnandq)) (((qnandq)nand(qnandq))nand(pnandp)) (((pnandp)nand(pnandp))nand(qnandq))

(((pnandp)nand(pnandp))nand(qnandq))

90

This is breathtakingly complicated, and again we have proceeded in an unreasonable way. Lets try again. p q (p q) (p q) ((p q) (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 dened by the following truth table: p t t f f q t f t f p nor q f f f t

(pnandq)nand((p q))

((p q))nand((p q))

For each of the following, nd equivalent expressions which use only the nor operator. i. p; p (p p) pnorp

ii. p q; pq (p q) (pnorq) ((pnorq) (pnorq)) (pnorq)nor(pnorq) iii. p q. pq (p q) pnorq (pnorp)nor(qnorq)

24. Give an explanation of the second and third proofs in example 9. Proof 2. Proof of the contrapositive: x0

arithmetic

91

a minus times a minus is a plus multiplying out (x 1)(x 2) 0

x 10x 20

x 2 3x + 2 0 The proof of the real theorem follows easily: x 2 3x + 2 < 0 x > 0 contraposition (x > 0) (x 2 3x + 2 < 0) x 0 x 2 3x + 2 0

negation of comparisons by the above true

Proof 3. Demonstrate the contradiction: x 2 3x + 2 < 0 x 0

multiplying second inequality by 3 both sides x 2 3x + 2 < 0 3x 0

subtracting 2 from both sides of second inequality rearranging x 2 3x + 2 < 0 3x 2 2

since 2 < 0

x 2 < 3x 2 3x 2 2 x 2 < 3x 2 3x 2 < 0

transitivity of < x2 < 0 false

squares of real numbers are always positive We may use this fact to establish the result we want: (x 2 3x + 2 < 0 x 0) false by implication (x 2 3x + 2 < 0 x 0) false

by unit for

by De Morgans Law (2) by implication

(x 2 3x + 2 < 0 x 0) (x 2 3x + 2 < 0) (x 0) (x 2 3x + 2 < 0) (x 0)

92

by rewriting negated inequality (x 2 3x + 2 < 0) (x > 0)

Appendix B

Solutions to Chapter 2: Predicate Calculus


1. (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) (m) (n) (o) (p) (q) (r) (s) (t) (u) (v) (w) (x) (y) (z) s : Snake Reptile(s) s : Snake Poisonous(s) c : Person | Child(c) Present (c) e : Person | Executive(e) HasSecretary(e) e : Person | HasSecretary(e) Executive(e) p : Person | Vote(p) PollTax(p) p : Person; l : Lift | Employee(p) p UsesLift l Goods(l) p : Person; l : Lift | p UsesLiift l Goods(l) Employee(p) t : Thing | Gisters(t ) Gold(t ) p, q : Person | EstateAgent (p) EstateAgent (q) p q p, q : Person | EstateAgent (p) EstateAgent (q) p = q p : Person | Brave(p) DeservesFair (p) p : Person | Visitor (p) Dined(p) p : Person | Visitor (p) Dined(p) t : Thing | InHouse(t ) EscapedKids(t ) s : Student Intelligent (s) HardWorking(s) c : Coat | Waterproof (c) Treated(c) m : Medicine Dangerous(m) TooMuch(m) x : Food | Fruit (x) Veg(x) Wholesome(x) Nourishing(x) t : Thing | Enjoyable(t ) Immoral(t ) Illegal(t ) Fattening(t ) l : Person | Lecturer (l) GoodTeacher (l) WellInformed(l) Entertaining(l) p : Person | VastlyUnderpaid(p) Indispensible(p) Lecturer (p) Fireman(p) a : Actor | Famous(a) Talented(a) RegularlyWound(w) Abused(w) w : Watch GoodTimekeeper (w) p : Person | TalksALot (p) SaysAGreatDeal(p) c : Car | Age(c) > 10 SeverelyDamaged(c) ToBeMended(c)

93

94

2. (a) (b) (c) (d) (e) (f) (g) (h) (i) (j) (k) (l) (m) 3. (a) (b) (c) (d) (e) 4. (a) (b) (c) (d) (e) (f) (g) 5. (a) (b) (c) (d) (e) 6. ( x: T A(x)) ( y : U B(x, y ))
f f b f b b b1 b1 b b2 b b b f b

e : Elephant | Neat (e) WellGroomed(e) Attractive(e) e : Elephant Gentle(e) WellTrained(e) e : Elephant Gentle(e) ( s : Student s HasWellGroomed e) e : Elephant | Jumbo(e) WellTranied(e) gentle(e) e : Elephant | WellTrained(e) Gentle(e) e : Elephant | Jumbo(e) WellTrained(e) Gentle(e) e : Elephant | Gentle(e) WellTrained(e) e : Elephant | WellTrained(e) Gentle(e) e : Elephant | Gentle(e) WellTrained(e) e : Elephant Gentle(e) WellTrained(e) e : Elephant | Gentle(e) WellTrained(e) e : Elephant Jumbo(e) Dumbo(e) s : Student ( e : Elephant s RidesToGraduationOn e)

t : Time ( u : Time u isbefore t ) t , u : Time | t u t isbefore u u isbefore t t : Time ( u : Time t isbefore u) t : Time ( u : Time u isbefore t ) t , u : Time | u isafter t t isbefore u

n : Z 3 < x < 5 n : Z ( m : Z m < n) n : Z ( m : Z m n) x, y : Z x + y = y + x m, n : Z m n < m + n x, y, z : Z | x 0 y 0 z 0 x 3 = y 3 + z 3 n : N | n > 2 ( x, y, z : Z | x 0 y 0 z 0 x n = y n + z n )

A(x, y ) ( x: T B(y )) ( y : U ; z: V C(x, y , z))


b2 f b f b f f

b b

( x: T y : U A( y , x) ( y : V C( y ))) B(x, y ) x: T ; y : U A(z) B(z)


f b

A(x) (B(y ) ( x: T C(y ) ( y : U D(x))))

(b) This substitution is not legal, since there would be variable capture. (d) 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)).

(a) ( x : T A(x)) ( y : U B(f (x, z), y)).

95

(e) This substitution is not legal, since there would be variable capture. 7. (a) (b) (c) (d) (e) (f) (g) (h) 8. (a) (b) (c) (d) 9. x x 10. x = x 11. (a) (b) (c) (d) (e) (f) (g) (h) x : Z E (x) x : Z E (x) O(x) x : N | P (x) N (x) x : N | E (x) P (x) x = 2 x : N | E (x) P (x) ( y : N | E (y) P (y) y = x) x : Z O(x) x : Z | P (x) O(x) x : Z | E (x) O(x) p : Person ( q : Person | q p married(p, q)) x : Z ( y : Z x + y = 0) y : Z ( x : Z x + y = 0) x : Z x < 0 n : Noise AppalsMe(n) t : Thing | Wicked(t ) ThisWayComes(t ) a : Armity | Strange(a) IHave(a) c : TheirCandles Out (c) p : Person | Child(p) His(p) m : Murder Performed(m) i : Person | Idiot (i) i told x p : Person | OfWomanBorn(p) p ShallHarm Macbeth

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) (b) (c) (d) i, j : N | 1 i 20 1 j 30 Ai,j 0 j : N | 1 j 30 A4,j > 0 A15,j > 0 i, j : N | 1 i 20 1 j 30 Ai,j = 0 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)

96

(b) It is a generalisation of exclusive-or. 16. (a) x : S p q

implication distribution x : S p q ( x : S p) ( x : S q) ( x : S p) ( x : S q)

generalised De Morgan distribution

( x : S p) ( x : S q) (b) Let x be an arbitrary member of S , and consider rst: ( x : S p q) ( x : S p) (p q) ( x : S p) (p q) p

specialisation

specialisation

propositional calculus q generalisation

x : S q

We have proved something of the form (s t ) u, which is, by exportation,equivalent to (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) ( x : S p) ( x : S q) ( x : S p) ( x : S q) x : S p q x : S p q

generalised De Morgan

forall implies exists, with monotonicity distribution implication

97

(d) x : S p N implication x : S p N ( x : S p) N ( x : S p) N

no capture on

generalised De Morgan implication

( x : S p) N (e) x : S N p implication x : S N p N x : S p

no capture on implication

N x : S p (f) x : S p N

implication no capture on x : S p N ( x : S p) N

generalised De Morgan implication ( x : S p) N

( x : S p) N

Appendix C

Solutions to Chapter 3: Set Theory


1. Let M = {r , s, t }. State whether each of the following is correct or incorrect: 2. Specify the following set explicitly: (a) The set of nonnegative integers less than 5: { n : N | n < 5 }. (a) (c)

r M Correct {r } M Does not type ch

(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 | x 2 = 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 greater than 5: {7}.

(d) D = { x : N | x is a letter in the word correct } D is the set of all nonnegative numbers 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 and 12: {4, 5, 6, 7, 8, 9, 10, 11}.

(c) C = { x : N | x > 0 x < 0 } C is the set of all nonnegative numbers which are both greater than zero and less than zero: .

(h) { x : Z | x = 2 x = 5 } This is the set of all numbers which are either 2 or 5: {2, 5}. 4. Dene each of the following at set comprehension terms: (a) The set of integers between 0 and 100: { n : Z | 0 n 100 }. (c) The set of human fathers: { p : Person | ( q : Human p fatherof q) }. 98

(g) { x : Z | x DecimalDigit } This is the set of all numbers which are also in the set DecimalDigit : {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.

(f) DecimalDigit = { x : N | 0 x 9 } DecimalDigit is the set of all nonnegative numbers which lie between 0 and 9: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}.

(b) The set of integer multiples of 10: { n : Z 10 n }.

99

(d) The set of tautologies: { p : Proposition | p TruePropositions }. (This is rather a vacuous solution, since it denes the set of tautologies in terms of an undened set of TruePropositions. Not much progress has been made, and perhaps we should return to our denition of tautology. This says that a proposition is a tautology if 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 }. (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 simple rule 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 nite? (a) (c) (e) The months of the year. Finite. The people living on the earth. Finite. {1, 2, 3, . . .}. Innite. (b) (d) {1, 2, 3, . . . , 99, 100}. Finite. { x : N | x is even }. Innite. (f) The even numbers {2, 4, 6, 8, . . .}: { n : N 2 n }.

6. Which of these sets are equal? (a) { x : Letter | x is in the word follow }. (c) { x : Letter | x is in the word ow }.

(b) The letters which appear in the word wolf . (d) The letters which appear in the word ower . (e) The letters f , l, o, and w. (g) { x : Z | ( y : Z x = 2 y) } (i) {0, 2, 2, 3, 3, 4, 4, . . .} (f) { x : Z | x is even and x 2 is odd }

(h) {1, 2, 3}

(k) {3, 3, 2, 1, 2} We have that

(j) { x : Z 2 x }

(l) { x : Z | x 3 6 x 2 7 x 6 = 0 } 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 | x 2 = 9 and 2 x = 4 }. Empty.

100

(d) D = { x : N | x + 8 = 8 }. Nonempty.

(c) C = { x : N | x x }. Empty.

(e) { n : Z | n > 2 ( x, y, z : N | x 0 y 0 z 0 x n +y n = z n ) }. Empty. (Until recently, no one could answer this question. It relies on the (in)famous Fermats Last Theorem. This year, a Cambridge mathematician working in the U.S.A. claimed to have a lengthy proof.)

8. List all the subsets of the following sets (b) This set is ill-formed. (a) {, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}} (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 sets involved). (e) {, {}, {{}}, {, {}}} (g) This set is ill-formed. (f) The required set has 2 elements: {, {{1, 2}}}.

9. Let the following sets of gures in the Euclidean plane be dened: Q = { x : Euclidean | x H = { x : Euclidean | x R = { x : Euclidean | x S = { x : Euclidean | x S RQ is a quadrilateral } is a rhombus } is a rectangle } is a square }

Which of these sets are proper subsets of the others? S H Q 10. Does every set have a proper subset? Nothe 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:

by the denition of subset Since nothing belongs to the mpty set by the denition of implication since false is a unit for by the denition of empty set

x : X x A x x : X x A false

x : X (x A) false x : X x A A=

101

12. How does one prove that a set A is not a subset of a set B? One very simple way is to exhibit a member of A that does nbot belong to B. Prove that A = {2, 3, 4, 5} is not a 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 (a) Y X True. (b) Z Z False. (d) V X False. (e) W Z True. of the following statements is true or false: (g) Z V True. (h) X = W False. (j) W Y False. (c) (f) (i)

W V Y Z V 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}, and F = {s}. Let X be an unknown set. Determine which sets A, B, C, D, E , or F can equal X if (a) X A and X B. X = D (b) X B and X C. X = C we are given the following information: (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 (a) a C, True (b) suppose that d A, e B, f C. Which statement must be true? (d) e A, True (e) 18. In the Venn diagrams below, shade the set A B:

d B, Cant c A, Cant

B B A A

B A

19. Let A = {1, 2, 3, 4}, B = {2, 4, 6, 8}, and C = {3, 4, 5, 6}. Find (b) {1, 2, 3, 4, 5, 6} (d) {2, 4, 6, 8} (c) {2, 3, 4, 5, 6, 8} (a) {1, 2, 3, 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 A B.

102

Proof AAB by the denition of subset by the denition of set union by propositional calculus by predicate calculus

x : X x A x A B

x : X x A x A x B x : X true true The other case is symmetrical. 21. Prove that set union is idempotent, that is, that A = A A. Proof A=AA by the denition of equality by the denition of set union xAxA x AA

x : X x A

x : X x A x : X x A true

by the idempotence of by predicate calculus xA

22. Prove that A = A . Proof A=A by the denition of equality by the denition of set union since nothing is in the empty set by propositional calculus (unit for ) by predicate calculus xA x A false xAx x A

x : X x A

x : X x A

x : X x A

x : X x A true

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

103

Proof AB = by the denition of equality x : X x A B x : X x A B x : X (x A B) by the denition of set union x : X (x A x B) DeMorgans Law x : X x A x B by predicate calculus ( x : X x A) ( x : X x B) by the denition of the empty set A=B= 24. In the Venn diagrams below, shade the set A B: x false since nothing is in the empty set by predicate calculus

B B A A

B A

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

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

104

Proof AB A by the denition of subset x : X x A B x A by the denition 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 = A A. Proof A=AA by the denition of equality x : X x A x : X x A x : X x A x : X true true 28. Prove that A = . Proof A= by the denition of equality x : X x A x : X x A x false by the denition of empty set by the propositional calculus x AA xAxA xA by the denition of intersection by the idempotence of

by the idempotence of by predicate calculus

105

x : X (x A )

by the denition of intersection by the denition of empty set since false is a zero for by propositional calculus by predicate calculus

x : X (x A x ) x : X (x A false) x : X false x : X true true

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

B B A A

B A

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

31. Prove that A \ B is a subset of A. Proof A\B A by the denition of subset by the denition of \

x : X x A \ B x A x : X x A x B x A by propositional calculus by predicate calculus x : X true true 32. Prove that (A \ B) B = .

106

Proof (A \ B) B = by the denition of equality x : X x (A \ B) B x : X (x (A \ B) B) by the denition of intersection x : X (x (A \ B) x B) 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 denition of equality x : X x A \ B x : X (x A \ B) 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 denition of subset AB 34. Prove that A \ B is a subset of A B. by the denition of \ x by the denition of the empty set and propositional calculus by the denition of \ x by the denition of the empty set

107

Proof A\B AB 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 A B = A. Proof AB =A by the denition of equality x : X x A B xA xA by the denition of intersection x : X x A x B 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 AB 36. Prove that A B implies A (B \ A) = B. AB x : X x A x B by propositional calculus x : X x A x B by propositional calculus by denition of

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) xB xB by propositional calculus x : X (x A (x B x A)) A (B \ A) = B 37. by denition of \, , and equality

(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 xBxA by propositional calculus

(a) Prove that set dierence is not commutative. Consider a counterexample: {1}\ \ {1}.

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 by set theory A=B (c) Is set dierence associative? Take the following as a counterexample: {1, 2} \ ({1} \ {1, 2}) = {1, 2} \ = {1, 2} xB

({1, 2} \ {1}) \ {1, 2} = {2} \ {1, 2} =

109

38. Let A, B, and C be arbitrary sets. Express A B C as a union of disjoint sets. ((A \ B) \ C) ((B \ A) \ C) ((C \ A) \ B) (A B C) 39. Let A, B, and C be arbitrary sets. (a) Show that if C A and C B then C A B. (That is, A B is the largest set contained in both A and B.) C AC 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 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 B C AB

(b) Show that if C A and C B then C A B. (That is, A B is the smallest set which contains both A and B.) C AC 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 B) x C x : X (x A x B) x C x : X (x A x B) x C x : X x A B x C x : X (x A x C) (x B x C)

C AB

40. Suppose that A and that A B = A C. Show that it does not necessarily follow that B = C. Consider the case where B and C are dierent subsets of A. For example, choose A = {1, 2}, B = {1}, and C = {2}. Suppose in addition that A B = A C; can you now conclude that B = C? Consider what would happen if we could nd x such that x B but x C. Since x B, we clearly have x A B. Now, this is equal to A C, so x A or x C. We know that the latter is false, so we have x A. So x A B, and because AB = AC we know that x AC. Therefore x A and x C. Now we have a contradiction, so we know that there is no such x. Therefore B C. By symmetry C B, so B = C. 41. Prove the absorption laws: (a) A (A B) = A x : X x (A (A B)) x : X x A (x A x B)

x : X (x A true) (x A x B)

110 x : X x A (true x B) x : X x A true x : X x A

(b) A (A B) = B x : X x (A (A B)) x : X x A (x A x B) x : X x A (false x B) x : X x A false x : X x A

x : X (x A false) (x A x B)

42. In each of the following, nd the generalised union and generalised intersection. (a) {} {} = , {} =

(b) {, {1}}

(d) { i : N {i} }

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

{, {1}} = ,

{ i : N {i} } = ,

{{a}, {b}, {a, b}} = ,

{, {1}} = {1}

{ i : N {i} } = N

{{a}, {b}, {a, b}} = {a, b}

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}} (c) P{{a, b}, {b, a}, {a, b, b}} = {, {{a, b}}}

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

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 obtained by 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 the other. Assume that all input sets are nite subsets of N. 46. (Stanat) Programming Problems (a) Write a program to generate the power set of {0, 1, 2, . . . , n} for any natural number n given as input. (b) i. Write a program which accepts specications of two nite subsets of the natural numbers, A and B, and prints a nonredundant list of the elements of A B and A B. ii. Write a program to determine for a given set A and an arbitrary n N whether or not n A.

Appendix D

Solutions to Chapter 4: Relations


1. Show that the relation divides, which was introduced in Example 46.2, is a partial ordering on N. Recall the denition of divides: divides == { a, b : Z | ( m : Z b = m a) } and the notion of a partial ordering: (a) a (b) a (c) a a (reexivity); bb bb a a = b (antisymmetry); and ca c (transitivity).

Now, divides is reexive, since a divides a by denition of divides m : Z a = m a by existential introduction 1Za =1a true a = 1 a a =1a a=a by reection true The argument for antisymmetry is as follows. First, notice that if we have the two equations b = m a and a = n b, then m and n are both 1. b =ma a =nb rewriting the rst equation using the second 111 since true is a unit for since 1 is an integer

by arithmetic

112

b =mnb by arithmetic mn =1 by arithmetic m=1n=1 Now, we can use the denition of divides to prove our result: a divides b b divides a by denition 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 1Zb =1a a =1b by arithmetic and propositional calculus a=b Finally, the argument for transitivity goes like this. If a divides b, then b is some multiple of a, say m a; if b divides c, then c is some multiple of b, say n b. Putting these together, we have c is a multiple of a, namely n m a. Formally, a divides b b divides c by denition 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 rst m, n : Z b = m a c = n m a by predicate calculus by predicate calculus m, n : Z c = n m a m, n : Z p : Z c = p a by predicate calculus

113

p : Z c = p a by changing the bound variable m : Z c = m a by denition of divides a divides c 2. Explain why is an equivalence relation on the set of all propositions. If is an equivalence relation, then it must be reexive, symmetric, and transitive. It has each of these properties, since the following are theorems of the propositional calculus: p (p (p p q) (q p) r ) (p r) q) (q

Each may be veried using a truth table. 3. Let be a total ordering on a set A. Dene the associated strict ordering a b a b a b. b on A by

Prove that is a transitive relation. First, consider a, b, and c which are such that a and b c. Suppose that a = c. a c bb bb ca=c c rewriting the rst predicate with the equation by the denition of c c bcbb rearranging bb cbc (its a total order) by antisymmetry of b=cbc by contradiction false So, the assumption that a = c leads to a contradiction, so we can conclude that a bb c a c. cbc

Transitivity now follows easily. a a bb bb c cac

by the previous argument by the denition of

114

a a

babb bb

cbcac

by propositional calculus cac by transitivity of a a cac by the denition of c (its a total order)

Is it total? The relation is irreexive, since we have from its denition that a b a b; thus it cannot be a total order. Is it antisymmetric? It is antisymmetric, but only in a degenerate way: since we cannot have both a b and b a (since it is irreexive), the antecedent is false in the predicate that denes the property of antisymmetry: a bb a a = b,

and so the property holds. 4. Prove the following theorems. A (B C) = (A B) (A C)

(A B) C = (A C) (B C) We prove only the rst of these three.

(A B) C = (A C) (B C)

A (B C) = (A B) (A C). Proof Let (x, y) be an arbitrary element of A (B C). by Cartesian product membership x Ay BC by property of set intersection x A (y B y C) (x A y B) (x A y C) by Cartesian product membership (x, y) A B (x, y) A C by property of set union (x, y) (A B) (A C) Thus, the two sets must be equal. since distributes over itself

(x, y) A (B C)

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} {1, 2, 3}. Every member of the power set of this Cartesian product is a binary relation on the original set; the power 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 reasoning 2 as in the rst part of the question, we have 2n 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 both negative. This is reexive, symmetric, and transitive (and therefore an equivalence relation). (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 reexive and symmetric. It is 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 the relation possesses the property. A relation is reexive if every element in the source of the relation is related to itself. Thus, the empty relation on the integers is not reexive, since, for example, (0, 0) . However, the Cartesian product Z Z contains every pair of integers; in particular, we have that id Z Z Z. Thus, the Cartesian product on Z is reexive. From the Law of Reexivity, every number is self-identical, so equality is reexive. The strict inequality < is clearly not reexive, but the non-strict inequality is. We addressed the reexivity of divides in Question 1. A relation is irreexive if no element of the source is related to itself. The empty relation and the strict inequality are therefore irreexive. A relation is symmetric if, whenever it relates a to b, it also relates b to a. The empty relation is symmetric, but in a rather trivial way, since it relates nothing. The Cartesian product is the full relation: it relates everything, and so is symmetric. Equality is obviously symmetric, and so therefore is the non-strict inequality, since it contains equality. The strict inequality is not symmetric. A relation is antisymmetric if the only symmetric pairs are of the form (a, a). Again, the empty relation trivially satises this property. The Cartesian product is not antisymmetric, but equality is. The strict inequality is antisymmetric, but only trivially so. The non-strict inequality and divides are both antisymmetric. A relation is transitive if, whenever a is related to b and b to c, then a is related to c. The empty relation is trivially transitive; all the other relations are transitive.
Reexive Irreexive Symmetric Antisymmetric Transitive no yes yes yes yes ZZ yes no yes no yes = yes no yes yes yes < no yes no yes yes yes no yes yes yes divides yes no no yes yes

8. Find a nonempty set and a relation on it which is neither reexive nor irreexive. Choose 1, 2 1}. This is the set to be as small as possible. Take {1, 2} as the set, and {1 not reexive with respect to the set {1, 2}, since it does not relate 2 to itself. It is not irreexive, since 1 is related to itself. What if the set is empty? In Solution 7, we had that the empty relation on the set Z is not reexive, but that is with respect to Z. If we consider the empty relation with respect to the empty set, then it is reexive, since every element in the empty set is related to itself trivially. Also, it is irreexive, since no element is related to itself. If this sounds contradictory, then consider the formalisation of the two statements: x : x x : x x x .

116

These are not actually contradictions. 9. Construct a binary relation on a nonempty set which is neither symmetric nor antisymmetric. Choose the set to be as small as possible. Take {1, 2, 3} as the set, and 2, 2 1, 3 1} as the relation. It is not symmetric, since it contains 3 1, but {1 3. It is not antisymmetric, since it cotains the pairs 1 2 and 2 1. What if not 1 the 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; in each row, you may assume that the relations R and S both possess the property individually. For each relation that does not possess the property, give a counterexample. A relation is reexive if it contains the identity on the source. So, if R is reexive, then any relation which includes R is also reexive, since it must also contain the identity. R S is one such larger relation. If the identity is a subset of both R and S , then it is a subset of their intersection. A relation is irreexive if it is disjoint from the identity on the source. If both R and S are disjoint from the identity, then so are R S and R S . A relation is symmetric if it is its own inverse. Consider the following. (x, y) (R S ) from the denition of relational inverse (y, x) R S from the denition of set union (y, x) R (y, x) S from the denition of relational inverse (x, y) R (x, y) S from the denition of set union (x, y) (R S ) Thus, (R S ) = from the previous argument R S RS = since both R and S are symmetric

So, if R and S are both symmetric, then so is R S , since it is its own inverse. A similar argument suces to show that R S is symmetric also. A relation R is antisymmetric if we have that RR id A, for source A. Supposing that both R and S are antisymmetric, (R S ) (R S ) = from the previous argument (R S ) (R S ) = by the distribution law

(R R ) (S S ) (R S ) (S R )

117

We know that the rst two terms are subsets of id A, so in order for the relation R S to be antisymmetric, we need to show that R S id A and S R id A. There is no reason to suppose that either of these is true in the general case. As an example of two antisymmetric relations whose union is not antisymmetric, take R to be {1, 2} and S to be {2, 1}. There are no symmetric pairs in either, so they are both 2 and antisymmetric by default. However, the union has a symmetric pair, namely 1 1, and thus is clearly not antisymmetric. If we consider the intersection, then we 2 are in a happier position. Again, supposing that both R and S are antisymmetric, R S (R S ) R S R S R R S S R R id A

= by the previous argument = by rearranging since A B A since R is antisymmetric

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 a 2} for R and {2 3} for S . Clearly, counterexample is not hard to nd. Consider {1 RS is not transitive. The intersection of two transitive relations is, however, transitive, as is shown by the following argument. a a a a b RS b bRa bRb cRa c RS
Reexive Irreexive Symmetric Antisymmetric Transitive Union RS yes yes yes no no Intersection RS yes yes yes yes yes

from the denition of intersection rearranging bS b cRa cRb bS b cS cS

c RS

since R and S are both transitive cS

from the denition of intersection a

118

11. Sketch graphs of the following relations on the set of real numbers, and determine what kinds of properties the relations have. (b) { x, y : Real | x 2 1 = 0 y > 0 }. (a) { x, y : Real | x = y }.

(c) { x, y : Real | abs(x) 1 abs(y) 1 }.

(a)

(b)

(c)

y 1

-1

1 x

-1 -1

Reexive Irreexive Symmetric Antisymmetric Transitive

(a) yes no yes yes yes

(b) no no no yes yes

(c) no no no yes yes

12. Write a program which takes as input a relation described as a set of ordered pairs and determines whether it is reexive, irreexive, symmetric, antisymmetric, or transitive. 13. (Stanat & McAllister) Prove or disprove the following assertions. (a) If R and S are reexive, then R o S is reexive. R o S is reexive, providing that it 9 9 contains the identity on its source. It is sucient to prove that (x, x) R o S , for 9 all x. (x, x) R o S 9 by the denition 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 reexive, the resulting predicate (x, x) R (x, x) S is true. (b) If R and S are irreexive, then R we oer a counterexample: {1 2} o {2 9 1} = {1
o 9

S is irreexive. This assertion is not true, and

1}.

The two relations being composed are irreexive, but the result is not. (c) If R and S are symmetric, then R o S is symmetric. A relation is symmetric if it is 9 its own inverse. Consider the inverse of R o S . 9 (x, z) (R o S ) 9 by the denition of inverse

119 (z, x) R o S 9 by the denition of composition y : A (z, y) R (y, x) S by the denition of inverse y : A (y, z) R (x, y) S by rearranging y : A (x, y) S (y, z) R by the denition of composition (x, z) S o R 9 There is no reason to conclude that (R o S ) = S o R , and so the composition is 9 9 not in general symmetric. As a counterexample, consider the following R = {a S = {b R o S = {a 9 b, b c, c c} a} b}

(d) If R and S are antisymmetric, then R o S is antisymmetric. This assertion is not 9 3, 2 3}, and for S true. Take as the relation R the antisymmetric relation {1 1, 3 2}. Now the composition is the antisymmetric relation {3 {1 2, 2 1}

which is not antisymmetric. (e) If R and S are transitive, then R o S is transitive. This assertion is not true, as the 9 following counterexample shows. {a c, b c} o {c 9 b, c d} = {a b, b d}

14. Prove that dom distributes through ; that is dom(R Q ) = dom R dom Q Does the same hold for ran? What about ?. Let x be an arbitrary member of dom(RQ ). x dom(R Q ) denition of dom union of relations distribution denition of dom denition of

y : B x (R Q ) y

y : B x Ry x Q y

( y : B x R y) ( y : B x Q y) x dom R x dom Q

120 x (dom R dom Q ) We have shown that an arbitrary member of dom(R Q ) is also a member of dom R dom Q ; hence the sets are equal. A very similar proof can be demonstrated for ran. For , we cannot establish equality, but can prove inclusion: dom(R Q ) dom S dom Q 15. Prove that dom(S x dom(S R) = S (dom R). Let x be an arbitrary member of dom(S R) R) y R).

denition of dom denition of conjunction- non-capture denition of dom denition of

y : B x (S

y : B x Ry x S

( y : B x R y) x S x dom R x S x (dom R S ) Hence, dom(S

R) = S (dom R).

16. Can (R+ )+ be simplied? Yes: R+ is transitive, so taking its transitive closure leaves it unchanged. (R+ )+ = R+ .

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

122

2. An important idea in mathematics is in the investigation of whether the combining of two entities with a common property yields a result with that property. (a) Suppose that f and g are both functions. Is f o g a function? Prove that your 9 answer is correct. f o g is a function. Suppose it is not. Then, we can nd x, y1 9 and y2 such that x y1 f o g and x y2 f o g, and y1 y2 . Since these arrows 9 9 belong to these relational compositions, we have the existence of mid-points z1 and z2 , with x z1 z1 f x z2 f y1 g z2 y2 g

Now, since f is a function, we must have that z1 = z2 . Since we now have that y1 g and z1 y2 g, and g is a function, we must conclude that y1 = y2 . z1 This is a contradiction, hence f o g is a function. 9 (b) Suppose that f and g are both injective functions. Is f o g injective? Prove that 9 your answer is correct. f o g is injective. Otherwise, we have distinct x1 and x2 , 9 with some y such that (f o g)x1 = y and (f o g)x2 = y. That is, g(f x1 ) = g(f x2). 9 9 In this case, either f x1 = f x2 a contradiction, since f is injectiveor, if they are not equal, then g maps distinct values to the same value ya contradiction, since g is injective. Therefore f o g is injective. 9 (c) Suppose that f and g are both surjective functions. Is f o g surjective? Prove that 9 your answer is correct. f o g is surjective provided the target of f and the source 9 of g are identical. Otherwise, if the former is a subset of the latter, then there may be 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 o g bijective? Prove that 9 your answer is correct. This follows from the previous two answerswith the same caveat as for surjections. 3. If f and g are functions, then are the following necessarily functions, too? (a) f g (c) f \ g

(b) f g

For any that are not necessarily functions, state necessary/sucient conditions on f and g (maybe in terms of dom or ran for their combination to be a function). f g is a function, because intersection can only reduce the collection of arrows, so no diverging arrows can be introduced. The same applies to f \ g. f 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 sucient condition for the union of f and g to be a function, then, is that their domains are disjointi.e. that there is no x like the one above: dom f dom g = In fact, this condition is stronger than is necessary. A weaker condition which is still sucient is that where the domains of f and g overlap, they must yield the same results. That is, x : dom f dom g f x = g x

123 4. If R : A B is a relation, and f is dened by f a = R( {a} | | ) then what is the type of f ? Is f partial or total? Surjective? Injective? f : A P B. f is total because its value is dened for every member of A (if a is not in dom A, then f a = ). In general, it will not be surjective or injective. 5. Give a sucient condition on f and g such that f g = g f . One condition is that f g = f g, and hence the same conditions apply as those necessary for f g to be a function (above). 6. Prove this law on overriding and domain restriction: S (f g) = (S f ) (S g) f ) (S g), say x y.

Consider an arbitrary member of (S x y (S x x f ) (S g) g)) g))

denition of function overriding denition of denition of (x (x (x y ((dom(S y ((dom(S and y (S (S (S f )) (S f )) x g)) (x g) y (S g)

denition of

, and dom(S

f ) x dom(S

propositional calculus, and denition of propositional calculus (x ((x (x x

y f x S x (S dom g)) (x

g) = S dom g

y g x S) y g x S) y g x S)

y f x S (x S x dom g)) (x y f x S x dom g) (x y f x dom g) x f) x

propositional calculus denition of

y g x S)

y g) x S y g) x S

denition of denition of x denition of x

y ((dom g)

y (((dom g)

f ) g) x S

y (f g) x S y S (f g)

This is rather long-winded. Can we improve on it? Yes; we have made use of one identity that we proved earlier: dom(S g) = S dom g; we can use others, too: S = denition of (f g)

124 (((dom g) ((dom g) and , \, f ) g) g) g) g) g)

S (S

= distribution of = property of = property of

over

f )) (S

((S \ dom g)

= property of dom and (dom(S (S g) = denition of 7. Prove f X

((S dom g)

and (S

f ) (S

f )) (S f )) (S

(S

f ) (S

f)

Y f( S T | = f( S | 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 converseunder the assumption that f X Y : since there are no converging arrows, the xs identied by the two quantiers must be the same. Consider, then, an arbitrary member of f ( S T | | ): y f( S T | | ) denition of ( | | )

denition of , and propositional calculus see above, assuming f X denition of ( | | ) Y

x : X x S T f x = y

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) y f( S | y f( T | | ) | ) y f( S | f( T | | ) | )

denition of

Therefore, we have shown f X T y : Y y f( S T | y f( S | f( T | | ) | ) | ) This is sucient to prove the result. 8. Let f : A B and g : C D. The product function h : A C B D is dened 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.

125

9. The infamous 91-function is dened recursively as follows: f :NN

f (x) = x 10 f (x) = f (f (x + 11)) (a) Show that f (99) = 91.

if x > 100 if x 100

(b) Prove that f (x) = 91 for all x from 0 to 100. 10. Assuming S and T are nite sets, nd expressions for the following, involving #S and #T (a) #(S T ) = #S + #T #(S T ) (c) #(S T ) = #S #T

(b) #(S \ T ) = #S #(S T ) (d) #(P S ) = 2#S

There are 2#S #T relations between S and T . This is because every relation is a subset of the Cartesian product S T ; there are 2n elements in the powerset of an n-element set; and there are #S #T elements in the Cartesian product. 11. For nite sets A and B, (a) How many functions are there between A and B? The sum of the number of total functions and the number of strictly partial functionssee 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 functions when restricted to various subsets of B. The number of such functions, then, is the sum of the number of total functions to B for each of those subsets.
2#A 1 i=0 (#B)! (d) How many injections are there from A to B? #B P#A , i.e. (#B#A)! . There are as many injections as there are ways of choosing (#A) elements of B.

(e) #(S T ) = 2#S #T

#B i

(e) How many surjections are there from A to B? Since it is the target that holds the key to the denition of a surjection, we can calculate the number of surjections by induction on the cardinality of the target. Heres a likely basis. Suppose that A has cardinality m and B has cardinality n. If n = 1, then there is exactly one surjection from A to B: namely, the constant function. If n > 1, then we have

#(A B) = #(A B) #NS


where NS = {f : A B | ran f B}. NS is interesting, because although the functions in it are non-surjective w.r.t. B, they are surjective w.r.t. a subset of B. Thus, we have an inductive denition of the size of A B. Take C to be a proper

126 subset of B. There are s = #(A C) 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 functions which are not surjections to B. Subtract this from the number of functions from A to B (which is n m ), and were done. This this is summarised as follows:

#(A B) = S (#A, #B),


where S (m, 1) S (m, n) = = 1
n1

nm

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 number of ways of choosing all the elements of A; that is (#A)!. 12. The Ministry of Defence has eight dierent contracts that deal with a high security project. 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 ve companies working on some part. In how many ways can the contracts be awarded so that every company is involved? This is simply a matter of counting the total surjections from the set of contracts to the set of companies. i.e. it is S (8, 5) = 126 000,

You might also like