Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Discrete math with computers_3

.pdf
Скачиваний:
87
Добавлен:
16.03.2016
Размер:
2.29 Mб
Скачать

8.5. SUMMARY

203

 

Table 8.1: Summary of Set Notation

 

 

 

 

 

Elements

a, b, c, . . .

 

 

Sets

A, B, C, . . .

 

 

Empty set

{ }, φ

 

 

Enumerated set

{e1, e2, . . .}

 

 

Set comprehension

{x | · · · }

 

 

Cardinality

| A |

 

 

Member

x A

 

 

Not member

x A

 

 

Subset

A B

 

 

Not subset

A B

 

 

Proper subset

A B

 

 

Not proper subset

A B

 

 

Union

A B

 

 

Intersection

A ∩ B

 

 

Set di erence

A − B

 

 

Cross product

A × B

 

1.

x (A B)

{ Premise }

2.

x U ¬(x A B)

{ Def. comp }

3.

x U ¬(x A x B)

{ Def. }

4.

x U (¬(x A) ¬(x B))

{ DeMorgan }

5.

x U x U (¬(x A) ¬(x B))

{ Idemp. of }

6.

(x U ¬(x A)) (x U ¬(x B))

{ Comm. of }

7.

x U − A x U − B

{ Def. of di . }

8.

x (U − A) (U − B)

{ Def. }

9.

(x A ∩ B )

{ Def. of comp. }

10.

x. x (A B) ↔ x (A ∩ B )

{ introduction }

11.(A B) = A ∩ B

8.5Summary

The notations used in set theory are listed in Table 8.1, and the laws for reasoning about sets are given in Table 8.2.

204

CHAPTER 8. SET THEORY

Table 8.2: Set Laws

Idempotent

A = A A

A = A ∩ A

Domination

A U = U

A ∩ =

Identity

A = A

A ∩ U = A

Double complement

A = A

DeMorgan’s laws

(A B) = A ∩ B (A ∩ B) = A B

Commutative laws

A B = B A

A ∩ B = B ∩ A

Associative laws

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

Distributive laws

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

Absorption laws

A (A ∩ B) = A

A ∩ (A B) = A

8.6. SUGGESTIONS FOR FURTHER READING

205

8.6Suggestions for Further Reading

Mathematics from the Birth of Numbers, by Gullberg [16], is an interesting general survey of mathematics. It covers many of the topics in this book, including an excellent survey of elementary set theory.

Classic Set Theory [14], by Derek Goldrei, is a self-study textbook telling the full story of set theory, including construction of the real numbers, the Axiom of Choice, cardinal and ordinal numbers, and more. This book is challenging, but it conveys the sense of excitement that surrounded set theory as it was developed.

8.7Review Exercises

Exercise 13. For the following questions, give a proof using set laws, or find

acounterexample.

(a)(A B) ∩ C = A ∩ (B C)

(b)A − (B C) = A ∩ (B C)

(c)(A ∩ B) (A ∩ B ) = A

(d)A (B − A) = A B

(e)A − B = B − A

(f) A ∩ (B − C) = (A ∩ B) (A ∩ C)

(g)A − (B C) = (A − B) (A − C)

(h)A ∩ (A B) = A ∩ B

(i)(A − B ) (A − C ) = A ∩ (B ∩ C)

Exercise 14. The function

smaller :: Ord a => a -> [a] -> Bool

takes a value and a list of values and returns True if the value is smaller than the first element in the list. Using this function, write a function that takes a set and returns its powerset. Use foldr.

Exercise 15. Prove that (A B) = ((A A ) ∩ A ) ((B B ) ∩ B ).

Exercise 16. Using a list comprehension, write a function that takes two sets and returns True if the first is a subset of the other.

Exercise 17. What is wrong with this definition of diff, a function that takes two sets and returns their di erence?

diff :: Eq a => [a] -> [a] -> [a]

diff set1 set2 = [e | e <- set2, not (elem e set1)]

206

CHAPTER 8. SET THEORY

Exercise 18. What is wrong with this definition of intersection, a function that takes two sets and returns their intersection?

intersection :: [a] -> [a] -> [a]

intersection set1 set2 = [e | e <- set1, e <- set2]

Exercise 19. Write a function using a list comprehension that takes two sets and returns their union.

Exercise 20. Is it ever the case that A (B − C) = B?

Exercise 21. Give an example in which (A C) (B C) = .

Exercise 22. Prove the commutative law of set-intersection, A ∩ B = B ∩ A.

Exercise 23. Express the commutative law of set-intersection in terms of the set operations and Boolean operations defined in the Stdm module.

Exercise 24. Prove the associative law of set-union, (A B) C = A (B C).

Exercise 25. Prove that the di erence between two sets is the intersection of

