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

Discrete math with computers_3

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

C.7. PREDICATE LOGIC

411

C.7 Predicate Logic

1.

F (1) F (2) F (3)

 

 

(a)

 

 

(b)

F (1) F (2) F (3)

G(2, 3)

(c)

G(2, 1)

G(2, 2)

G(1, 1)

G(1, 2)

 

G(1, 3)

 

G(3, 1)

G(3, 2)

G(3, 3)

 

 

 

 

 

2.

F (1, 5) F (1, 6)

F (2, 5) F (2, 6)

F (3, 5) F (3, 6)

F (4, 5) F (4, 6)

3.

There is an even number.

x. E(x)

Every number is either even or odd.

x. (E(x) O(x))

No number is both even and odd.

x. ¬(E(x) O(x))

The sum of two odd numbers is even.

x. y. O(x) O(y) → E(x + y)

The sum of an odd number and an even number is odd.

x. y. E(x) O(y) → O(x + y)

4.

Chickens are birds.

x. C(x) → B(x)

Some doves can fly.

x. D(x) F (x)

Pigs are not birds.

x. P (x) → ¬B(x)

Some birds can fly, and some can’t.

x. B(x) F (x) x. B(x) ¬F (x)

An animal needs wings in order to fly.

x. (¬W (x) → ¬F (x))

412

APPENDIX C. SOLUTIONS TO SELECTED EXERCISES

 

If a chicken can fly, then pigs have wings.

 

x. C(x) F (x)

→ x. P (x) → W (x)

Chickens have more feathers than pigs do.

x. y. (C(x) P (y)) → M (x, y)

An animal with more feathers than any chicken can fly.

x. A(x) ( y. (C(y) M (x, y))) → F (x)

5.

x. ( y. wantsToDanceWith (x, y))

Everybody has someone they want to dance with.

x. ( y. wantsToPhone (y, x))

There is someone whom everybody wants to call.

x. (tired (x) y. helpsMoveHouse (x, y))

There is a person who is tired, and who helps everyone to move house.

6.

forall [1,2,3] (==2)

=1==2 /\ 2==2 /\ 3==2

=False /\ True /\ False

=False

forall [1,2,3] (< 4)

=(1 < 4) /\ (2 < 4) /\ (3 < 4)

=True /\ True /\ True

=True

7.

exists [0,1,2] (==2)

=0==2 \/ 1==2 \/ 2==2

=False \/ False \/ True

=True

C.7. PREDICATE LOGIC

413

exists [1,2,3] (> 5)

=(1 > 5) \/ (2 > 5) \/ (3 > 5)

=False \/ False \/ False

=False

8.

1.x.( y.p(x, y))

=x. x = 1 + 1 x = 2 + 1

=(1 = 1 + 1 1 = 2 + 1) (2 = 1 + 1 2 = 2 + 1)

=(False False) (True False)

=False True

=False

2.x.( y.p(x, y))

=x.(x = 1 + 1) (x = 2 + 1)

=(1 = 1 + 1 1 = 2 + 1) (2 = 1 + 1 2 = 2 + 1)

=(False False) (True False)

=False True

=True

3.x.( y.p(x, y))

=x.(x = 1 + 1 x = 2 + 1)

=(1 = 1 + 1 1 = 2 + 1) (2 = 1 + 1 2 = 2 + 1)

=(False False) (True False)

=False False

=False

4.x, y.p(x, y)

=x.(x = 1 + 1 x = 2 + 1)

(1 = 1 + 1 1 = 2 + 1) (2 = 1 + 1 2 = 2 + 1)

=(False False) (True False)

=False False

=False

414

APPENDIX C. SOLUTIONS TO SELECTED EXERCISES

9. The solution is based on showing that for any arbitrary value of x, say p, we can infer G(p); hence we can infer x.G(x).

Theorem 110. x.F (x), x.F (x) → G(x) x.G(x)

Proof.

x.F (x) x.F (x) → G(x)

 

