Sie sind auf Seite 1von 31

Outline

Chapter 2 THE PREDICATE CALCULUS

1. The Propositional Calculus 2. The Predicate Calculus 3. Using Inference Rules to Produce Predicate Calculus Expressions 4. Application: A Logic-Based Financial Advisor

Artificial Intelligence, 2004 by Yeuan-Kuen Lee http://www.csie.mcu.edu.tw/~yklee/Courses/AI/ArtificialIntelligence2004.html

Ch 2 The Predicate Calculus

Propositional Calculus

2.1 The Propositional Calculus 2.1.1 Symbols and Sentences 2.1.2 Semantics
Symbol make up Syntax Sentence Semantic ( meaning )
4

Chapter 2 The Predicate Calculus

Ch 2 The Predicate Calculus

2.1 The propositional calculus


Language:
Symbol make up Syntax Sentence Semantic ( meaning )

2.1.1 Symbols and sentences


DEFINITION : PROPOSITIONAL CALCULUS SYMBOLS

Propositional symbols : P, Q, R, S denote propositions, or statements about the world that may be either true or false. Example: the car is red, water is wet Truth symbols : true, false Connectives: , , , ,
Sentences are formed from these atomic symbols by the following rules:
Symbol
Ch 2 The Predicate Calculus

Propositional calculus and predicate calculus are first of all languages.

Using their words, phrases, and sentences, we can represent and reason about properties and relationships in the world.
Ch 2 The Predicate Calculus 5

make up

Syntax

Sentence Semantic ( meaning ) 6

2.1.1 Symbols and sentences


DEFINITION: PROPOSITIONAL CALCULUS SENTENCES

2.1.1 Symbols and sentences


DEFINITION: PROPOSITIONAL CALCULUS SENTENCES

Every propositional symbol and truth symbol is a sentence. Example: true, P, Q, and R are sentences The negation of a sentence is a sentence. Example: P and false are sentences The conjunction, or and, of two sentences is a sentences. Example: P P is a sentence term: conjunct
Ch 2 The Predicate Calculus 7

The disjunction, or or, of two sentences is a sentences. Example: P P is a sentence term: disjunct The implication of one sentence from another is a sentence. Example: P Q is a sentence term: premise or antecedent term: conclusion or consequent

Ch 2 The Predicate Calculus

2.1.1 Symbols and sentences


DEFINITION: PROPOSITIONAL CALCULUS SENTENCES

2.1.1 Symbols and sentences


Symbols ( ) and [ ] Used to group symbols into subexpressions To control the order of evaluation and meaning Example: (P Q) R is quite different from P (Q R)

The equivalence of two sentence is a sentence. Example: P Q is a sentence Legal sentences are also called well-formed formulas or WFFs.
make up
Syntax

Symbol

Sentence Semantic ( meaning )

Ch 2 The Predicate Calculus

Ch 2 The Predicate Calculus

10

2.1.1 Symbols and sentences


An expression is a sentence or well-formed formula

2.1 The Propositional Calculus 2.1.1 Symbols and Sentences 2.1.2 Semantics
Symbol make up Syntax Sentence Semantic ( meaning )
12

iff
it can be formed of legal symbols through some sequence of these rules.
(( P Q) R ) P Q R
is a well-formed sentence
Ch 2 The Predicate Calculus 11 Ch 2 The Predicate Calculus

2.1.2 Semantics

[ Meaning of sentence ]

2.1.2 Semantics
A proposition symbol corresponds to a statement about the world P Q
It is raining I live in a brown house

A precise treatment of semantics is essential

Automatic Reasoning is needed in AI program. It is important to demonstrate that the truth of their conclusions depends only on the truth of their initial knowledge. Logical errors are not introduced in the inference procedures

May be either true or false

The truth value assignment to propositional sentences is called interpretation. Propositional symbols
interpretation mapping

{ T, F }

Note T, and F are truth values,


Ch 2 The Predicate Calculus 13 Ch 2 The Predicate Calculus

true and false are part of set of well-formed formulas


14

2.1.2 Semantics
DEFINITION : PROPOSITIONAL CALCULUS SEMANTICS

2.1.2 Semantics
DEFINITION : PROPOSITIONAL CALCULUS SEMANTICS

An interpretation of a set of propositions is the assignment of a truth value, either T or F, to each propositional symbol. The symbol true is always assigned T, and the symbol false is assigned F.

The interpretation or truth value for sentences is determined by: The truth assignment of negation, P , is F if the assignment to P is T, and T if the assignment to P is F. (where P is any propositional symbol) The truth assignment of conjunction, , is T only when both conjuncts have truth value T; otherwise, it is F.

Ch 2 The Predicate Calculus

15

Ch 2 The Predicate Calculus

16

2.1.2 Semantics
DEFINITION : PROPOSITIONAL CALCULUS SEMANTICS

2.1.2 Semantics
DEFINITION : PROPOSITIONAL CALCULUS SEMANTICS

The interpretation or truth value for sentences is determined by:

The truth assignment of disjunction, , is F only when both disjuncts have truth value F; otherwise, it is T. The truth assignment of implication, , is F only when the premise or symbol before the implication is T and the truth value of the consequent or symbol after the implication is F; otherwise, it is T.
Ch 2 The Predicate Calculus 17

The interpretation or truth value for sentences is determined by: The truth assignment of equivalence, , is T only when both expressions have the same truth assignment for all possible interpretations; otherwise, it is F.

Ch 2 The Predicate Calculus

18

2.1.2 Semantics
Truth table List all possible truth value assignments to the atomic propositions of an expression Give the truth value of the expression for each assignment P Q PQ The truth table for P Q T T T T F F F T F F F F
A truth table enumerate all possible worlds of interpretation that may be given to an expression

2.1.2 Semantics
Two expressions in the propositional calculus are equivalent if they have the same value under all truth value assignments. This equivalence may be demonstrated using truth tables.
P Q

