Vous êtes sur la page 1sur 31

# Lecture 2

Predicate Logic

Formal Methods

## Now we introduce another part of our logical

language.
The language of propositions allows us to
But that does not allow us to describe such as
Every cloud has a silver lining
These are known as universal statements
because it describe properties that must be
satisfied by every object in some universe of
discourse.

## Dr. Nazir A. Zafar

Formal Methods

Predicate Logic

Example 3.1:
The following are examples of universal
statements:
1. Any student interested doing research with
Dr. Zafar must register FM course.
2. Nobody knows the trouble I seen.
3. Jim doesn't know anybody who can sign his
bail application.

Formal Methods

Predicate Logic

## Sometimes we wish to state that at least one

thing has a particular property, without
necessarily knowing which thing it is.
This leads to an existential statement.

Example 3.2
The following are examples of existential
statements:
1. I heard it from one of your friends.
2. A mad dog has bitten Andy.
3. Some people prefer logic.
Dr. Nazir A. Zafar

Formal Methods

Predicate Logic

## To formalize such statements, we require a

language that reveals the internal structure of
propositional statements
A language that allows us to take and apply the
objects without proper taking names of it.
The language we require is the language of
predicate calculus
Also called predicate logic or first order logic
Second order logic is extension of first order logic
Higher order logic is extension of the second
order logic

Formal Methods

Predicate Logic

## Predicate is a statement with a place for an object

When these places are filled, our predicates
become statements about the objects that fill them
Example:
The statement _ > 5 is a predicate, no body
knows it is true or false
But 0 > 5, a proposition which is false
However, we could also choose to put an object
variable in the empty place above. And still it will
remain predicate e.g. x > 5,
Dr. Nazir A. Zafar

Formal Methods

## Predicate and Propositions

Example:
Construct a predicate and a proposition from _ > 5 .
Predicate:
The statement _ > 5 , _ is filled by x and the
resultant, x > 5 , is called predicate
Note:
The statement was filled but still not a proposition.
This is because we cannot say whether it is true
or false without knowing the value of x.
Proposition:
One of the ways to make a proposition out of x >
5 is as
x x > 5 (this is proposition)
Dr. Nazir A. Zafar

Formal Methods

Predicate Logic
Meanings of: x x > 5 (True)
Explanation: Let = {0, 1, 2, 3, . . .}
The above statement can be written as
0 > 5 1 > 5 2 > 5 3 > 5 4 > 5 .
Meanings of: x x > 5 (False)
Explanation:
This statement can be written as
0 > 5 1 > 5 2 > 5 3 > 5 4 > 5 .
Dr. Nazir A. Zafar

Formal Methods

## Formalization using Existential Quantifier

Example 3.1 (1) :
Formalize the statement
I heard it from one of your friends.
Formalization:
Notations:
Friends stands for set of all your friends,
told (x, y) means x has told y.
Formal Statement:
f Friends told (f, me)
Dr. Nazir A. Zafar

Formal Methods

## Formalization using Existential Quantifier

Example 3.1 (2) :
Formalize the statement
A mad dog has bitten Andy
Formalization:
Notations:
bit (x, y) means x has bitten y.
Formal Statement:
Dr. Nazir A. Zafar

Formal Methods

## Formalization using Existential Quantifier

Example 3.1 (3) :
Formalize the statement
Some people prefer logic.
Formalization:
Notations:
Person stands for the set of all people, and
PL(x) means x prefers logic.
Formal Statement:
p Person PL(p)
Dr. Nazir A. Zafar

Formal Methods

## Formalization using For all Quantifier

Example 3.1 (1):
Formalize following statements
1. Any student interested doing research with Dr. Zafar must
register FM course.
Formalization:
Notations:
Student: set of all students doing research with Dr. Zafar
Register (x) means x must register the FM Course
Formal Statement:
s Student Register (s)

Formal Methods

## Formalization using For all Quantifier

Example 3.1 (1): Modified
Formalize following statements
1. Any student interested doing research with Dr. Zafar must
register FM course.
Formalization:
Notations:
Student: set of all MS students
fm-group: set of students doing research with Dr. Zafar,
Register (x) means that x must register the FM Course
Formal Statement:
s Student | s fm-group Register (s)
Dr. Nazir A. Zafar

Formal Methods

## Formalization using For all Quantifier

Example 3.1 (2):
Formalize following statements
1. Nobody knows the trouble I have seen.
Formalization:
Notations:
Person stands for set of all people,
K(x) means that x knows the trouble I have seen
Formal Statement:
p Person K(p)
What is negation of above statement?
Dr. Nazir A. Zafar

Formal Methods

## Formalization using For all Quantifier

Example 3.1 (3):
Jim doesnt know anybody who can sign his bail
application.

Notations:
P stands for set of all people,
K(x, y) means x knows y
S(x, y) means x can sign ys application for bail
Formalization:
p P K(Jim, p) S(p, Jim)
Dr. Nazir A. Zafar

Formal Methods

## Example 3.1 (3): Validity Checking