{ E}

 

{ E}

F (p)

F (p) → G(p)

{→E}

G(p)

{ I}

x.G(x)

10.

x. y.F (x, y) y. x.F (x, y)

F (p, q)

{ I}

y.F (p, y) x.F (x, q)

{ E}

x.F (x, q)

{ I}

x. y.F (x, y)

y. x.F (x, y)

{ E}

y. x.F (x, y)

11.

y. x.F (x, y) x. y.F (x, y)

WRONG!

Counterexample:

Let F (x, y) = x == y with U = {1, 2}

y. x.F (x, y)

=y.(1 = y 2 = y)

=(1 = 1 2 = 1) (1 = 2 2 = 2)

=(True False) (False True)

=(True True)

=True

but on the other side:

x. y.F (x, y)

=x.(x = 1 x = 2)

=(1 = 1 1 = 2) (2 = 1 2 = 2)

=(True False) (False True)

C.7. PREDICATE LOGIC

415

=False False

=False

The equations do not return the same result, therefore the sequent is not correct.

12.

Theorem 111. x.(F (x) G(x)) ( x.F (x)) ( x.G(x))

Proof.

 

x.F (x) G(x)

E

 

 

 

x.F (x) G(x)

E

 

 

 

 

 

 

{

 

}

 

 

 

 

 

{

 

}

 

 

F (p) G(p)

 

 

{ EL}

 

F (q) G(q)

 

 

{ ER}

 

 

F (p)

 

 

 

 

G(q)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

{ I}

 

 

 

 

 

 

{ I}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

x.F (x)

 

 

 

 

 

x.G(x)

 

 

 

{ I}

x.F (x) x.G(x)

13. There will be 1000 terms containing F . In general, if the quantifiers are nested k deep, and the universe contains n elements, then the innermost term will occur nk times.

16.

P → x.f (x) x.P → f (x)

P P → x.f (x)

{→E}

x.f (x)

{ E}

f (c)

{→I}

P → f (c){c arbitrary}

{ I}

x.P → f (x)

17.

x.f (x) x.g(x) x.f (x) g(x)

Counterexample:

Let f (x) = x == 1 and g(x) = x == 2 with U = {1, 2}

x.f (x) x.g(x)

=(1 = 1 2 = 1) (1 = 2 2 = 2)

=(True False) (False True)

=False False

416

APPENDIX C. SOLUTIONS TO SELECTED EXERCISES

= False

However, on the other side:

x.f (x) g(x)

(1 = 1 1 = 2) (2 = 1 2 = 2)

=(True False) (False True)

=True True

=True

Thus the law cannot be used as an equation.

x.f (x) g(x) x.f (x) x.g(x)

Counterexample:

Let f (x) = x == 1 and g(x) = x == 2 with U = {1, 2}

x.f (x) g(x)

=(1 = 1 1 = 2) (2 = 1 2 = 2)

=(True False) (False True)

=False False

=False

On the other side:

x.f (x) x.g(x)

=(1 = 1 1 = 2) (1 = 2 2 = 2)

=(True False) (False True)

=True True

=True

Thus the law cannot be used as an equation.

19.

Assume that lists xs and ys are finite lists of type [a] and that xs is of length n.

P (n) (length xs = n)

( z.z xs z ys z (xs ++ ys))

C.8. SET THEORY

417

C.8 Set Theory

13.

(A B) ∩ C

=A ∩ B ∩ C

=A ∩ B ∩ C

=A ∩ (B C)

A − (B C)

=A ∩ (B C)

=A ∩ (B C)

(A ∩ B) (A ∩ B )

=A ∩ (B B )

=A ∩ U

=A

A (B − A)

=A (B ∩ A )

=(A B) (A A )

=(A B) ∩ U

=A B

A − B

=A ∩ B

=B ∩ A

=B ∩ A

=B − A

(A ∩ B) (A ∩ C)

=(A ∩ B) (A ∩ C)