P PQ PQ

(PQ ) (PQ)

T T F F

T F T T T F F F F T T T T T T F T T T T Truth table demonstrating the equivalence of PQ and PQ


20

Ch 2 The Predicate Calculus

19

Ch 2 The Predicate Calculus

2.1.2 Semantics
These following equivalences can be proven: (P) P (PQ) (PQ) Contrapositive law: (PQ) (QP) Morgans law: (PQ)(PQ) (PQ)(PQ)

2.1.2 Semantics
These following equivalences can be proven: (Conti.) Commutative laws (P Q) (Q P) (P Q) (Q P) Associate laws (( P Q ) R ) ( P ( Q R )) (( P Q ) R ) ( P ( Q R )) Distribute laws P(Q R) (P Q) (P R) P (Q R) (P Q) (P R)
These identities can be used to change propositional calculus expressions into a syntactically different but logically equivalent form.
21 Ch 2 The Predicate Calculus 22

Ch 2 The Predicate Calculus

2.1.2 Semantics
Logic Theorist
(An early AI program, Newell and Simon, 1956)

Predicate Calculus

Designed by Newell, Simon and Shaw Use transformations between equivalent forms of expression To prove many of the theorem in Whitehead and Russells Principia Mathematica (1950)

Allen Netwell
Ch 2 The Predicate Calculus 23

Chapter 2 The Predicate Calculus

2.2 The predicate calculus


Propositional calculus Atomic symbol, P, denotes it rained on Tuesday. Drawback: There is no way to access the components of an individual assertion. Predicate calculus provides this ability. weather( tuesday, rain ) Predicate calculus also allows expressions to contain variable. weather( X, rain ), where X is a day of the week The statement weather( X, rain ) is true; i.e., it rains every day.
Ch 2 The Predicate Calculus 25

2.2 The predicate calculus


2.2.1 Syntax 2.2.2 Semantics 2.2.3 A Block World Example of Semantic Meaning

Ch 2 The Predicate Calculus

26

2.2.1 The syntax


Predicate calculus symbol Like a token in a programming language irreducible syntactic element (can not be broken into their component parts by the operations of the language) Strings of letters and digits (beginning with a letter) Blanks and nonalphanumeric characters cannot appear within the string The underscore, _, may be used to improve readability.
Ch 2 The Predicate Calculus 27

2.2.1 The syntax


Legitimate characters in a symbol
a R6 9 p _ z

Examples of characters not in the alphabet include


# % @ / &

Legitimate symbols
George fire tom_and jerry bill XXXX friends_of

Examples of strings that are not legal symbols


3jack no blanks allow ab%cd ***71 duck!!!

Symbols are used to denote objects, properties, or relations


Ch 2 The Predicate Calculus 28

2.2.1 The syntax


DEFINITION: PREDICATE CALCULUS SYMBOLS

2.2.1 The syntax


Readability of expressions (for human readers) l(g,k) vs. likes(george, kate) Symbols intended meaning assists us in understanding the program code The only meaning that predicate calculus expressions may be said to have is through their formal semantics Improper symbols Parentheses ( ) , Commas , , Period . Used only to construct well-formed expressions Do not denote objects or relations (improper)
29 Ch 2 The Predicate Calculus 30

alphabet : make up the symbols, consists of: 1. The set of letters, both upper- and lowercase, of the English alphabet. 2. The set of digits, 0, 1, 2, 9. 3. The underscore, _ . Symbols begin with a letter and followed by any sequence of these legal characters
Ch 2 The Predicate Calculus

Predicate calculus symbols


Predicate calculus symbol Constant

Predicate calculus symbols


Constant 1. Specific object or property in the world

Variable

2. Must begin with a lowercase letter 3. Constant true and false are reserved for truth symbols O: geroge, tree, tall, blue

Function

Predicate

Ch 2 The Predicate Calculus

31

Ch 2 The Predicate Calculus

32

Predicate calculus symbols


Variable 1. Used to designate general classes of objects or properties 2. Must begin with a uppercase letter O: George, BILL, KAte, X: geORGE, bill

Predicate calculus symbols


Function
domain domain mapping range range
objects

1. Must begin with a lowercase letter 2. Denote a mapping of one or more elements (in the domain) to a unique element (in the range) 3. Arity: indicate the number of elements in the domain mapped onto each element of the range. 4. Function expression: a function symbol followed by its arguments (enclosed in parentheses and separated by commas)
33 Ch 2 The Predicate Calculus 34

Ch 2 The Predicate Calculus

Predicate calculus symbols


Function The act of replacing a function with its value is called evaluation. O: f(X,Y), father(david), price(banana). george = father ( david )
value function symbol argument

2.2.1 The syntax


DEFINITION: SYMBOLS and TERMS

Predicate calculus symbols include: 1. Truth symbols true and false (these are reserved symbols). 2. Constant symbols are symbol expressions having the first character lowercase. 3. Variable symbols are symbol expressions beginning with an uppercase character. 4. Function symbols are symbol expressions having the first character lowercase. Functions have an attached arity indicating the number of elements of the domain mapped onto each element of the range.
35 Ch 2 The Predicate Calculus 36

Ch 2 The Predicate Calculus

2.2.1 The syntax


DEFINITION: SYMBOLS and TERMS (Conti.)

Predicate calculus symbols


Predicate Symbols in predicate calculus may also represent predicates. A predicate names a relationship between zero or more objects. 1. Must begin with a lowercase letter 2. Arity of the predicate: the number of related objects Example: likes equals on near part_of

A function expression consists of a function constant of arity n, followed by n terms, t1, t2,, tn , enclosed in parentheses and separated by commas. A predicate calculus term is either a constant, variable, or function expression.
objects and properties ( in the problem domain )
cat times(2, 3) X
Ch 2 The Predicate Calculus

