predicate logic
DESCRIPTION
Predicate Logic is the Bases of all the Logic used in Formal Methods in Software EngineeringTRANSCRIPT
Logic & Formal Methods
Predicate Logic
Instructor: Dr H. Farooq AhmadSarmad SadikTA: Muhammad Afzal, MaqboolReference: Discrete Mathematics with Examples by Simpson
Topics• Universal quantification• Existential quantification• Satisfaction and validity• The negation of quantifiers• Free and bound variables• Substitution• Restriction• Uniqueness• Equational reasoning• Natural deduction• One point rule
Page 2
Pros and cons of propositional logic
• Propositional logic is declarative
• Propositional logic allows conjunction, disjunction, negated information
• Propositional logic is compositional:• meaning of B1,1 P1,2 is derived from meaning of B1,1 and of
P1,2
• Meaning in propositional logic is context-independent (unlike natural language, where meaning depends on context)
• Propositional logic has very limited expressive power (unlike natural language)
First-order logic
• Whereas propositional logic assumes the world contains facts,
• first-order logic (like natural language) assumes the world contains– Objects: people, houses, numbers, colors,
baseball games, wars, …– Relations & functions: red, round, prime,
brother of, bigger than, part of, comes between, father of, best friend, one more than, plus, …
Syntax of FOL: Basic elements
• Constants KingJohn, 2, NUS,... • Functions Sqrt, LeftLegOf,...• Variables x, y, a, b,...• Connectives , , , , • Equality = • Quantifiers ,
Predicates
• A predicate is a proposition whose truth depends on the value of one or more variables.
• For example, “n is a perfect square” is a predicate whose truth depends on the value of n.
• A function like notation is used to denote a predicate supplied with specific variable values. P(n)=“n is a perfect square”
• P(4) is true and P(5) is false.
Page 6
Universal Quantification
• Universal Quantification denoted as • Universal Quantification allows us to
capture statements of the form “for all” or “for every”.
• For example, “every natural number is greater than or equal to zero” can be written formally as
0: nNn
Page 7
Universal Quantification
• A quantified statement consists of three parts: the quantifier, the quantification, which describes the variables and the type of variable with which the statement is concerned and the predicate which is normally some statement about the quantified variables.
• Every predicate logic statement can be considered as follows
predicate tion quantifica quantifier Page 8
Universal Quantification
nmnmnmNnm :,
nmnmnmNnNm :;:
nmnmnmNnNm ::
small is d d owns p small is p:;: DogdPeoplep
Page 9
Exercise
• Everybody likes Jaffa cakes• All vegetarians don’t like Jaffa
cakes• Everybody either likes Jaffa cakes
or is a vegetarian• Either every body likes Jaffa cakes
or everybody is a vegetarian
Page 10
Solution
n) vegetariaisx People:x(cakes) Jaffa likes x People:x(
n) vegetariaisx cakes Jaffa likes(x People:x
cakes)) Jaffa likes(x n vegetariais(x People:x
cakes Jaffa likes x People:x
Page 11
Universal Quantification
• Law 1
• Example
):()):():(( qpXxqXxpXx
strong) is p tallis pPerson:p(
strong)) is pPerson:p( tall)is pPerson:p((
Page 12
Universal Quantification
• Law 2
• Example
)):():(():( qXxpXxqpXx
strong) is p tallis pPerson:p(
strong)) is pPerson:p( tall)is pPerson:p((
Page 13
Existential quantification
• Existential quantifier denoted by • As universal quantification is used to
assert that a certain property holds of every element of a set, existential quantification is used to assert that such a property holds of some (or at least) elements of a set
• “Some natural numbers are divisible by 3” may be written as
03 modn N:n
Page 14
Exercise
• Some people like Jaffa cakes• Some vegetarians don’t like Jaffa
cakes• Some people either like Jaffa cakes
or are vegetarian• Either some people like Jaffa cakes
or some people are vegetarian
Page 15
Solution
n) vegetariaisx People:x(cakes) Jaffa likesx People:x(
n) vegetariais x cakes Jaffa likes(x People:x
cakes) Jaffa likes(x n vegetariaisx People:x
cakes Jaffa likesx People:x
Page 16
Existential quantification
• Law 3
• Example
)):():(():( qXxpXxqpXx
)))(:())(:((
))()(:(
csmallCarccfastCarc
csmallcfastCarc
Page 17
Existential quantification
• Law 4
• Example
)):():(():( qXxpXxqpXx
)))(:())(:((
))()(:
csmallCarccfastCarc
csmallcfastCarc
Page 18
Satisfaction and validity
• The predicate n>3 can be considered neither true nor false unless we know the value associated with n
• A predicate p is valid if and only if it is true for all possible values of the appropriate type. That is, if a predicate p is associated with a variable x of type X, then p is valid if, and only if,
• Example
trueis : pXx
true toequivalent is 0nN:n as validis 0n predicate The
Page 19
Satisfaction and validity
• A predicate p is satisfiable if and only if it is true for some values of the appropriate type. That is, if a predicate p is associated with a variable x of type X, then p is satisfiable if, and only if ,
• Example
trueis : pXx
true toequivalent is
0nN:n as esatisfiabl is 0n predicate The
Page 20
Satisfaction and validity
• A predicate p is unsatisfiable if, and only if, it is false for all possible values of the appropriate type.
• If a predicate p is associated with a variable x of type X, then p is unsatisfiable if, and only if,
false is : pXx
Page 21
Satisfaction and validity
• The analogies between valid, satisfiable and unsatisfiable predicates, and tautologies, contingencies and contradictions:
• valid predicates and tautologies are always true
• satisfiable predicates and contingencies are sometimes true and sometimes false
• unsatisfiable predicates and contradictions are never true
Page 22
The negation of quantifiers
• The statement “some body like Brian” may be expressed via predicate logic as
• To negate this expression, we may write as,
• which in natural language may be expressed as “nobody likes Brian”
Brian likes : pPersonp
Brian likes : pPersonp
Page 23
The negation of quantifiers
• Logically saying “nobody likes Brian” is equivalent to saying “everybody does not like Brian”.
• The negation of quantifiers behaves exactly in this fashion, just as in natural language, “nobody likes Brian” and “everybody does not like Brian” are equivalent so in predicate logic
• And
• are equivalent.
Brian) likes :( pPersonp
Brian) likes (: pPersonp
Page 24
The negation of quantifiers• Law 5
• When negation is applied to a quantified expression it flips quantifiers as it moves inwards(i.e negation turns all universal quantifiers to existential quantifiers and vice versa, and negates all predicates)
pXxpXx :):(pXxpXx :):(
Page 25
The negation of quantifiers
• Consider the statement,
• The effect of negation of this expression can be determined as,
),,(::: zyxpZzYyXx
),,(::: zyxpZzYyXx ),,(::: zyxpZzYyXx
),,(::: zyxpZzYyXx
),,(::: zyxpZzYyXx
Page 26
Exercise
• Everyone likes everyone• Everyone likes someone• Someone likes everyone• Someone likes someone
Page 27
Free and bound variables
• Consider two predicates• n>5…..Eq. 1
• In equation 2, the variable n is bound, it is existentially quantified variable.
• In equation 1, n is free as its value may not be determined or restricted
.....Eq.25: nNn
Page 28
Free and bound variables
• Example
• In this statement, y and x are two variables. y is universally quantified and it is bound, while x is free variable.
• In statement,• The occurrence of x in the declaration is
binding, any occurrences of x in p are bound, and any occurrences of any variables other than x are free
richard likes x robin) likesy People:y(
pXx :
Page 29
Free and bound variables• Example
• Exercise, Determine the scope of the universal and existential quantifiers of the following predicate,
• The distinction between predicates and propositions can be stated as predicates are logical statements which can contain free variables while propositions are logical statements which contain no such holes
3)0:( xxyxNx
)):(:( rqYypXx
Page 30
Substitution
• Consider statement,
• we may replace the name n with any term t, provided that t is of the same type as n. This process is called substitution: the expression p[t/n] denotes the fact that the term t is being substituted for the variable name n in the predicate p.
• Example, we may denote the substitution of 3 for n in the predicate n>5 by
5: nNn
]/3[5 nn Page 31
Substitution
• Also, we may denote the substitution of 3+4 for n in n>5 byn>5[3+4/n]
• Substitution is only for free variables
Page 32
Substitution• More than one substitution in case of more than
one free variable• Consider predicate,• Here x and y are both free variables. We may
substitute nigel for x as follows,
• Now substituting ken for y,
sad isy happy isx
sad isy happy is nigel
/x]sad)[nigel isy happy is(x
sad isken happy is nigel
]sad)[ken/y isy happy is (nigel
Page 33
Substitution• Similarly, in one step, overall substitution
may be denoted as,
• These two substitutions take place sequentially, first nigel is substituted for x, then ken is substituted for y. However, for simultaneous substitutions,
/x][ken/y]sad)[nigel isy happy is(x
ken/y]/x,sad)[nigel isy happy is(x
Page 34
Substitution• To illustrate the difference between sequential
and simultaneous substitution, consider the example,
• In former there is only one occurrence of y and in latter there are two occurrences of y
783
]/8,/)[73(
y
yxyyx
true
yyy
yxyyx
7838
]/8[73
]/8][/)[73(
Page 35
Restriction
• Filters role in predicate logic• Considering an example, all natural
numbers which are prime numbers and are greater than 2 are odd, may be written as,
• Using a filter, statement may be written as,
• Form of restricted predicates as,
odd isn 2)n prime is(n N:n
odd isn 2n prime isn |N:n
predicate n restrictio |tion quantifica quantifier
Page 36
Restriction
• Restriction can also be used in existential quantification, “there has been a female British Prime Minister”, may be written as Minister PrimeBritish a waspfemale is p|People:p
predicatenrestrictio|tionquantifica universal
predicate n restrictio tion quantifica universal
odd isn 2n prime isn |N:n
odd isn 2)nprime is(n N:n
Page 37
Restriction
• Law 6
• Law 7
t)pX:x(t)p|X:( x
):()|:( tpXxtpXx
Page 38
Exercise
• Represent the following statement in the form,
• Everyone who likes cheese likes spam• There is a person who likes cheese that
likes spam• Everyone who likes cheese also likes
spam and likes bananas
predicate n restrictio |tion quantifica quantifier
Page 39
Solution
bananas likes pspam likes pcheese likes p|People:p
spam likes pcheese likes p|People:p
spam likes pcheese likes p|People:p
Page 40
Uniqueness
• Existential quantifier, allows us to represent statements such as “there is at least one x, such that…”.
• In order to be more specific, consider, “there is exactly one x, such that…”
• Consider an example statement,
it is the case that the predicate x+1=1 is true for exactly one natural number:0
11xN:x
Page 41
• The operator which allow us to state that “ there is exactly one natural number, x, is denoted as
• As an example,
1
11:1 xNx
Uniqueness
richest a is cCountry:c1
Page 42
Uniqueness• Assuming the statement
• It is sometimes useful to pinpoint exactly which element of X for which predicate p holds. Also, it is convenient to perform some operation on this value.
• The µ operator allows us to do exactly this, the statement (µx:X | p) is read as “ the unique x from set X such that p holds of x”
• Example, (µx:N | x+1=1) where µ is associated with value 0
pXx :1
Page 43
Uniqueness• When a unique element of the relevant type does
possess the relevant property, then we are free to construct statements as given previously
• On the other hand, µ expressions that are not associated with a unique element generate an undefined value.
• As an example, the µ expressions(µn:N | n is even)
and(µc:Country | population (c) > 10,000,000)
are both undefined
Page 44
Uniqueness• We can incorporate terms into set
comprehensions, so we can apply terms in µ expressions. Expressions of the form,
• return the result of applying the term t to the unique element of the set X which satisfies the predicate p
• gives the value Washington
)|:( tpXx
)capital(c) richest is c |Country :c(
Page 45
Uniqueness• If there is no unique element which
possesses the relevant property, then the result is undefined
• and
• are both undefined.
)n even isn | N:n ( 2
)capital(c)10,000,000 (c) population |Country :c (
Page 46
Exercise
• Write the following in terms of µ expressions– The tallest mountain in the world– The height of the tallest mountain – The oldest person in the world– The nationality of the oldest person in
the world– The smallest natural number
Page 47
Solution
m))nN:m(|N:n(
y(p))nationalitin worldoldest is p|People:p(
in worldoldest is p|People:p(
height(m))in world tallest is m, Mountain, :m(
in world) tallest is m|Mountain:m(
Page 48
Equational Reasoning
• Two methods of reasoning– Equational reasoning– Natural deduction
• Also,
tpX:x
tp |X:x
tpX:x
tp | X:x
Page 49
Equational Reasoning
• Law 8If a predicate holds for all elements of a set, then it holds for some of them
• Law 9If a predicate holds for exactly one element of a set, then it holds for at least one of them
pXxpXx ::
pXxpXx ::1
Page 50
Equational Reasoning
• Law 10If p holds for all elements of X and t is a term of type X, then p holds for t
Example, The predicate holds for all natural numbers. The term 3+4 is of
type N and as such,
holds.
p(t)X)tp(x)X:x(
odd isx 2xprime(x)
odd is 432434)prime(3
Page 51
Equational Reasoning
• Law 11This law states that if t is a term of type X and p holds of t, then we can conclude that p holds for some elements of X
• ExampleThe proposition 7εN is true and furthermore 7 is prime. As such,
))(:())(( xpXxtpXt
prime isn N:n
Page 52
Equational Reasoning
• The quantification of any variables with regards to propositions which are always true or always has absolutely no effect. This notion is captured by following laws,
• Law 12
• Law 13
• Law 14
• Law 15
truetrue)X:x(
falsefalse)X:x(
truetrue)X:x(
falsefalse)X:x(
Page 53
Equational Reasoning• The predicate is
concerned with three variables: x, y and z. • x is bound and y and z are free. As x does
not appear in the predicate y=z, we are free to assume that the existential quantification of x has no effect on the truth or falsity of that predicate.
• We conclude that following equivalence holds.
zyxpXx
zyxpXx
))(:(
))((:
zyp(x)X:x
Page 54
Equational Reasoning
• Law 16It states that as x does not appear free in q, the following holds
• Example,
)):(():( qpXxqpXx
)10)3:(()103:( lnNnlnNn
Page 55
Equational Reasoning
• Law 17It states that as x does not appear free in q, the following holds,
• Example
)):(():( qpXxqpXx
)10)3:(()103:( lnNnlnNn
Page 56
Equational Reasoning
• Law 18It states as x does not appear free in q, the following holds
• Example
)):(():( qpXxqpXx
10)lspam) likes pPerson:p((
10)lspam likes pPerson:p(
Page 57
Equational Reasoning
• Law 19It states as x does not appear free in q, the following holds
• Example
)):(():( qpXxqpXx
10)lspam) likes pPerson:p((
10)l spam likes pPerson:p(
Page 58
Equational Reasoning
• Example: A theorem in predicate logic
• Proof:
):():( qpXxqpXx
law) onal(propositi qpX:x
law) onal(propositi )(:
5) (law )(:
:
qpXx
qpXx
qpXx
Page 59
Equational Reasoning
• Example Theorem
18) (law qpX:x
3) (law qpX:x
8) (law q)X:x(p)X:x(
5) (law q)X:x(p)X:x(
law) onal(propositi q)X:x(p)X:x(
q))X:x(p)X:x((
q)pX:x(q))X:x(p)X:x((
Page 60
Exercise
)):():(():( qXxpXxqpXx
Page 61
Solution
18) (law q)X:x(p)X:x(
5) (law ):():(
3) (law ):()X:x(
law) onal(propositi :
:
qXxpXx
qXxp
qpXx
qpXx
Page 62
Natural deduction• Natural deduction can also be extended to
predicate logic• Natural deduction rules for universal
quantification
• Rule1 states that if p holds for all values of X, then provided that t is of type X- p holds for t
elim) ( )/(
x t:
xtp
pXx
Page 63
Natural deduction
• Example:All natural numbers which are prime and greater than 2 are odd. 7 is prime and greater than 2 and we may conclude that it is odd.
elim) ( )7(
N7 27prime(7) odd(n)2nprime(n)|N:n
odd
Page 64
Natural deduction
• Rules for existential quantificationIf xεX such that p holds for x, then if we are able to define further predicate, q in which x does not appear free, then we may conclude q
Page 65
q
qpXx |:
Natural deduction
• Intro rule• If p is true for any term t of set X, then
we conclude that, holdspXx :
intro) ( pX:x
p[t/x] Xt
Page 66
intro) ( prime(n)N:
prime(7) N7
n
Natural deduction
• Example
intro) ( qp|X:x
q[t/x] p[t/x] Xt
Page 67
The one-point rule
• It states that p is a person that likes Emily, but also that the name of person is Rick
• We can conclude that rick ε Person and rick likes emily are both true
• Law 20
X t p[t/x]
txpX:x
p(t/x)) x(t t)xpX:x(
rickpemily likes pPerson:p
Page 68
The one-point rule
• Example
txpX:x
Xtp[t/x]
car red a ownsbecky Personbecky
beckyp car red a owns pPerson:p
Page 69
beckyp car red a owns pPerson:p
Personbeckycar red a ownsbecky
References
• Discrete Mathematics with Examples by Simpson
Page 70
Thank you!
Page 71