one with the complement of the other, which can be written as

A − B = A ∩ B .

Exercise 26. Prove that union distributes over intersection,

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

Exercise 27. Prove DeMorgan’s law for set intersection, (A ∩ B) = A B .

Chapter 9

Inductively Defined Sets

In this chapter, we explore the construction of sets using induction. To understand why induction is useful, consider the problem of defining a set. The simplest method is to define a set by naming each of its elements, one by one. This is called enumeration. It works only for finite sets and is impractical for large sets. Another approach is to use ellipses (‘. . .’) to indicate that the set continues, but this is imprecise, and so can be ambiguous. For example, what is meant by {1, 2, 3, . . .}? Is the next element 4 or 5? Even if you think the answer is obvious, how do you know everyone else will consider the same thing to be obvious? If we are enumerating the positive integers, the next element is 4, but if we are adding the two previous numbers in the series, it is 5.

9.1The Idea Behind Induction

Induction is rather like a mathematical ‘program’ that calculates a proof when needed. The proof asserts that an element is a member of the set defined by induction. For example, here are two propositions:

0 S

n S → n + 1 S

Together, they let us show that any natural number is in set S. To see how they do this, consider an example: we show that 2 is an element of set S. Using the propositions above, we can construct a chain that looks like this:

0 S

0 S → 1 S

1 S → 2 S

We then use the first assertion and Modus Ponens to deduce that 1 is in set S, and from that, using Modus Ponens, we deduce that 2 is in set S. In fact,

207

208 CHAPTER 9. INDUCTIVELY DEFINED SETS

we can use the two propositions to build a chain that is as long as needed to reach any natural number.

Of course, if any of the links in the chain were missing, for example the proposition 0 S → 1 S, then we could not reach the number required. This is because we could not use Modus Ponens to get to the next link.

When we use an inductive definition to show that a set contains a given value v, we enumerate, or count, the values that must first be shown to be in the set before v. These values form a sequence, which is a set with an ordering. Computers can enumerate elements of sets in the order in which they are generated from a description of the set. We can use a computer to calculate a sequence that represents an infinite set, although we will only see a finite prefix of the entire sequence.

Let’s implement what we have seen using Haskell. A set of numbers can be represented by a list; for example, the set with the numbers 1,2, and 3 is [1,2,3], and the empty set is [].

How do we implement the implications? An implication of the form 1 s → 2 s can be implemented as a function that takes 1 and returns the next element, 2. If it is applied to anything other than 1, then an error message is returned:

imp1 :: Integer -> Integer imp1 1 = 2

imp1 other = error "premise does not match"

We can implement a chain using function application. The argument of the function imp1 is an element of s. If that element matches the pattern of imp1, then imp1 can be applied to it and produce a new element of s. This is just like what we do when deciding whether we can use Modus Ponens: we match the premise of the implication with elements of the set; if there is a match, then we can use Modus Ponens, otherwise the match fails and we cannot. For example, consider the following assertions:

1 S

1 S → 2 S

2 S → 3 S

This can be implemented by the following Haskell definitions:

imp1 :: Integer -> Integer imp1 1 = 2

imp1 x = error "premise does not match"

imp2 :: Integer -> Integer imp2 2 = 3

imp2 x = error "premise does not match"

9.1. THE IDEA BEHIND INDUCTION

209

s :: [Integer]

s = [1, imp1 (s !! 0), imp2 (s !! 1)]

The function application s!!0 returns the first element of s, indexing from 0; the result is 1. The function impl1 is applied to this. Since the argument matches the pattern, the application succeeds, adding 2 to s. Then the function impl2 is applied to 2. The argument matches the pattern, so the application succeeds, adding 3 to s. The value of s is [1,2,3].

There is a di erence between matching the premise of the implication with all of the elements of the set and applying imp1 to the most recently added member of s. However, in the form of induction that we are studying, it doesn’t matter. The only value that could possibly match the premise is the one generated by the previous implication. But consider now this set of assertions:

1 S

2 S → 3 S

This is implemented as:

imp1 :: Integer -> Integer imp1 2 = 3

imp1 x = error "premise does not match"

s :: [Integer]

s = [1, imp1 (s !! 0)]

In this case, we cannot use Modus Ponens to conclude that 3 is in the list, because nothing states that 2 is in it.

Exercise 1. Is the following a chain? You can test your conclusions by evaluating s in each case.

imp1 :: Integer -> Integer imp1 1 = 2

imp1 x = error "imp1: premise does not apply"

imp2 :: Integer -> Integer imp2 2 = 3

imp2 x = error "imp2: premise does not apply"

imp3 :: Integer -> Integer imp3 3 = 4