blue mother(jane) kate


37

Ch 2 The Predicate Calculus

38

Predicate calculus symbols


Predicate Atomic sentence: the most primitive unit of the predicate calculus language, is a predicate of arity n followed by n term enclosed in parentheses and separated by commas.
Predicate symbol

Predicate calculus symbols


Predicate A predicate relation is defined by its name and arity. likes(george, sarah, tuesday) Arity: 3 likes(george,susie) Arity: 2 It is considered to represent two different relations. (avoid confusion) Arguments [ may be constant symbols ] may also include variables or function expressions
likes(X, george)
constant symbol
39 Ch 2 The Predicate Calculus

Example: likes(X,X)

likes(george,kate)

likes(X, george)

likes(george,susie)

likes(george, sarah, tuesday) helps(richard, bill)

friends(bill, george)
Argument constant symbol (present object)

friends(bill,richard) helps(bill, george)

friends(father_of(david), father_of(andrew))

friends(father_of(david), father_of(andrew))
evaluation friends( george, allen )
40

Ch 2 The Predicate Calculus

2.2.1 The syntax


DEFINITION: PREDICATE and ATOMIC SENTENCES

2.2.1 The syntax


Sentence

Predicate symbols are symbols beginning with a lowercase letter. Predicates have an associated non-negative integer referred to as the arity or argument number for the predicate. Predicates with the same name but different arities are considered distinct. An atomic sentence is a predicate constant of arity n, followed by n terms, t1, t2, tn, enclosed in parentheses and separated by commas. The truth values, true and false, are also atomic sentences.
Ch 2 The Predicate Calculus 41

Atomic sentences are also called atomic expressions, atoms, or propositions.

Atomic sentence

Logical operator

Atomic sentence

, , , ,
Same logical connectives used in propositional calculus
Ch 2 The Predicate Calculus 42

2.2.1 The syntax


Sentence

domain domain

mapping

range range

2.2.1 The syntax


Sentence

Variable (in a sentence) refers to unspecified objects in the domain. Variable quantifier and constrain the meaning of a sentence containing a variable. A quantifier is followed by a variable and a sentence.

Universal quantifier, indicated that the sentence is true for all values of the variable.

X likes(X, ice_cream)
Existential quantifier, indicated that the sentence is true for at least one value in the domain. Y friends(Y, peter) is true There is at least one object, indicated by Y that is a friend of peter
44

Y friends(Y, peter) X likes(X, ice_cream)


Ch 2 The Predicate Calculus 43

Ch 2 The Predicate Calculus

2.2.1 The syntax


DEFINITION: PREDICATE CALCULUS SENTENCES

2.2.1 The syntax


example well-formed sentences: Let times and plus be function symbols of arity 2 and let equal and foo be predicate symbols with arity 2 and 3, respectively. plus(two, three) equal( plus(two, three), five) equal( plus(two, three), seven)
Not an atomic sentence an atomic sentence an atomic sentence

Every atomic sentence is a sentence.

1. 2. 3. 4. 5. 6. 7.

If s is a sentence, then so is its negation, s. If s1 and s2 are sentences, then so is their conjunction, s1 s2. If s1 and s2 are sentences, then so is their disjunction, s1 s2. If s1 and s2 are sentences, then so is their implication, s1 s2. If s1 and s2 are sentences, then so is their equivalence, s1 s2. If X is a variable and s is a sentence, then X s is a sentence. If X is a variable and s is a sentence, then X s is a sentence.

X foo (X, two, plus(two,three)) equal ( plus(two, three), five)


a sentence

(foo(two,two,plus(two,three))) (equal(plus(three,two),five) true )


a sentence
46

Ch 2 The Predicate Calculus

45

Ch 2 The Predicate Calculus

2.2.1 The syntax


Recursive algorithm: verify_sentence(expression) for verifying that an expression is a sentence. function verify_sentence(expression); begin case expression is an atomic sentence: return SUCCESS; expression is of the form Q X s , where Q is either or , X is a variable, and s is a sentence: if verify_sentence(s) returns SUCCESS then return SUCCESS else return FAIL; expression is of the form s: if verify_sentence(s) returns SUCCESS then return SUCCESS else return FAIL;
Ch 2 The Predicate Calculus 47

2.2.1 The syntax


Recursive algorithm: verify_sentence(expression) expression is of the form s1 op s2, where op is a binary logical operator: if verify_sentence(s1) returns SUCCESS and verify_sentence(s2) returns SUCCESS then return SUCCESS else return FAIL; otherwise: return FAIL end end.
(Conti.)

Ch 2 The Predicate Calculus

48

2.2.1 The syntax


example use predicate calculus to describe a simple world.

2.2 The predicate calculus


2.2.1 Syntax 2.2.2 Semantics 2.2.3 A Block World Example of Semantic Meaning
Ch 2 The Predicate Calculus 50

A set of family relationships in a biblical genealogy mother(eve, abel) mother(eve,cain) father(adam, abel) father(adam,cain) X Y (father(X, Y) mother(X, Y) parent(X, Y)) X Y Z (parent(X, Y) parent(X, Z) sibling(Y, Z)) sibling(cain, abel)
Ch 2 The Predicate Calculus 49

Parent-child relationship

2.2.2 The Semantics


Predicate calculus semantics provide a formal basis for determining the truth value of well-formed expressions. Information about a person, George, and his friends Kate and Susie may be expressed by friends(george, susie) friends(george, kate)
If it is true that then George is a friend of Susie George is a friendfriend of Kate NOT a of Kate

2.2.2 The Semantics


Using predicate calculus as a representation for problem solving:
Database: Predicate calculus expressions Each having truth value T Example clear(c) clear(a) ontable(a) ontable(b) on(c,b) cube(a) cube(b) pyramid(c) describe a describe

state of the world objects and relations

A BLOCK WORLD c b
52

