predicate logic colin campbell. a formal language predicate logic provides a way to formalize...

36
Predicate Logic Colin Campbell

Upload: danielle-mckay

Post on 28-Mar-2015

225 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Predicate Logic

Colin Campbell

Page 2: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

A Formal Language

Predicate Logic provides a way to formalize natural language so that ambiguity is removed.

Mathematical arguments (proofs) are usually written in pseudo logic.

Many programming languages involve elements of predicate logic. e.g. if..then

Page 3: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Predicate vs Propositional Logic

Predicate logic uses the same connectives as propositional logic but allows you to refer to different elements of the universe.

It also introduces quantifiers…so you can say things like..

It always rains in England. Sometimes it is sunny in Bristol.

Page 4: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Propositional Logic Revised

Propositional Logic is a formal approach to reasoning with or about declarative sentences.

If David likes Mary then Mary likes DavidDavid likes Mary

Mary likes David

Page 5: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Semantics vs Proof Theory

There are two approaches to reasoning in propositional logic.

Semantics= truth tables and valuations

Proof theory = formal notion of proof from axioms and inference rule

Page 6: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Truth-Tables The truth value of compound sentences can

then be determined by application of truth tables defined for each connective

A A

tf

ft

A B ABtftf

ttff

tfff

A B AB

tftf

ttff

ttft

etc

A sentence B truth-functionally follows from sentence A if for every row of the truth-table in which A is true B is also true. Denoted A|=B

Page 7: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Formal Proof

T=set of assumptions (sentences) then T|-A if we can generate a sequence of sentences

S1,S2,…,Si-1,Si,…,Sn=A

Where either

Si=axiom = a sentence in T (an assumption)orS1,…,Si-1 (inference rule) Si

Axioms for propositional logic

1. A(B A)

2. (A (B C)) ((A B) (A C))

3. (B A) ((B A) B)

Inference Rule: Modus PonensFrom A,AB infer B

Page 8: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Relating Semantics and Proof

Soundness

Proof theory Semantics

Completeness

Semantics Proof theory

Propositional logic is sound and complete

Semantics= Proof theory

Page 9: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Decidability A formal logic is decidable if there is a

mechanical (algorithmic) way of determining whether A follows from T.

T|=A ?

yes

No

Propositional logic is decidable: at worst we need only consider every row of the truth-table for which T is true, and there are only finitely many.

Page 10: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Predicate Logic: Introducing Quantifiers

Predicate logic allows for quantified statements by introducing the quantifiers “for all” and “there exists”.

Why do we need quantifiers ? Consider

All birds have wingsTweety is a birdTherefore, Tweety has wings

Propositional logic: All birds have wings= (Robins have wings)(Crows have wings)(Eagles have wings) ..........etc. This is impractical.

Page 11: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Quantifiers 2:

In predicate logic this translates to

TweetyW

TweetyB

xWxBx

B(x)= x is a Bird, W(x)=x has wings,x (B(x)W(x)) = For all x, if x is a bird then x has wingsB(Tweety)=Tweety is a bird.W(Tweety)=Tweety has wings

• Unlike propositional logic, predicate logic has variables- in this case x.• It also has constants – in this case Tweety• Tweety is an instantiation of the predicates B and W.

Page 12: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Functions It is also desirable to be able to represent

functional relationships in predicate logic. ConsiderBlue eyed people have blue eyed fathersSome people have blue eyesTherefore, some people’s fathers have blue eyes

Translates to

x BE x BE F x xBE x xBE F x

x is a variable ranging across all people

BE(x) -means “person x has blue eyes”

F is a function mapping from one person x to another person F(x), where F(x) is the father of x

Page 13: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Syntax: Building Blocks for Predicate Logic

Formula in predicate are built up from the following elements

(1) Predicates: PL is a set of n-ary predicates. e.g.

B(x)=x is a bird –unary M(x,y)=x is married to y –binary BT(x,y,z)=y is between x and z –

tertiary

Page 14: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Syntax (2) (2) Functions: FNL is a set of n-ary

functions. F(x)=Father of x, D(x,y,z)=Day of the

weeks falling on the date x/y/z. (3) Constants: CL is a set of constants

e.g. Tweety, numbers, Aunty Ethel (4) Variables: a set of variables, x,y,z

