Slide 3 - predicates

advertisement
Chapter 2, Predicate Logic
CMSC 250
1
Definitions



Subject / predicate
John / went to the store.
The sky / is blue.
Propositional logic- uses statements
Predicate logic or calculus- uses predicates
– predicates must be applied to a subject in order to be true or
false

P(x)
– means this predicate represented by P
– applied to the object represented by x
CMSC 250
2
Quantification






x
There exists an x
x
For all x's
Domain- the set where these subjects come from
(x) [P(x)] there exists an x for which predicate p is true
(x) [P(x)] for all x, predicate p is true
Notation:
– x  Z
– x  R
CMSC 250
there exists an x in the integers
for all x's in the reals
3
Predicate translation

A student of mine is wearing a blue shirt.
– Domain: all people P
– Quantification: There is at least one
– Predicates: "wearing a blue shirt" and "is my student"
Let B(x) represent "x is wearing a blue shirt"
Let S(x) represent "x is my student"
x  P such that B(x) ^ S(x)

All good students are in class.
– Domain: all people P
– Quantification: All of them
– Predicates: "are in class" and "is a good student"
Let C(x) represent "x is in class"
Let G(x) represent “x is a good student"
x  P such that G(x)  C(x)
CMSC 250
4
Establishing truth and falsity




CMSC 250
To show an existentially quantified statement () is
true, find an example.
One way to show an existentially quantified statement
is false is to show it's false for every member of the
domain.
To show a universally quantified statement () is
false, find a counterexample.
One way to show a universally quantified statement is
true is to show it's true for every member of the
domain.
5
Negation of quantified statements

(there is a cat which can fly) 
–
–
–
–
–

some cats can’t fly?
only some cats can fly?
cats can only fly sometimes?
all cats can’t fly?
watch me throw this cat out the window…
Let F(x) represent the predicate "x can fly"
~ (x  cats) [F(x)] 
(x  cats) [~F(x)]
CMSC 250
6
Negation of quantified statements

(everybody likes me) 
– nobody likes me?
– everybody doesn’t like me?
– somebody doesn’t like me?

Let L(x) represent the predicate "x likes me"
~(x  people) [L(x)] 
(x  people) [~L(x)]
CMSC 250
7
Discrete Structures
CMSC 250
Lecture 9
February 15, 2008
CMSC 250
8
Vacuous cases (for universally quantified
statements)



All even prime numbers which are greater than or equal
to 10 are the sum of two squares.
All students in this class who are ten feet tall have
green hair.
Are these true or false? How would we show they’re
true or false?
CMSC 250
9
Universal conditional statements and variants





A universal conditional statement: (x  D) [P(x)  Q(x)]
Its contrapositive:
(x  D) [~Q(x)  ~P(x)]
Its converse:
(x  D) [Q(x)  P(x)]
Its inverse:
(x  D) [~P(x)  ~Q(x)]
Also applies to existentially quantified conditional
statements
CMSC 250
10
Multiple quantification

Let C = {all chairs} and P = {all people},
and S(c,p) represent “person p is sitting in chair c "

(p  P) (c  C) [S(c,p)]
(c  C) (p  P) [S(c,p)]



(p  P) (c  C) [S(c,p)]
(c  C) (p  P) [S(c,p)]
CMSC 250
11
Order of mixed quantifiers




CMSC 250
 and  are different!
Example- domain N- the following do not mean the
same thing!
(x) (y) [y > x]
(y) (x) [y > x]
12
Mixed multiple quantification variations

Let C = {all chairs} and P = {all people},
and S(c,p) represent “person p is sitting in chair c"

(c  C) (p  P) [S(c,p)]
(p  P) (c  C) [S(c,p)]
(p  P) (c  C) [S(c,p)]
(c  C) (p  P) [S(c,p)]



CMSC 250
13
Negations of multiply quantified statements