friends(george, susie) has a truth value T friends(george, kate) has a truth value T F
51

Ch 2 The Predicate Calculus

Ch 2 The Predicate Calculus

2.2.2 The Semantics


DEFINITION: INTERPRETATION

domain domain

mapping

range range

2.2.2 The Semantics


DEFINITION: TRUTH VALUE OF PREDICATE CALCULUS EXPRESSIONS

Let the domain D be a nonempty set. An interpretation over D is an assignment of the entities of D to each of the constant, variable, predicate, and function symbols of a predicate calculus expression, such that:
1. Each constant is assigned an element of D. 2. Each variable is assigned to a nonempty subset of D; these are the allowable substitutions for the variable. 3. Each function f of arity m is defined on m arguments from D and defines a mapping from Dm into D. 4. Each predicate p of arity n is defined on n arguments from D and defines a mapping from Dn into {T, F}.
Ch 2 The Predicate Calculus 53

Assume an expression E and an interpretation I for E over a nonempty domain D. The truth value for E is determined by: 1. The value of a constant is the element of D it is assigned to by I. 2. The value of a variable is the set of elements of D it is assigned to by I. 3. The value of a function expression is that element of D obtained by evaluating the function for the parameter values assigned by the interpretation.
Ch 2 The Predicate Calculus 54

2.2.2 The Semantics


DEFINITION: TRUTH VALUE OF PREDICATE CALCULUS EXPRESSIONS

2.2.2 The Semantics


DEFINITION: TRUTH VALUE OF PREDICATE CALCULUS EXPRESSIONS

The truth value for E is determined by: 4. The value of truth symbol true is T and false is F. 5. The value of an atomic sentence is either T or F, as determined by the interpretation I. 6. The value of the negation of a sentence is T if the value of the sentence is F and is F if the value of the sentence is T. 7. The value of the conjunction of two sentences is T if the values of both sentences is T and is F otherwise.
Ch 2 The Predicate Calculus 55

The truth value for E is determined by: 8. - 10. The truth value of expressions using , , and is determined from the value of their operands as defined in Section 2.1.2. Finally, for a variable X and a sentence S containing X : 11. The value of X S is T if S is T for all assignments to X under I, and it is F otherwise. 12. The value of X S is T if there is an assignment to X in the interpretation under which S is T; otherwise it is F.
Ch 2 The Predicate Calculus 56

2.2.2 The Semantics


Quantification of variables is an important part of predicate calculus semantics.
kate Under the interpretation

2.2.2 The Semantics


Quantification

In the predicate calculus, variables must be quantified in either of two ways: universally or existentially.
Free variable

likes(george, X) likes(george, kate) likes(george, X ) likes(george, PEOPLE ) have the same meaning

A variable is considered free if it not within the scope of either the universal or existential quantifiers.
Closed expression

An expression is closed if all of its variables are quantified.


Ground expression

The variable is said to be a dummy.


Ch 2 The Predicate Calculus 57

A ground expression has no variables at all.


Ch 2 The Predicate Calculus 58

2.2.2 The Semantics


Universal quantification Universal quantifier ( for all ) X ( p (X) q ( Y ) r( X ) )
Using parentheses to indicate the scope of quantification. X is universally quantified in both p(X) and r(X).

2.2.2 The Semantics


Existential quantification Existential quantifier ( exist at least one )

The expression containing the variable is said to be true for at least one substitution from the domain of definition.
Computing problem

Computing problem

All the possible values of a variable symbol must be tested to see whether the expression remains true. X likes( george, X )

If the domain of an interpretation is infinite, exhaustive testing of all substitutions All humans to a universal quantified variable is computationally impossible: the algorithm may never halt. Because of the problem, the predicate calculus is said to be undecidable.
Ch 2 The Predicate Calculus 59

If the domain of the variable is infinite, and the expression is false under all substitutions, the algorithm will never halt.

Ch 2 The Predicate Calculus

60

2.2.2 The Semantics


Relationships between negation and the universal and existential quantifiers for predicates p and q and variables X and Y. X p(X) X p(X) X p(X) X p(X) X p(X) Y p(Y) X q(X) Y q(Y) X ( p(X) q(X) ) X p(X) Y q(Y) X ( p(X) q(X) ) X p(X) Y q(Y)

2.2.2 The Semantics


If it doesnt rain on Monday, Tom will go to the mountains. weather(rain, monday) go(tom, mountains) Emma is a Doberman pinscher and a good dog. Gooddog(emma) isa(emma, doberman) All basketball players are tall. X (basketball_player(X) tall(X))

http://www.petsmart.com/aspca/images/dogs/doberman_pinscher.jpg
Ch 2 The Predicate Calculus 61 Ch 2 The Predicate Calculus 62

2.2.2 The Semantics


Some people like anchovies. X (person(X) likes(X, anchovies))
Anchoa lucida (Jordan & Gilbert, 1882)

2.2.2 The Semantics


http://www.sealitsoc.org/images/scanned/bay_anchovy.jpg http://www.ikoreaplaza.com/

http://www.charterboats-uk.co.uk/Z%20-%20Fish%20Identification.htm
Ch 2 The Predicate Calculus

Green olives and anchovy cream http://usa.oliviersandco.com/browse.cfm/4,40.html


Ch 2 The Predicate Calculus 64

anchovy

63

2.2.2 The Semantics


If wishes were horses, beggars would ride. Equal(wishes, horse) ride(beggars) Nobody likes taxes. X likes(X, taxes)

2.2 The predicate calculus


2.2.1 Syntax 2.2.2 Semantics 2.2.3 A Block World Example of Semantic Meaning
65 Ch 2 The Predicate Calculus 66

Ch 2 The Predicate Calculus

2.2.3 A blocks world exampleof semantic meaning