imp3 x = error "imp3: premise does not apply" s :: [Integer]

s = [1, imp1 (s !! 0), imp2 (s !! 1), imp3 (s !! 2)]

Exercise 2. Is the following a chain?

210 CHAPTER 9. INDUCTIVELY DEFINED SETS

imp1 :: Integer -> Integer imp1 1 = 2

imp1 x = error "imp1: premise does not apply"

imp2 :: Integer -> Integer imp2 3 = 4

imp2 x = error "imp2: premise does not apply"

s :: [Integer]

s = [0, imp1 (s !! 0), imp2 (s !! 1)]

Exercise 3. Is the following a chain?

imp1 :: Integer -> Integer imp1 0 = 1

imp1 x = error "imp1: premise does not apply"

imp2 :: Integer -> Integer imp2 3 = 4

imp2 x = error "imp2: premise does not apply"

s :: [Integer]

s = [0, imp1 (s !! 0), imp2 (s !! 1)]

Exercise 4. Is the following a chain?

imp1 :: Integer -> Integer imp1 0 = 1

imp1 x = error "imp1: premise does not apply"

imp2 :: Integer -> Integer imp2 1 = 2

imp2 x = error "imp2: premise does not apply"

s :: [Integer]

s = [0, imp1 (s !! 1), imp2 (s !! 0)]

9.1.1The Induction Rule

Recall the two propositions we used in the first section:

0 S

n S → n + 1 S

The first one is called the base case, and the second is called the induction case, or the induction rule. It is the induction case that generates the links of the chain which will allow us to reach any number in the set being defined.

9.1. THE IDEA BEHIND INDUCTION

211

So far, the induction has had a fixed form because we were defining a particular set. However, we could have a rule

n S → n + 2 S.

Together with the base case 1 S, this would define the odd natural numbers. Alternatively, our induction rule might be

n S → n 5 S.

Together with the base case, this would define the set of powers of 5.

As we will see, it can sometimes be hard to construct the correct rule, and it is necessary to debug rules to get them right.

Suppose we have a set defined by the following assertions:

0 s

x s → x + 1 s

First, we want to find out whether 2 is in the set, and will use the computer to help. (Of course, we could solve this by hand, but if the induction rule is complicated, or if we want to find out whether 1,000,000 is in the set, software tools are invaluable.) We can implement the induction rule as the increment function:

increment :: Integer -> Integer increment x = x + 1

s :: [Integer]

s = [0, increment (s !! 0), increment (s !! 1)]

We can load this definition and evaluate s; the last element of s is 2.

Now suppose that we want to know whether 50 is in the set. It would be very tedious to write out each element as we have been doing. The same function is applied to each element of s, so we can have the following definition of s instead:

s :: [Integer]

s = 0 : map increment s

This style of programming is known as data recursion. The function map proceeds down s, creating each value it needs and then using it. We can then get at the fiftieth element by typing s!!50.

Now we have a new format for implementing inductive definitions. We first specify the induction rule, then recursively define a list in which the base case appears first, and then the rule is mapped down the list.

Exercise 5. Given the base case 0 n and the induction rule x n → x + 1 n, fix the following calculation so that 3 is in set n:

212

 

CHAPTER 9. INDUCTIVELY DEFINED SETS

 

fun :: Integer -> Integer

 

fun x = x - 1

 

n

:: [Integer]

 

n

= 0 : map fun n

Exercise 6. Use the following definitions, determine whether 4 is in set s, given 1 s and the induction rule x s → x + 2 s.

fun :: Integer -> Integer fun x = x + 2

s :: [Integer]

s = 1 : map fun s

Exercise 7. Fix this calculation of the positive integers:

fun :: Integer -> Integer fun x = 0

p :: [Integer]

p = 0 : map fun p

Exercise 8. Fix this calculation of the positive multiples of 3:

fun :: Integer -> Integer fun x = x * 3

p :: [Integer] p = map fun p

9.2How to Define a Set Using Induction

We have seen that an inductive set definition has a base case and an induction rule (or induction case). There is one more clause that needs to be specified in an inductive set definition. Suppose that we have defined a set S by saying that the numbers 1, 2, and 3 are in S. How do we know that something else isn’t also in S? If we don’t say explicitly that nothing else is in S, then the specification could be satisfied by lots of di erent sets. It could be the set {1, 2, 4.5, −78, 3}, for example.

We want to exclude all elements that aren’t introduced by the base case, or instantiations of the induction case, so we include a clause (called the extremal clause) in a set definition that states Nothing is an element of the set unless it can be constructed by a finite number of uses of the first two clauses.

To summarise, an inductive definition of a set consists of three parts: a base case, an induction case, and an extremal clause:

Соседние файлы в предмете Дискретная математика