=(A ∩ B) (A C )

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

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

=(A ∩ B ∩ C )

=A ∩ B ∩ C

=A ∩ (B − C)

A − (B C)

=A ∩ (B C)

=A ∩ (B ∩ C )

=A ∩ A ∩ B ∩ C

=(A ∩ B ) (A ∩ C )

=(A − B) (A − C)

418

APPENDIX C. SOLUTIONS TO SELECTED EXERCISES

A ∩ (A B)

=(A ∩ A ) (A ∩ B)

=(A ∩ B)

=A ∩ B

(A − B ) (A − C )

=(A ∩ B ) (A ∩ C )

=(A ∩ B) (A ∩ C)

=A ∩ (B C)

14.

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

smaller x (y:xs) = x < y

powerSet :: (Ord a, Eq a) => [a] -> [[a]] powerSet set = normalizeSet (foldr g [[]] set)

where g x acc =

[x:epset | epset <- acc,

not (elem x epset) && smaller x epset]

++acc

15.(A B) = A ∩ B

=(U − A) (U − B)

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

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

16.

isSubset :: Eq a => [a] -> [a] -> Bool

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

17.The arguments are in the wrong order.

18.The second definition of e shadows the first, so the result is the second set. One way to define it correctly is

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

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

19.

union :: Eq a => [a] -> [a] -> [a] union set1 set2

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

20.Yes, when A B and C A.

21.Both unions contain C, so C must be empty, and A and B must be disjoint. For example, A = {1, 2, 3}, B = {4, 5, 6}, C = .

C.8. SET THEORY

419

22.

A ∩ B

= { defn ∩ } {x|x A x B}

={ commutative } {x|x B x A}

={ defn ∩ }

B ∩ A

23.

A *** B = B *** A

24.

(A B) C

= { defn }

{x |(x A x B) x C}

= { associative }

{x|x A (x B x C)}

= { defn }

A (B C)

25.

A− B

={ double complement } {x|x A x B }

={ defn. − }

{x|x A ¬(x U x B )}

= { defn. complement }

{x|x A ¬(x U ¬(x B ))} = { defn. }

{x|x A ¬(x U ¬(x U x B))}

= { defn. complement }

{x|x A ¬(x U ¬(x U ¬(x B)))} = { defn. }

{x|x A ¬(x U (¬(x U ) (x B)))}

= { DM , double negation }

{x|x A (¬(x U ) ¬(¬(x U ) (x B)))} = { DM }

{x|x A (x U (¬¬(x U ) ¬(x B)))}

= { DM }

{x|x A (x U (x U x B))}

= { double negation, defn. } {x|x A (x U x B)}

420

APPENDIX C. SOLUTIONS TO SELECTED EXERCISES

={ null , defn. } {x|x A x U − B}

={ defn.− }

A∩ B

= { defn. complement, ∩ }

26.

A (B ∩ C)

= { defn ∩, }

{x|x A (x B x C)} = { over }

{x|(x A x B) (x A x C)} = { def . ∩, }

(A B) (A C)

27.

(A ∩ B)

={ defn. complement } {x|x U x (A ∩ B)}

={ defn. , ∩ }

{x|x U ¬(x A x B)} = { DM }

{x|x U (¬(x A) ¬(x B))} = { defn. }

{x|x U (x A x B)} = { over }

{x|(x U x A) (x U x B)}

= { defn. − }

{x|(x U − A) (x U − B)}

= { defn. complement, }

A B

C.9 Inductively Defined Sets

19.The base case appears at the end of the stream, so it cannot be used to start the inductive process of calculating successive elements. So, the stream does not have a printable value.

20.It will never terminate and return the accumulator in which the stream of naturals is constructed.

21.No. The problem is that the stream may present an infinite number of naturals before the one we are interested in can be reached. For example, in [1,3..] ++ [2,4..] all the odd naturals appear before any even number.

22.Given a number n, the set R of roots of n is defined as follows:

n1 R

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