Suppose we want to model the blocks world to design a control algorithm for a robot arm. c a b d
on(c,a) on(b,d) ontable(a) ontable(d) clear(b) clear(c) hand_empty

2.2.3 A blocks world example


The arm can move the blocks, it can change the state of the world and clear a block. on(c,a) on(b,d) ontable(a) ontable(d) clear(b) clear(c) hand_empty

c a

b d

Figure 2.3 A blocks world with its predicate calculus description

This set of blocks offers an interpretation and a possible model for the set of predicate calculus. The predicate calculus is declarative, i.e., there is no assumed timing or order for considering each expression.
Ch 2 The Predicate Calculus 67

To pick up a block and stack it on another block, both blocks must be clear. Suppose it removes block c from block a and updates the knowledge base to reflect this by deleting the assertion on(c,a). The program needs to be able to infer that block a has become clear.
Ch 2 The Predicate Calculus 68

2.2.3 A blocks world example


c a b d
on(c,a) on(b,d) ontable(a) ontable(d) clear(b) clear(c) hand_empty

2.2.3 A blocks world example


X ( Y on(Y, X) clear(X) ) X ( Y on(Y, X) clear(X) )
This rule describes when a block is clear. For all X, X is clear if there does not exist a Y such that Y is on X. This rule not only defines what it means for a block to be clear but also provides a basis for determining how to clear blocks that are not.
1

b c a d

on(c,a) on(b,d) ontable(a) ontable(d) ontable(c)

clear(b) clear(c) hand_empty clear(a)

c a
69

b d

Example: Block d is not clear. because: X -> d , Y --> b on(b, d) is false To make it true on(b,d) should be delete b must be removed from d
70

Ch 2 The Predicate Calculus

Ch 2 The Predicate Calculus

2.2.3 A blocks world example


X Y ( ( hand_empty clear (X) clear (Y) X Y ( ( hand_empty clear (X) clear (Y) pick_up(X) put_down(X, Y) ) stack(X, Y) ) pick_up(X) put_down(X, Y) ) stack(X, Y) ) This rule describes operations such as stacking one block on top to another. To stack X on Y: first empty the hand, then clear X, then clear Y and then pick_up X and put_down X on Y

Using inference rules to produce predicate calculus expressions

Ch 2 The Predicate Calculus

71

Chapter 2 The Predicate Calculus

2.3 Using inference rules

to produce predicate calculus expressions

2.3.1 Inference rules 2.3.2 Unification 2.3.3 A Unification Example

2.3 Using inference rules 2.3.1 Inference rules

to produce predicate calculus expressions

The semantics of the predicate calculus provides a basis for a formal theory of logical inference.
Consistent

A set of true assertion

infer

new correct expression

This ability is an important feature of the predicate calculus

Ch 2 The Predicate Calculus

73

Ch 2 The Predicate Calculus

74

2.3.1 Inference rules


An interpretation that makes a sentence true is said to satisfy that sentence. An interpretation that satisfies every member of a set of expressions is said to satisfy the set. An expression X logically follows from a set of predicate calculus expressions S if every interpretation that satisfies S also satisfies X.

2.3.1 Inference rules


X logically follows S X logically follows S
This notion gives us a basis for verifying the correctness of rules of inference.
logically follows S X

infer

The function of logical inference is to produce new sentences that logically follow a given set of predicate calculus sentences.
75 Ch 2 The Predicate Calculus 76

Ch 2 The Predicate Calculus

2.3.1 Inference rules


An inference rule is essentially a mechanical means of producing new predicate calculus sentence from other sentences, i.e., inference rules produce new sentences based on the syntactic form of given logical assertions. Sound inference rule Sound inference rule
When every sentence X ( produced by an inference rule operating on a set S of logical expressions ) logically follows from S, the inference rule is said to be sound.

2.3.1 Inference rules


DEFINITION: SATISFY, MODEL

For a predicate calculus expression X and an interpretation I If X has a value of T under I and a particular variable assignment, then I is said to satisfy X. If I satisfies X for all variable assignments, then I is a model of X.
X is satisfiable if and only if there exist an

Complete inference rule Complete inference rule


If the inference rule is able to produce every expression that logically follows from S, then it is said to be complete.
Ch 2 The Predicate Calculus 77

interpretation and variable assignment that satisfy it; otherwise, it is unsatisfiable.


Ch 2 The Predicate Calculus 78

2.3.1 Inference rules


DEFINITION: SATISFY, VALID, INCONSISTENT

2.3.1 Inference rules


X ( p(X) p(X)) inconsistent

For a predicate calculus expression X and an interpretation I A set of expression is satisfiable if and only if there exist an interpretation and variable assignment that satisfy every element. If a set of expression is not satisfiable, it is said to be inconsistent. If X has a value T for all possible interpretation, X is said to be valid.

X ( p(X) p(X)) valid

Ch 2 The Predicate Calculus

79

Ch 2 The Predicate Calculus

80

logically follows

2.3.1 Inference rules


DEFINITION: PROOF PROCEDURE

E1 E2 E2 E3

infer

E1 E3

2.3.1 Inference rules

infer

DEFINITION: LOGICALLY FOLLOWS, SOUND, and COMPLETE

A proof procedure is a combination of an inference rule and an algorithm for applying that rule to a set of logical expressions to generate new sentences. We present proof procedures for the resolution inference rule in Chapter 12.
Proof procedure inference rule

A set of logical expressions


Ch 2 The Predicate Calculus

Algorithm

New sentence
81

A predicate calculus expression X logically follows from a set S of predicate calculus expression if every interpretation and variable assignment that satisfies S also satisfies X. An inference rule is sound if every predicate calculus expression produced by the rule from a set S of predicate calculus expression also logically follows from S. An inference rule is complete if, given a set S of predicate calculus expressions, the rule can infer every expression that logically follows from S.
Ch 2 The Predicate Calculus 82

2.3.1 Inference rules


