Anda di halaman 1dari 30

CS-3234

Lesson 4: Predicate calculus (I)


Syntax & Semantics

G Stefanescu — National University of Singapore

Logic & Formal Systems


Semester 1, Fall, 2002-2003

Slide 4.1 CS-3234 / Logic & Formal Systems / G Stefanescu


The need for a richer language
propositional logic deals satisfactorily with finite sentences
composed using not, and, or, if . . . then
on finite models this may be enough to deal with there exists,
all, among, only. E.g., if there are 3 students A  B and C, taking
p  “A has red hat”, q  “B has red hat” and r  “C has red
hat”, the formula “there exists a student with a red hat” may be
 
modeled as p q r.
on infinite models this may require infinite formulas; e.g.,
“each

natural  number is even

or odd” has to be translated as
  
p0 q0   p1 q1   p2 q2    
where p0  “0 is even”, q0  “0 is odd”, p1  “1 is even”,
q1  “1 is odd”,. . .

Slide 4.2 CS-3234 / Logic & Formal Systems / G Stefanescu


Key features

predicate logic (also known as first order logic) is an extension


of propositional logic using variables for objects
let us use x for “x is a natural number”; the above formula may
be shortly written as
   
x E x O x 
 
where E x   “x is even” and O x   “x is odd”
these variables are combined with function symbols to repre-
sent new objects and with predicate 
symbols to describe re-
lations between objects; e.g., if s x  is the successor function
and L x  y  represents “x y”, then “a number is smaller than


its succesor” is represented as xL x  s x 

Slide 4.3 CS-3234 / Logic & Formal Systems / G Stefanescu


Examples
 
“Not all birds can fly”: let B x  denotes “x is a bird” and F x 
denotes “x can fly”; the statement may be represented by for-
mula   
x B x F x  


All man are mortal.



Socrates is men. Therefore,

Socrates is
mortal: let H x  denotes “x is man”, M x  denotes “x is mor-
tal”, and s denotes Socrates; the statement may be described as
the deduction
    
M x   H s  M s 


x H x


Andy and Paul have the same maternal


grandmother: let use a
and p for Andy and Paul and M x  y  for “x is y’s mother”; the
statement may

be

modeled 
as  
x y u v M x  y   M y  a   M u  v   M v p  x  u


Slide 4.4 CS-3234 / Logic & Formal Systems / G Stefanescu


..examples
In the last example we need equality - the formalism is know
as first order logic with equality.
In some cases (including the above one) formulas may be sim-
plified using functions. If m x  denotes the mother of x (this is
totally and uniquely defined, hence it really defines a function),
then the above statement
 
may be modeled much simpler
m m a   m m p  
Ann likes
 
Mary’s brother is ambigous and may be translated as
x B x  m   L a  x  (Ann likes one of Mary’s brothers)
or   
x B x  m L a  x  (Ann likes all of Mary’s brothers)


Slide 4.5 CS-3234 / Logic & Formal Systems / G Stefanescu


Soundness & Completness


we will extend both the natural deduction ‘ ’ and the standard


semantic interpretation ’  ’ to the predicate calculus
a basic result is a similar soundness & completness theorem

φ1  φ2     φn ψ iff φ1  φ2     φn  ψ




due to K Gödel (the proof is much more complicate - see lec-


ture 12)

Slide 4.6 CS-3234 / Logic & Formal Systems / G Stefanescu


Predicate logic as a formal language
Two entities
objects - they are denoted by terms, i.e., by

individual constants
a, p, or using function symbols (e.g., m a  is also an object)
predicates/truth values of relations - they are denoted by for-
mulas; such a formula captures a relation between objects; for
particularly given objects a formula may be true or false
The formal approach starts with the construction of terms, then in-
troduces predicate logic formulas. The vocabulary consists of
— a set P of predicate symbols
— a set F of functions symbols
— a set C of constant symbols
(In some formalisms C is included in F : a constant is seen as a 0-ary operation.)
Slide 4.7 CS-3234 / Logic & Formal Systems / G Stefanescu
Terms