etc (5) Connectives, Quantifiers and

Brackets: ,,,,, (,),[,]

Page 15: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Terms Terms are possible instantiations of predicates. The set of terms TL is defined recursively in the

following way:

(i) All variables and constants are terms(ii) If f is an n - ary function symbols and t1....tn are terms then f(t1....tn) is a term.

FNL={father, mother, first-child}, CL={bill}, VL={x} -ranging across parents

x, bill, father(x), mother(x), first-child(x), father(bill), mother(bill), first-child(bill), father(father(x)), father(mother(x)), first-child(father(x)) father(father(bill)), father(mother(bill)),.......etc

Page 16: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Formula in Predicate Logic

Atomic Formula: The atomic formula ATL, have the form P(t1,...., tn) where P is an n-ary relation in PL and ti are terms for i=1,...,n

E.g. PNL={Rich,Happy}, FNL={father,mother},CL={jim, fred, mary}, VL={x,y}

Atomic formula include…Rich(x), Happy(y), Rich(bill), Happy(father(y)), Rich(mother(mary)), Happy(father(mother(x))) etc

Page 17: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Formula 2 Well-Formed Formula: The set of well-

formed formula WFL is defined recursively as follows:

(i) all atomic formula are well-formed formula(ii) If F and G are well-formed formula so are (F), (FG), (FG), (FG), (FG)(iii) If F is a well-formed formula and xVL then (xF) and (xF) are well-formed formula.

E.g. Rich(x)Happy(x), Rich(x)Happy(y), Rich(bill)Happy(father(fred)), (x Happy(x)) yRich(y)), x(Rich(x) Happy(x))

Page 18: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Translating from Logic to English

Example: PL ={married, younger-than, equal} all binaryVL={x,y,z} ranging over all parentsCL={bill, john, george, mary}FNL={father, mother, first-child} -all unaryConnectives ,,,,Quantifiers ,, Brackets