DEFINITION: MODUS PONENS, MODUS TOLLENS, and AND ELIMINATION.

2.3.1 Inference rules


DEFINITION: AND INTRODUCTION and UNIVERSAL INSTANTIATION

If the sentences P and P Q are known to be true, then modus ponens let us infer Q. Under the inference rule modus tollens, if P Q is known to be true and Q is known to be false, we can infer P. And elimination allows us to infer the truth of either of the conjuncts from the truth of a conjunctive sentence. For instance, P Q let us conclude P and Q are true.
Ch 2 The Predicate Calculus 83

And introduction lets us infer the truth of conjunction from the truth of its conjuncts. For instance, if P and Q are true, then P Q is true. Universal instantiation states that if any universally quantified variable in a true sentence is replaced be any appropriate term from the domain, the result is a true sentence. Thus, if a is from the domain of X, X p(X) let us infer p(a).
Ch 2 The Predicate Calculus 84

2.3.1 Inference rules


P
F F T T

2.3.1 Inference rules


Example: the use of modus ponens in the propositional calculus: Our observations: P Q : If it is raining then the ground will be wet P : It is raining.
PQ P set of true expression PQ P Q set of true expression modus ponens Q

P T T F F

Q T F T F

-Q F T F T

PQ P Q -Q-P T F T T T F F F T F T T

Ch 2 The Predicate Calculus

85

Ch 2 The Predicate Calculus

86

2.3.1 Inference rules


Example: the use of modus ponens in expressions containing variables Syllogism: all men are mortal and Socrates is a man; therefore Socrates is mortal
All men are mortal Socrates is man X (man(X) mortal (X)) man(socrates)

2.3.1 Inference rules


X (man(X) mortal (X)) man(socrates) set of true expression X (man(X) mortal (X)) man(Socrates) mortal (Socrates) man(socrates) universal instantiation (man(Socrates) mortal (Socrates))

X (man(X) mortal (X)) man(socrates) set of true expression


Ch 2 The Predicate Calculus 87 Ch 2 The Predicate Calculus

88

2.3.1 Inference rules


X (man(X) mortal (X)) man(Socrates) mortal (Socrates) man(socrates) set of true expression X (man(X) mortal (X)) man(Socrates) mortal (Socrates) man(socrates) mortal(socrates) set of true expression
Ch 2 The Predicate Calculus 89

2.3 Using inference rules


modus ponens

to produce predicate calculus expressions

mortal(socrates)

2.3.1 Inference rules 2.3.2 Unification 2.3.3 A Unification Example

Ch 2 The Predicate Calculus

90

2.3.2 Unification
Are two expressions the same or match ?
Why ?

2.3.2 Unification
Are two expressions the same or match ? In propositional calculus: Two expressions match if and only if they are syntactically identical. In predicate calculus: ( the existence of variables in expression ) The process of match two sentences is complicated. Expression 1 Expression 2 Unification Unification (Algorithm) (Algorithm) Match or Not ?

For modus ponens inference rule PQ P


Q

infer

PQ P Q

For resolution inference rule E1 E2 E2 E3


E1 E3

infer

E1 E2 E2 E3 E1 E3

for determining the needed substitutions


91 Ch 2 The Predicate Calculus 92

Ch 2 The Predicate Calculus

2.3.2 Unification
Example 1: Example 1: Socrates in man(socrates) was substituted for X in X(man(X) mortal(X) Modus ponens : mortal(socrates)

2.3.2 Unification
Example 2: Example 2: p(X) and p(Y) are equivalent, Y may be substituted for X to make the sentences match.

man(socrates) man(X)

Unification Unification (Algorithm) (Algorithm)

Match, {socrates/X}

p(X) p(Y)

Unification Unification (Algorithm) (Algorithm)

Match, {Y/X}

Ch 2 The Predicate Calculus

93

Ch 2 The Predicate Calculus

94

2.3.2 Unification
Logical database must be expressed in an appropriate form: 1. All variables be universally quantified. 2. Existentially quantified variables may be eliminated from sentences in the database by replacing them with the constants that make the sentence true.
Existence qualified variable X

2.3.2 Unification
Unification is complicated: Some instances of the expression
Unification foo(X, a, goo(Y) parent(bob, tom) parent(mary, tom)
May be complicated.
95

1) foo(fred, a, goo(Z)
{ fred/X, Z/Y }

{ W/X, jack/Y }

2) foo(W, a, goo(jack))

X parent(X, tom)

{ Z/X, moo(Z)/Y }

3) foo(Z, a, goo(moo(Z)))

This assertion is true.


Ch 2 The Predicate Calculus

Unification are also referred to as bindings. A variable is said to be bound to the value substituted for it.
Ch 2 The Predicate Calculus 96