Terms are defined as follows:


any variable is a term
any constant in C is a term
if  t1  t2     tn are term and f F has arity n, then
f t1  t2     tn  is a term
nothing else is a term
In a Backus-Naur like-form we may write

t ::  x c f t     t 

where x is a variable, c C , and f F has arity n.


Slide 4.8 CS-3234 / Logic & Formal Systems / G Stefanescu
Parse tree (prefix notation for terms)

11 −      
11: s p   q   p  q  s r  


 

10: p  q  s r  


 
9 * 10 * 9:  s p    q 


8: q  s r 


5 s 6 q 7 p 8 + 7:p
6:q

p
5:s  p 
2 3 q 4 s
4:s r 
3:q
(p+1)*q − p*(q+(r+1)) 1 r 2:p
1:r

Slide 4.9 CS-3234 / Logic & Formal Systems / G Stefanescu


Formulas

Formulas over F  P  are inductively defined using the set of terms
over F as follows::
if P is a predicate in P taking n arguments (n 1) and
t1  t2     tn are terms over F , then P t1  t2     tn  is a formula

if φ is a formula, then so is φ
   
if φ and ψ are formulas, then so are φ  ψ   φ ψ  and φ


ψ
 
if φ is a formula and x is a variable, then xφ  and xφ  are
formulas
nothing else is a formula

Slide 4.10 CS-3234 / Logic & Formal Systems / G Stefanescu


..formulas
In a Backus-Naur like-form we may write
     
φ ::  P t      t  φ φ  ψ φ ψ φ ψ



xφ  xφ 
where P is a predicate of arity n, t’s are terms and x is a variable.

Convention
 x and x bind most tightly

then  and
then


Slide 4.11 CS-3234 / Logic & Formal Systems / G Stefanescu


Example

“Every son of my father is my brother”


It has more possible translations, e.g., 
(father is predicate)

let m represent “me” (or “I”),  S x  y  “x is
a son of y”, F x  y  “x is the further of y”, and B x  y  “x is a
brother  of  y”; the statement

may

be represented as
x y F x  m   S y x  B y m  


or

(father is function) as before, but use f x  to represent “the
father of

x”; the statement

may be represented as
x S x  f m  B x  m 


Slide 4.12 CS-3234 / Logic & Formal Systems / G Stefanescu


From natural language to logics and back
The predicate calculus is a precise, formal setting, while natural lan-
guages are more vague. Hence:
— (1) the reading of formulas (passing from logic to a natural lan-
guage) is easy/clear, but the passing from a natural language state-
ment to a (predicate) logic formula is more problematic (one may
come with more, sometimes inequivalent, proposals)
— (2) while in mathematics one sometimes lives under the illu-
sion that there is just one logic (predicate calculus or classical first-
order logic) in fields more closed to natural language —like com-
puter science or philosophy—, one finds the opposite: there is a
lot of logics including intuitionistic logic, linear logic, modal logic,
temporal logic, belief logic, dynamic logic, Hoare logic, specifica-
tion logic, relevance logic, higher-order logic, bunched logic, non-
commutative logic, etc., many coming with a lot of versions.
Slide 4.13 CS-3234 / Logic & Formal Systems / G Stefanescu
Free and bound variables - examples

a variable ocurring in xQ x  is immaterial, or bound by
1
(It’s like in calculus: in 0 sin  x dx the variable x is bound by .)



to verify that xQ x  is true amounts to replace x by any of its
possible values and checking that Q holds for each one of them
 
similarly for xQ x  , but in this case xQ x  is true when Q
holds for at least one particular value of x

Slide 4.14 CS-3234 / Logic & Formal Systems / G Stefanescu


Free and bound variables - examples
Roughly speaking
you should interpret x as an infinite conjunction of formulas
parametrized

by

x  
xP x   P a1   P a2   P a3    
where a1  a2  a3    is supposed to be a listing of all possible
values for x.
similarly,