Jim doesnt know anybody who can sign his bail appl.
Notations:
Set of all persons = P = {p1, p2, p3, p4}
Set of persons known to Jim = P1 = {p1, p2}
Set of persons not known to Jim = P2 = {p3, p4}
K(x, y) mean that x knows y.
S(x, y) mean that x can sign ys bail appl.
K(Jim, p1) = true, K(Jim, p2) = true,
K(Jim, p3) = false, K(Jim, p4) = false,
S(p1, Jim) = false, K(p2, Jim) = false,
S(p3, Jim) = false/true, K(p4, Jim) = false/true
Dr. Nazir A. Zafar

Formal Methods

Validity Checking
Predicate Logic
p P K(Jim, p) S(p, Jim)
Propositional Logic
[K(Jim, p1) S(p1, Jim)] [K(Jim, p2) S(p2,
Jim)] [K(Jim, p3) S(p3, Jim)] [K(Jim, p4)
S(p4, Jim)]
[t t] [t t] [f t/f] [t t/f]
tttt
t, a tautology

## Dr. Nazir A. Zafar

Formal Methods

Algorithm
Sign-Appl (P, P1, Jim)
if P = [ ] then
true
else
for i = 1 to Length (P)
if K(Jim, P[i]) then
S(P[i], Jim)
endif
endfor

## Dr. Nazir A. Zafar

Formal Methods

Algorithm
P1 = known to Jim;
Jim: P;
known = {(Jim, p1), (Jim, p2)}
K : P x P Bool
K (Jim, x) ==
if (Jim, x) known then
true
else false

## Dr. Nazir A. Zafar

Formal Methods

Algorithm
P1 = known to Jim;
Jim: P;
known = {(Jim, p1), (Jim, p2)}
S : P x P Bool
S (x, Jim) ==
if x P1 then
false
endif
pre x Jim
Dr. Nazir A. Zafar

Formal Methods

## Quantifiers and Declaration

In the Z notation, two kinds of quantified
expressions have a similar syntax
Qx:a|pq
where
Q is the quantifier;
x is the bound variable;
a is the range of x;
p is the constraint; and
q is the predicate.
Dr. Nazir A. Zafar

Formal Methods

Useful Equivalences
1. ( x : a | p q) ( x : a p q)
2. ( x : a | p q) ( x : a p q)

Pronunciation:
x : a | p q is pronounced as there exists an x
in a satisfying p, such that q.
x : a | p q is pronounced for all x in a
satisfying p, q holds

## Dr. Nazir A. Zafar

Formal Methods

Scope of Variable
Example: Define scope of the variable x and y
( x : a | p q r) s t
y : a | p q ( y : b | r s t) u v
Scopes

(x : a | p q r )

scope of first x

y : a | p q (y : b | r s t ) u v

scope of second y

scope of first y
Dr. Nazir A. Zafar

Formal Methods

## Independent Variable has no Importance

Example 3.7
Consider the following quantified expression,
which states that every natural number x is
greater than or equal to zero
Formal Description:
num : N num 0
The choice of num as variable is not important;
the following expression has the same meaning
nat : N nat 0
Dr. Nazir A. Zafar

Formal Methods

## Dependant Variable has Importance

Example 3.8:
Consider the following quantified expression,
which states that there is some natural number
max such that every natural number num must
be less than or equal to max
max : N ( num : N num max)
This statement is false.
By changing the name of the universal quantifier
variable from num to max, results confusion
max : N ( max : N max max)
This statement is true; the meaning has changed.
Dr. Nazir A. Zafar

Formal Methods

## Bound Variable as a Range Variable

Example 3.10:
In the expression below, the first bound variable
is used as the range of the second:

a : b c : a p
In this case, it would make no sense to merge
the two quantifications.

Formal Methods

## Free Occurrences of a Variable

Example 3.11: In the expression below, there
is a single free occurrence of variable z
x : N z x
Example 3.12: There are both free and bound
occurrences of variable x in expression below

x = 3 x : N 0 x
Free Occurrence
Bound Occurrence
Note: Occurrence of x adjacent to quantifier is
neither free nor bound;
Dr. Nazir A. Zafar

Formal Methods

Substitution

## If we wish to change the subject of the statement

from x to y, we must replace each free
occurrence of x in p with an occurrence of y. This
process is called substitution.
We write p [y / x] to denote the predicate that
results from substituting y for each free
occurrence of x in predicate p
The expression y need not be another type
variable. it can be any expression whose
possible values match those with x.

## Dr. Nazir A. Zafar

Formal Methods

Substitution
Example 3.13
1. (x y + 2) [0 / x]
0 y+2
2. ( x : N x y + 2) [0 / x]
( x : N x y + 2)
3. ( x : N x y + 2) [5 / y]
( x : N x 5 + 2)

## Dr. Nazir A. Zafar

Formal Methods

Substitution
Example 3.14
1. (x y + 2) [0 / x] [5 / y]
0 y + 2 [5 / y]
0 5+2
2. (x y + 2) [y / x] [5 / y]
(y y + 2) [5 / y]
5 5 + 2)

## Dr. Nazir A. Zafar

Formal Methods

Substitution
Example 3.15
1. (x y + 2) [y, 5 / x, y]
y 5+2

Parallel

2. (x y + 2) [y / x] [5 / y]

Sequential

(y y + 2)
5 5 + 2)
Dr. Nazir A. Zafar

Formal Methods