CMSC 250
Let P= {all people}, and C= {all cats}, and L(p,c)
represent “person p likes cat c"
~((p  P) (c  C) [L(p,c)]) 
(p  P) (c  C) [~L(p,c)]
14
Other variations


Let S be the set of all students and C be the set of all
colleges, and A(s,c) represent "student s attends college
c".
Exactly one student attends college:
(s  S) ( c C) [A(s,c)  ~((p  S) (u  C) [p  s  A(p,u)])]
(s  S) (c  C) [A(s,c)  ((p  S) (u  C) [p = s  ~A(p,u)])]

At most one student attends college:
(s,p  S) (c,u  C) [(A(s,c)  A(p,u))  p = s]

At least two students attend college:
(s,p  S) (c,u  C) [A(s,c)  A(p,u)  p  s]
CMSC 250
15
Discrete Structures
CMSC 250
Lecture 10
February 18, 2008
CMSC 250
16
Establishing truth and falsity with multiple
quantification

Recall:
– to show x is true, find an example.
– to show x is false, find a counterexample.

Let the domain be the natural numbers
(x)( y)( z)[ x  y  z ]
2
2
(x)( y)( z )[ x  y  z ]
(x)( y)( z)[ y even  z even  x  y  z]
2
CMSC 250
2
17
Set (Euler) diagrams

Circles are used to indicate “truth sets" for a predicate
– where the predicate applied to an object is true



A dot is used to indicate a specific instance
A completely contained circle indicates a "for all" relationship
An overlapping circle indicates "some"
All college students are brilliant.
Some poets are unsuccessful.
All brilliant people are scientists.
Some athletes are unsuccessful.
All college students are scientists. Some poets are athletes.
OR
U
S
CMSC 250
B
C
P
U
P
A
A
18
Interpretations

Assign meanings to predicates and domains to
quantified variables
(x)( y)[x  y  (z)[x  z  y  z 
(L(x, y)  L(x, z)  L(z, y))]]




CMSC 250
One interpretation: domain N, L is <
Another interpretation: domain Q, L is <
Another interpretation: domain N, L is / (L(x, y) means
"x can be divided by y evenly")
An interpretation is analogous to a row of a truth table
(except there are an infinite number of them).
19
Rules of inference for
quantified statements
Universal Modus Ponens
Universal Modus Tollens
(x  D) [P(x)  Q(x)]
aD
P(a)
 Q(a)
(x  D) [P(x)  Q(x)]
aD
~Q(a)
 ~P(a)
Universal instantiation
Existential generalization
(x  D) [P(x)]
aD
 P(a)
P(a)
aD
 (x  D) [P(x)]
CMSC 250
20
Rules that don't exist or need more
clarification

Existential Modus Ponens doesn't exist
Existential Modus Tollens doesn't exist

Universal generalization: P(a), (x  D) [P(x)]

– only if a is completely arbitrary in the domain

Existential instantiation: (x  D) [P(x)], P(a)
– only if a is completely arbitrary in the domain
CMSC 250
21
Errors in deduction

Converse error:
(x  D) [P(x)  Q(x)]
Q(a)
 P(a)

Called asserting the
consequence
CMSC 250

Inverse error:
(x  D) [P(x)  Q(x)]
~P(a)
 ~Q(a)

Called denying the
hypothesis
22
Easy formal direct proofs by deduction
P1: (x  D) [P(x)  Q(x)]
P2: ~Q(a), where a  D
 (x  D) [~P(x)]
P1: (x  D) [P(x)  Q(x)]
P2: (x  D) [R(x)  ~P(x)]
P3: P(b), where b  D

CMSC 250
Q(b) ^ ~R(b)
23
More formal direct proofs by deduction
P1: (x  D) [P(x)  Q(x)]
P2: (x  D) [~P(x)  R(x)]
P3: P(b), where b  D

(x  D) [Q(x) ^ R(x)]
P1: (x  D) [P(x)  Q(x)]
P2: (y  D) [~P(y)  R(y)]
P3: (z  D) [~Q(z)]