x should

be
interpreted

as an infinite disjunction
  
xP x   P a1  P a2  P a3   
where a1  a2    are as above.

Slide 4.15 CS-3234 / Logic & Formal Systems / G Stefanescu


Free and bound variables - formal
Let φ be a formula in predicate logic.
An occurrence of x in φ is free in φ if it is a leaf node in the
parse tree of φ such that there is no path upward from that node
x to a node x or x.
An occurrence of x that is not free is called bound.
Example

(convention:
 
blue

represents free and red bound): In
S x  y  x P x Q x 


the occurrences of variable x in P and Q are bound by ; on the other


hand, the occurence of y and the occurrence of x in S are free.
Strictly speaking, we do not have free or bound variables (as in the title), but
free and/or bound occurrences of variables. A variable may have both free and
bound occurrences in the same formula (like x in the given example), but an oc-
currence of a variable is either free or bound (not both).
Slide 4.16 CS-3234 / Logic & Formal Systems / G Stefanescu
Substitution
Definition
Given a variable x, a term t, and a formula φ we define φ t  x
to be the formula obtained by replacing each free occurence of
variable x in φ with t.

Examples:
    
S x  y    x P x  Q x    f x   y   x


  S f x  y  y  x P


x  Q x 
    
S y  y   x P x  Q x 
 
  f x  y   x


 
 S y  y  x P x Q x 


What about
    
yS x  y    x P x  Q x  f  y   x


 yS f y   y   x P x  Q x   ??


Slide 4.17 CS-3234 / Logic & Formal Systems / G Stefanescu


Caution: clash of variables

We should avoid
    
yS x  y    x P x  Q x  f  y   x


 yS f y   y   x P x Q x  


Reason
the meaning of the formula is unexpectedly changing: the new term
f y (which replaces x) makes y to bound to more variable occur-
 

rences than in the original formula φ


In different terms,
— in the original formula φ the first occurrence of x is free, hence φ is true or false
depending on the value of x
— this property should be preserved by replacing x with f y , i.e., the corre-  

sponding occurrence of y should be free and the truth value of the formula should
depend on y
— however, in  yS f y  y  x P x  Q x there is no free occurrence of y,
         

so its truth value does not depend on y


Slide 4.18 CS-3234 / Logic & Formal Systems / G Stefanescu
Clash of variables - concrete example
  
Take natural numbers, S x  y  : “x y”  P x  : “x 100”  Q x  : 

“x 10” . The formula in the above example becomes


   
φ x  yx y  x x 100  x 10  


 
and φ 10  is true. Take f x   2 x. With the “unsafe” substitution


2 y  x we get


    
φ 2 y  y2 y y  x x 100  x 10 


 

 
and φ 10   φ 2 5  is false. Using the forthcoming “safe” substi- 

tution we get
    
φ 2 y  z2 y z  x x 100  x 10  


 

 
and φ 10   φ 2 5  is true, as in the original formula.


Slide 4.19 CS-3234 / Logic & Formal Systems / G Stefanescu


Renaming variables
A solution to the above problem is to
rename the bound variables with fresh ones in order to avoid
such clashes.
Specifically in the above example we may rename y by z
   
yS x   y   x P x   Q x  


 zS x  z   x P x  Q x 


then apply

the substitution
    
zS x  z   x P x    Q x    f y   x


 zS f y   z   x P x  Q x 


Slide 4.20 CS-3234 / Logic & Formal Systems / G Stefanescu


..renaming variables
Definition: Given a term t, a variable x, and a formula φ, we say that
t is free for x in φ if no free x leaf of φ occurs in the scope of y or
y for any variable y occurring in t.

Fact: When this condition is fulfilled the substitution is safe.

Examples:
   
φ yS x  y   x P x Q x  ;



then f z  is free for x in φ,
but g z  y  is not free for x in φ

Slide 4.21 CS-3234 / Logic & Formal Systems / G Stefanescu