2.3.2 Unification
occurs check occurs check A variable cannot be unified with a term containing that variable. X cannot be replaced by p(X) as this creates an infinite expression: P(p(p(p(X)). The test for this situation is called the occurs check.

2.3.2 Unification
It is important that any unifying substitution be made consistently across all occurrences of the variable in both expression be matched. If a variable is bound to a constant, that variable may not be given a new binding in a future unification.

Ch 2 The Predicate Calculus

97

Ch 2 The Predicate Calculus

98

2.3.2 Unification
Composition of unification substitutions Composition of unification substitutions If S and S are two substitution sets, then the composition of S and S (written SS) is obtained by Applying S to the element of S and adding the result to S. Example: { X/Y, W/Z }, { V/X }, { a/V, f(b)/W } { V/Y, W/Z} {a/V. f(b)/W } So, these are equivalent to the single substitution. { a/Y, f(b)/Z }
Ch 2 The Predicate Calculus 99

2.3.2 Unification
Most General Unifier Most General Unifier A final requirement of the unification algorithm is that the unifier be as general as possible: that the most general unifier be found for the two expressions. This is important, because, if generality is lost in the solution process, it will lesson the scope of the eventual solution or even eliminate the possibility of a solution entirely.
input
100

Ch 2 The Predicate Calculus

2.3.2 Unification
Most General Unifier Most General Unifier < Example > In unifying p(X) and p(Y), and constant expression such as { fred/X, fred/Y } will do the trick. However, fred is not the most general unifier; any variable will work and produce a more general expression: {Z/X. Z/Y}. fred would be a unifier, but it would lessen the generality of the result.
Ch 2 The Predicate Calculus 101

2.3.2 Unification
DEFINITION: MOST GENERAL UNIFIER (mgu) (mgu)

If s is any unifier of expressions E and g is the most general unifier of that set of expressions, then for s applied to E there exists another unifier s such that Es = Egs, where Es and Egs are the composition of unifiers applied to the expression E.

Ch 2 The Predicate Calculus

102

2.3.2 Unification
function unify (E1, E2) function unify (E1, E2) Unify takes as arguments two expressions in the predicate calculus and return either the most general unifying substitutions or the constant FAIL if no unification is possible. Unify is defined as a recursive function. The recursion stop when either argument is a symbol or the elements of the expression have all been match.

2.3.2 Unification
By representing an expression as a list (an order sequence of elements) with the predicate or function name as the first element followed by its arguments, we simplify the manipulation of expressions.
PC SYNTAX PC SYNTAX LIST SYNTAX LIST SYNTAX

p ( a, b ) p ( f ( a ), g ( X, Y ) ) equal ( eve, mother(cain) )

(p a b) (p (fa) (gXY)) ( equal eve ( mother cain ) )

Ch 2 The Predicate Calculus

103

Ch 2 The Predicate Calculus

104

2.3.2 Unification
function unify (E1, E2) function unify (E1, E2)
begin case both E1 and E2 are constants or the empty list: %recursion stop if E1 = E2 then return {} else return FAIL; E1 is a variable: if E1 occurs in E2 then return FAIL % occurs check else return {E2/E1} E2 is a variable: if E2 occurs in E1 then return FAIL % occurs check else return {E1/E2} either E1 or E2 are empty: then return FAIL %the lists are of different sizes otherwise: [ ---- ] % both E1 and E2 are list end % end case end
Ch 2 The Predicate Calculus 105

2.3.2 Unification
function unify (E1, E2) function unify (E1, E2)
otherwise: begin HE1 := first element of E1; HE2 := first element of E2; SUBS1 := unify(HE1, HE2); if SUBS1 := FAIL then return FAIL; TE1 := apply(SUBS1, rest of E1) TE2 := apply(SUBS1, rest of E2) SUBS2 := unify(TE1, TE2); if SUBS2 := FAIL then return FAIL; else return composition(SUBS1, SUBS2) end
Ch 2 The Predicate Calculus 106

(Conti.)

2.3 Using inference rules

to produce predicate calculus expressions

2.3.3 A Unification Example


unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )). unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )). E1 : ( parents X (father X) (mother bill)) E2 : ( parents bill (father bill) Y ) << neither argument is an atomic symbol >> unify ( parents, parents) return empty substitution, {} << applying empty substitution {} to the remainder : no change >> unify ( (X (father X) (mother bill)), (bill (father bill) Y ) ) unify ( X , bill ) return substitution, {bill/X} << applying substitution {bill/X} to the remainder >> ((father X) (mother bill)) ----- > ((father bill) (mother bill)) ((father bill) Y ) ----- > ((father bill) Y)

2.3.1 Inference rules 2.3.2 Unification 2.3.3 A Unification Example

Ch 2 The Predicate Calculus

107

Ch 2 The Predicate Calculus

108

2.3.3 A Unification Example


1. unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )) Unify first elements and apply substitution to rest

2.3.3 A Unification Example


1. unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )) return {}

2. unify( parents, parents )

3. unify ( (X (father X) (mother bill)), (bill (father bill) Y ) ) return {} Unify first elements and apply substitution to rest return {bill/X} 4. unify ( X , bill ) 5. unify ( ((father bill) (mother bill)), ((father bill) Y ) )

2. unify( parents, parents ) 3. unify ( (X (father X) (mother bill)), (bill (father bill) Y ) )

Fig 2.4 Initial steps


Ch 2 The Predicate Calculus 109

Fig 2.5 Further steps


Ch 2 The Predicate Calculus 110

2.3.3 A Unification Example


unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )). unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )). unify ( ((father bill) (mother bill)), ((father bill) Y ) ) unify (( (father bill), (father bill) )) unify (father bill), (father bill) unify ( (father bill), (father bill) ) unify ( father, father ) unify ( (bill), (bill) ) return empty substitution, {} return empty substitution, {} return empty substitution, {} return empty substitution, {}
111

2.3.3 A Unification Example


unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )). unify(( parents X (father X) (mother bill)), (parents bill (father bill) Y )).

unify (( (( (mother bill)), (( Y )) )) unify (mother bill)), Y

unify (( (( (mother bill)), (( Y )) )) unify (mother bill)), Y unify ( ( (mother bill)), ( Y ) ) unify ( ( mother bill), Y ) unify ( (), () ) return substitution, { (mother bill)/Y } return empty substitution, {}

Finally, composition of {bill/X} and { (mother bill)/Y } unify ( bill, bill ) unify ( (), () )
Ch 2 The Predicate Calculus

return {{ bill/X, (mother bill)/Y }} return bill/X, (mother bill)/Y


Ch 2 The Predicate Calculus 112

Application: A Logic-based Financial Advisor

2.4 Application: to represent and reason about problem domains. A Logic-based Financial Advisor
1. Individuals with an inadequate savings account should always make increasing the amount saved their first priority, regardless of their income. 2. Individuals with an adequate savings account and an adequate income should consider a riskier but potentially more profitable investment in the stock market. 3. Individuals with a lower income who already have an adequate savings account may want to consider splitting their surplus income between savings and stocks, to increase the cushion in savings while attempting to increase their income through stocks.
Ch 2 The Predicate Calculus 114