CMSC 250
(x  D) [R(x)]
24
Discrete Structures
CMSC 250
Lecture 11
February 20, 2008
CMSC 250
25
One more proof
P1: (x  D) [(A(x)  B(x))  (M(x)  N(x))]
P2: (y  D) [A(y)  ~N(y)]


(z  D) [M(z)  B(z)]
Note: (x  D) [A(x)  ~N(x)] 
(y  D) [A(y)  ~N(y)] 
(z  D) [A(z)  ~N(z)] etc.

Also, the quantified variables are completely independent
in different quantified predicates like (y  D) [A(y)] and
(y  D) [B(y)  Q(y)]
CMSC 250
26
Example using predicate logic

Once we define operations or concepts we can use
them in defining other operations.

Consider only , , =, and the domain N

Define DIV(x,y): (z)[x  z = y]

Now we can define PRIME(y):
(x)[DIV(x,y)  x = 1  x = y]

Also ODD(y): (x)[y = 2  x + 1]
CMSC 250
27
Example, continued

Using these, define SUM3P(x):
(y1 , y 2 , y3 )
[PRIME(y 1 )  PRIME(y 2 )  PRIME(y 3 )  x  y1  y 2  y3 ]

CMSC 250
Now we can state the following:
(n)(x)[x  n  ODD(x)  SUM3P(x)]
28
Another application- describing properties
of programs

Motivation:
– finding bugs
– proofs of correctness
– specifying programs- clarifying goals before coding A
precondition is a property which must be true before some
piece of code is executed, otherwise it won’t work correctly


CMSC 250
A postcondition is a property which will be true after
some piece of code executes (assuming the
precondition was true beforehand)
An invariant is a property which is true at every
iteration of a loop (at the top of the loop)
29
Example
i= 0;
// precondition: true (meaning there are no
// requirements or conditions which must be
// satisfied in order for the code to work correctly)
while (i < n && arr[i] < x)
// invariant: 0  i < n 
//
(j, 0  j < i)[arr[j] < x]
i++;
// postcondition: n < 0 
//
(0  i  n 
//
(j, 0  j < i)[arr[j] < x] 
//
i < n  arr[i]  x)
CMSC 250
30
Discrete Structures
CMSC 250
Lecture 12
February 22, 2008
CMSC 250
31
Another example
i= 1;
max= arr[0];
// precondition: true
while (i < n) {
// invariant: 1  i < n 
//
(j, 0  j <
//
(k, 0  k <
if (arr[i] > max)
max= arr[i];
i++;
}
// postcondition: n < 1 
//
(i = n 
//
(j, 0  j
//
(k, 0  k
CMSC 250
i)[arr[j] = max] 
i)[arr[k]  max]
< n)[arr[j] = max] 
< n)[arr[k]  max])
32
A further example
i= 0;
found= 0;
// precondition: true
while (i < n && !found)
// invariant: found = 0  0  i < n 
//
(j, 0  j < i)[arr[j]  x]
if (arr[i] == x)
found= 1;
else i++;
// postcondition:
//
n < 0 
//
((found = 0  i = n 
//
(j, 0  j < i)[arr[j]  x])) 
//
(found = 1  0  i < n  arr[i] = x 
//
(j, 0  j < i)[arr[j]  x]]))
CMSC 250
33
One more example

If we need to refer to the initial value of a variable, the
convention is to use its name with a prime symbol
i= 0;
// precondition: n  0
while (i < n – 1) {
// invariant: i < n – 1 
//
(j, 0 ≤ j < i)[arr[j] = arr'[j + 1]] 
//
(j, i ≤ j < n)[arr[j] = arr'[j]]
arr[i]= arr[i + 1];
i++;
}
// postcondition:
//
n < 0 
//
(i = n – 1 
//
(j, 0 ≤ j < i)[arr[j] = arr'[j + 1]] 
//
[arr[n - 1] = arr'[n - 1]])
CMSC 250
34
Download