Formal Methods - Lecture 02
-
Author
naeemkashif -
Category
Documents
-
view
21 -
download
2
Embed Size (px)
description
Transcript of Formal Methods - Lecture 02
-
Lecture 2
Predicate Logic
Dr. Nazir A. Zafar Formal Methods
-
Now we introduce another part of our logical language.
The language of propositions allows us to make statements about specific objects
But that does not allow us to describe such as
Chapter 3: Predicate Logic
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
-
Example 3.1:
The following are examples of universal statements:
1. Any student interested doing research with Dr. Zafar must register FM course.
Predicate Logic
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.
Dr. Nazir A. Zafar Formal Methods
-
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
Predicate Logic
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
-
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 Logic
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
Dr. Nazir A. Zafar Formal Methods
-
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
Predicate Logic
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
-
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:
Predicate and Propositions
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
-
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 .
Predicate Logic
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
-
Example 3.1 (1) :
Formalize the statement
I heard it from one of your friends.
Formalization:
Formalization using Existential Quantifier
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
-
Example 3.1 (2) :
Formalize the statement A mad dog has bitten Andy
Formalization:
Formalization using Existential Quantifier
Formalization:
Notations:
MadDog stands for set of all mad dogs,
bit (x, y) means x has bitten y.
Formal Statement:
d MadDog bit (x, Andy)Dr. Nazir A. Zafar Formal Methods
-
Example 3.1 (3) :
Formalize the statement
Some people prefer logic.
Formalization:
Formalization using Existential Quantifier
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
-
Example 3.1 (1):
Formalize following statements
1. Any student interested doing research with Dr. Zafar must register FM course.
Formalization:
Formalization using For all Quantifier
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)
Dr. Nazir A. Zafar Formal Methods
-
Example 3.1 (1): Modified
Formalize following statements
1. Any student interested doing research with Dr. Zafar must register FM course.
Formalization:
Formalization using For all Quantifier
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
-
Example 3.1 (2):
Formalize following statements
1. Nobody knows the trouble I have seen.
Formalization:
Notations:
Person stands for set of all people,
Formalization using For all Quantifier
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
-
Example 3.1 (3):
Jim doesnt know anybody who can sign his bail application.
Notations:
P stands for set of all people,
Formalization using For all Quantifier
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
-
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.
Example 3.1 (3): Validity Checking
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
-
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)
Validity Checking
Jim)] [K(Jim, p3) S(p3, Jim)] [K(Jim, p4) S(p4, Jim)]
[t t] [t t] [f t/f] [t t/f] t t t t t, a tautology
Dr. Nazir A. Zafar Formal Methods
-
Sign-Appl (P, P1, Jim)
if P = [ ] then
true
else
for i = 1 to Length (P)
if K(Jim, P[i]) then
Algorithm
if K(Jim, P[i]) then
S(P[i], Jim)endif
endfor
Dr. Nazir A. Zafar Formal Methods
-
P1 = known to Jim;
Jim: P;
known = {(Jim, p1), (Jim, p2)}
K : P x P BoolK (Jim, x) ==
Algorithm
K (Jim, x) ==
if (Jim, x) known thentrue
else false
Dr. Nazir A. Zafar Formal Methods
-
P1 = known to Jim;
Jim: P;
known = {(Jim, p1), (Jim, p2)}
S : P x P BoolS (x, Jim) ==
Algorithm
S (x, Jim) ==
if x P1 thenfalse
endif
pre x Jim
Dr. Nazir A. Zafar Formal Methods
-
In the Z notation, two kinds of quantified expressions have a similar syntax
Q x : a | p qwhere
Quantifiers and Declaration
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
-
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
Useful Equivalences
x : a | p q is pronounced as there exists an xin a satisfying p, such that q.
x : a | p q is pronounced for all x in asatisfying p, q holds
Dr. Nazir A. Zafar Formal Methods
-
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 )|:( rqpax
Scope of Variable
)|:(first xofscope rqpax
yfirst ofscope
ysecondofscope
)|:(|: vutsrbyqpay
Dr. Nazir A. Zafar Formal Methods
-
Example 3.7
Consider the following quantified expression, which states that every natural number x is greater than or equal to zero
Independent Variable has no Importance
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
-
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)
Dependant Variable has Importance
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
-
Example 3.10:
In the expression below, the first bound variable is used as the range of the second:
a : b c : a p
Bound Variable as a Range Variable
a : b c : a p
In this case, it would make no sense to merge the two quantifications.
Dr. Nazir A. Zafar Formal Methods
-
Example 3.11: In the expression below, there is a single free occurrence of variable z
x : N z xExample 3.12: There are both free and bound
Free Occurrences of a Variable
occurrences of variable x in expression below
x = 3 x : N 0 x
Note: Occurrence of x adjacent to quantifier is neither free nor bound;
Free Occurrence Bound Occurrence
Dr. Nazir A. Zafar Formal Methods
-
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
Substitution
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
-
Example 3.13
1. (x y + 2) [0 / x] 0 y + 2
2. ( x : N x y + 2) [0 / x]
Substitution
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
-
Example 3.14
1. (x y + 2) [0 / x] [5 / y] 0 y + 2 [5 / y] 0 5 + 2
Substitution
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
-
Example 3.15
1. (x y + 2) [y, 5 / x, y] Parallel y 5 + 2
Substitution
2. (x y + 2) [y / x] [5 / y] Sequential
(y y + 2) 5 5 + 2)
Dr. Nazir A. Zafar Formal Methods