The use of predicate calculus

Chapter 2 The Predicate Calculus

2.4 A Logic-based Financial Advisor


The adequacy of both savings and income is determined by the the number of dependents an individual must support. 1. Have at least $5,000 in the bank for each dependents 2. A steady income and supply at least $15,000 per year plus an additional $4,000 for each dependents. Constant: adequate, inadequate Major Features unary predicates: savings_account and income
saving_account(adequate), saving_account(inadequate) income(adequate), income(inadequate)
Ch 2 The Predicate Calculus 115

2.4 A Logic-based Financial Advisor


Conclusions unary predicate: investment investment(stocks), investment(savings), investment(combination). Investment strategies 1. savings_account(inadequate)investment(savings) 2. savings_account(adequate) income (adequate) investment(stocks) 3. savings_account(adequate) income (inadequate) investment(combination)
Ch 2 The Predicate Calculus 116

2.4 A Logic-based Financial Advisor


Is savings adequate or inadequate ? 4. X amount_saved(X) Y (dependents(Y) greater(X, minsavings(Y))) savings_account(adequate) 5. X amount_saved(X) Y (dependents(Y) greater(X, minsavings(Y))) savings_account(inadequate) where minsavings(Y) = 5000*Y amount_saved(X) : the current amount in savings dependents(Y) : the number of dependents of an investor greater(X, Y) : standard arithmetic test
Ch 2 The Predicate Calculus 117

2.4 A Logic-based Financial Advisor


Is income adequate or inadequate ? 6. X earnings(X, steady) Y (dependents(Y) greater(X, minincome(Y))) income(adequate) 7. X earnings(X , steady) Y (dependents(Y) greater(X, minincome(Y))) income(inadequate) 8. X earnings (X , unsteady) income(inadequate).
where minincome(Y) = 15000 + 4000* Y Binary predicate earnings
1. Amount earned 2. Constant: steady, or unsteady
Ch 2 The Predicate Calculus 118

2.4 A Logic-based Financial Advisor


Example: an individual with 3 dependents, $22,000 in savings, and a steady income of $25,000 9. amount_saved(22000) 10. earnings(25000, steady) 11. dependents(3) What is the logical system ?

2.4 A Logic-based Financial Advisor


The set of logical sentences describes the problem domain The set of logical sentences describes the problem domain
2. 2. 1. savings_account(inadequate)investment(savings) 1. savings_account(inadequate)investment(savings) savings_account(adequate) income (adequate) investment(stocks) savings_account(adequate) income (adequate) investment(stocks) savings_account(adequate) income (inadequate) investment(combination) savings_account(adequate) income (inadequate) investment(combination)
X amount_saved(X) Y (dependents(Y) greater(X, minsavings(Y))) X amount_saved(X) Y (dependents(Y) greater(X, minsavings(Y))) savings_account(adequate) savings_account(adequate) X amount_saved(X) Y (dependents(Y) greater(X, minsavings(Y))) X amount_saved(X) Y (dependents(Y) greater(X, minsavings(Y))) savings_account(inadequate) savings_account(inadequate) X earnings(X, steady) Y (dependents(Y) greater(X, minincome(Y))) X earnings(X, steady) Y (dependents(Y) greater(X, minincome(Y))) income(adequate) income(adequate)

3. 3.

4. 4. 5. 5. 6. 6.

7. 7.

X earnings(X , ,steady) Y (dependents(Y) greater(X, minincome(Y))) X earnings(X steady) Y (dependents(Y) greater(X, minincome(Y))) income(inadequate) income(inadequate) 8. X earnings (X , ,unsteady) income(adequate) 8. X earnings (X unsteady) income(adequate)

9. amount_saved(22000) 9. amount_saved(22000) 10. earnings(25000, steady) 10. earnings(25000, steady) 11. dependents(3) 11. dependents(3)

Ch 2 The Predicate Calculus

119

Ch 2 The Predicate Calculus

120

2.4 A Logic-based Financial Advisor


Using unification and modus ponens, a correct investment strategy for this individual may be inferred: Step 1
Unify the conjunction of 10 and 11 with the first two components of the premise of 7 earnings(25000, steady) dependents(3) earnings(X, steady) dependents(Y)
{ 25000/X, 3/Y }

2.4 A Logic-based Financial Advisor


Step 2
Unify the conjunction of 9 and 11 with the first two components of the premise of 4 amount_saved(22000) dependents(3) amount_saved(X) dependents(Y) 4.
15000 amount_saved(22000) amount_saved(22000) dependents(3) greater(22000, minsavings(3) ) dependents(3) greater(22000, minsavings(3) ) savings_account(adequate) savings_account(adequate) { 22000/X, 3/Y }

7.

27000 earnings(25000 ,, steady) earnings(25000 steady) dependents(3) greater(25000, minincome(3) ) dependents(3) greater(25000, minincome(3) ) income(inadequate) income(inadequate)

new assertion 13. savings_account(adequate)


121 Ch 2 The Predicate Calculus 122

new assertion 12. income(inadequate)


Ch 2 The Predicate Calculus

2.4 A Logic-based Financial Advisor


Step 3
3, 12, 13 modus ponens Conclusion: investment(combination)

income(inadequate) savings_account(adequate) income(inadequate) savings_account(adequate) investment(combination) investment(combination) This example illustrates how predicate calculus may be used to reason about a realistic problem, drawing correct conclusions by applying inference rule to the initial problem description. We have NOT discussed exactly how the algorithm can determine the correct inferences to make to solve a given problem or the way in which this can be implemented on a computer?
Ch 2 The Predicate Calculus 123

Das könnte Ihnen auch gefallen