Natural deduction
Rules
predicate logic extends propositional logic, so all propositional
logic natural deduction rules are inherited
we have to design new rules dealing with the quantifiers and
with equality symbol
So, we are describing here first order logic with equality. Often the presentation
of predicate logic starts with the simpler case where equality is absent.

Slide 4.22 CS-3234 / Logic & Formal Systems / G Stefanescu


The proof rules for equality

The proof rules for equality


 t1  t2 φ t 1  x  
 :  i  e
t  t φ t2  x 
Example:    
x 1  1 x x


1 1 x 1 0 1 x 1 1 x 0
     

 

1 x 1  1 x premise
 


2  x 1 1 x 1 0 premise
 


3 1 x 1 1 x 0 (  e) for 1,2
 

The formula φ used in the last step is x  1   x 0 

Slide 4.23 CS-3234 / Logic & Formal Systems / G Stefanescu


Properties of equality
The equality is




reflexive: t t

 


symmetric: t1 t2 t2 t1
1. t1  t2 premise
2. t1  t1 (=i)
3. t2  t1 (=e) 1,2 (where φ is x  t1 
 t2  t2  


transitive: t1 t3 t1 t3
1. t2  t3 premise
2. t1  t2 (=i)
3. t1  t3 (=e) 1,2 (where φ is t1  x)

Slide 4.24 CS-3234 / Logic & Formal Systems / G Stefanescu


The proof rules for universal quantification

The proof rules for universal quantification


x0
..
.
xφ  φ x0  x  
x: x e x i
φ t  x xφ
These rules generalize the rules for  .

Comments on x i  : In this rule the box starts with a “fresh” vari-
able x0 which doesn’t occur anywhere outside the box. If the for-
mula φ is true for such a generic element, then it should be true for
arbitrary terms.

Slide 4.25 CS-3234 / Logic & Formal Systems / G Stefanescu


Universal quantification - examples (1)
    



Example 1: P t  x P x Q x   Q t



1 P t   
premise
2 x P x  Q x   premise



3 P t Q t ( xe) for 2


4 Q t ( e) for 3,1


Slide 4.26 CS-3234 / Logic & Formal Systems / G Stefanescu


Universal quantification - examples (2)
    



Example 2: x P x  Q x  xP x  xQ x 


  
1 x P x  Q x   premise


2 xP
x 
premise
3 x0 P  x0  Q x0  ( xe) for 1


4 P  x0  ( xe) for 2
5 Q x0  ( e) for 3,4


6 xQ x  xi for 3-5

Slide 4.27 CS-3234 / Logic & Formal Systems / G Stefanescu


The proof rules for existential quantification

The proof rules for existential quantification


x0 φ x 0  x 
xφ ..
.
φ t  x  χ 
x: x i x e
xφ χ

These rules generalize the rules for .

Comments on x e  : Again, the box starts with a “fresh” variable
x0 which doesn’t occur anywhere outside the box. If formula xφ is
true, then φ is true of a particular value of x. To conclude with χ we
need proofs covering all possible values of x. So, the box starts with
φ true for such a generic element and concludes with χ.

Slide 4.28 CS-3234 / Logic & Formal Systems / G Stefanescu


Universal quantification - examples (1)


Example 1: xφ xφ

1 xφ premise
2 φ x  x ( xe) for 1
3 xφ ( xi) for 2

Slide 4.29 CS-3234 / Logic & Formal Systems / G Stefanescu


Universal quantification - examples (2)
    



Example 2: x P x  Q x  xP x  xQ x 


  
1 x P x  Q x   premise


2 xP
x premise
3 x0 P  x0  
( xe) for 1
4 P  x0  Q x0  ( xe) for 1


5 Q x0  ( e) for 4,3




6 xQ  x  ( xi) for 5
7 xQ x  ( xe) for 2,3-6

Slide 4.30 CS-3234 / Logic & Formal Systems / G Stefanescu

Anda mungkin juga menyukai