married(mary,john) translates to ”Mary is married to John”equal(father(bill),george) translates to ”George is the father of Bill”equal(mother(mother(bill)),mary) translates to ”Mary is the maternal grandmother of Bill”(equal(mother(x),y)equal(father(x),y)) translates to ”y is a parent of x”xy(married(x,y) married(y,x)) translates to ”for any parents x and y if x is married to y then y is married to x”xy(equal(mother(x),y) translates to ”everyone has a mother”

Page 19: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Translating from English to Logic

“Anyone who is persistent can learn logic” translates to x(persistent(x)learn(x, logic))

“All blocks which are on top of or attached to blocks which have been moved, have also been moved” translates to xy((block(x)block(y)(ontop(x,y) attached(x,y))moved(y))moved(x))

“You can fool some of the people all of the time, and you can fool all the people some of the time, but you can’t fool all the people all the time” translates to xy(person(x)time(y)fool-at(y,x)) yx(person(x)time(y)fool-at(y,x)) (x y (person(x)time(y)fool-at(y,x)))

Page 20: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Removing Ambiguity

Bertrand Russell gave the following example of how translating to logic can remove ambiguity.

Consider the sentence “The current king of France is bald”. Is this sentence true?

Translating to logic gives: x(KF(x)B(x)) KF(x)= x is the current king of France. B(x)= x is bald. This is clearly false! Why?

Page 21: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Whoops-Missed a bit

Its only me!So the correct translation is

xKF(x)x(KF(x)y(KF(y)equals(x,y)))x(KF(x)B(x))

Still false though!

What about “the current king of France is not bald” – is it true or false?

Page 22: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Declarative Formula

Some formula have a truth-value while others don’t.

xy(equal(mother(x),y) has a truth-value So does x(Rich(x)Happy(x)) But neither Rich(x) nor married(x,y)

married(y,x) have truth values. In predicate logic declarative formula are

closed. Non-declarative form are open.

Page 23: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Open and Closed Formula Scope of a Quantifier: The scope of x (resp. x) in

x F (resp x F) is F E.g. In x(Rich(x)Happy(x)) the scope of x is

(Rich(x)Happy(x)) In xy(equal(mother(x),y) the scope of x is

y(equal(mother(x),y) and the scope of y is (equal(mother(x),y)

Free and Bound Occurrence of a Variable: A bound occurrence of a variable in a formula is an occurrence immediately following a quantifier or an occurrence within the scope of a quantifier, which has the same variable immediately after the quantifier.

Any other variable is free.

Page 24: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Open and Closed:2 Example: In the formula (xP(x,y))Q(x) the

occurrence of x in P(x,y) is bound but the occurrence of x in Q(x) is free.

All occurrences of x in x(P(x,y)Q(x)) are bound. Open and Closed Formula: A closed formula is

a well-formed formula with no free occurrences of any variable. An open formula is a formula that is not closed

Example: xy(equal(mother(x),y) is closed since all occurrences of x fall within the cope of x and all occurrences of y fall within the sope of y.

Page 25: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Interpretations Really a language of predicate logic is only a set

of symbols which can be interpreted in different ways.

Consider the formula: yxP(x,y) Quantification over natural numbers, P(x,y)

means xy then interpretation is `for all natural numbers x there is some natural y for which xy’

Quantification over people, P(x,y) means `y is the father of x’ then interpretation is `there is some who is the father of everyone’

Page 26: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Interpretations:2

Formal Logic

PL={P,Q,R,..}FL={f,g,h,..}CL={a,b,c,..}

U1 U2

IPLI={PI,QI,RI,..}FLI={fI,gI,hI,..}CLI={aI,bI,cI,..}

J PLJ={PJ,QJ,RJ,..}FLJ={fJ,gJ,hJ,..}CLJ={aJ,bJ,cJ,..}

Page 27: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Theories and Models

Theory: A theory of a language of predicate logic L is any finite set of closed well-formed formula of L.

Model: A model of a theory T is an interpretation of L under which all the formula in T are true.

Page 28: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Satisfiability

A theory of L, is satisfiable if it has at least one model.

Any theory that is not satisfiable is said to be inconsistent.

Any theory for which every possible interpretation is a model is said to be valid.

Page 29: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Satisfiability: 2

The theory consisting of the single formula x(P(x) P(x)) is inconsistent.

The theory {x (P(x) P(x))} is valid.

Page 30: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Example Consider the following theories:

Also consider the following two interpretations

ycyPxfxxPT

cfcPyxyPxT

,,

,,

2

1

Interpretation I: Let U1 be the set of all integers, cI=0, fI is the successor function, PI is >

Interpretation J: Let U2 be the set of all integers, cJ=0, fJ is the predecessor function, PI is

Page 31: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Example: 2

Under IT1 meansIf for every integer x there is some integer y such that x>y then 0>0+1Clearly this is false since the antecedent is true and the consequence is false - I is not a model of T1

T2 meansIf for every integer x x>x+1 then there exists an integer y such that 0>y

This is true since the antecedent is false - I is a model of T2

Page 32: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Example: 3

Under JT1 meansIf for every integer x there is some integer y such that xy then 0 0-1Clearly this is true since both the antecedent and consequence are true - J is a model of T1

T2 meansIf for every integer x, x x-1 then there exists an integer y such that 0yThis is true since, again, both antecedent and consequence are true - J is a model of T2

Page 33: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Example: 4

We see that T1 is not a valid theory since I is not a model of T1.

Both I and J are models of T2. Is T2 valid? Let K be any interpretation of L then T2

means If for every element xU PK (x, fK(x)) then

there exists some element yU such that PK(cK, y ).

Page 34: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Example: 5 Two possibilities Antecedent false -in this case the

conditional is automatically true. Antecedent true -in this case since

cKU we have PK (cK, fK(cK)) and hence the consequence of the conditional must also be true since we can select y to be fK(cK).

Page 35: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Semantic Entailment A theory T is said to entail a closed formula F if F is

true in every model of T.

models of F models of F

models of T

T F

models of F models of F

models of T

T F

models of F models of F

models of T

T F

T F

Page 36: Predicate Logic Colin Campbell. A Formal Language Predicate Logic provides a way to formalize natural language so that ambiguity is removed. Mathematical

Decidability

Proof Procedure

Query: does F follow from T

Proof Procedure

Query: does F follow from T

T F

T F

Predicate logic is only semi-decidable

Algorithm terminate and answers “yes”

Algorithm may or may not terminate and answers “no”