Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reasoning using First-Order Logic

Similar presentations


Presentation on theme: "Reasoning using First-Order Logic"— Presentation transcript:

1 Reasoning using First-Order Logic

2 sen  sen’, sen  sen’, sen  sen’
Sentences A predicate is a sentence If sen, sen’ are sentences & x a variable, then (sen), sen, x sen, x sen, sen  sen’, sen  sen’, sen  sen’ are sentences Nothing else is a sentence

3 Examples of Sentences Birthday( x, y) – x celebrates birthday on date y y x Birthday (x, y) – For all dates, there exists a person who celebrates his/her Birthday on that date. That is – “everyday someone celebrates his/her Birthday”

4 x y Brother (x, y)  Loves (x, y)
Examples (contd.) Brother( x, y) – x is y’s brother Loves (x, y) – x loves y x y Brother (x, y)  Loves (x, y) Everyone loves (all of) his/her brothers. Let m (x) represent mother of x then “everyone loves his/her mother” is x Loves (x, m (x) )

5 x equal (x, succ ( pred (x) )
Examples (contd.) Any number is the successor of its predecessor succ (x), pred (x), equal (x, y) x equal (x, succ ( pred (x) )

6 Alternative Representation
The previous example can be represented succinctly as x (succ ( pred (x ) = x) Not Allowed in predicates

7 term = term is also a sentence
FOL with Equality In FOL with equality, we are allowed to use the equality sign (=) between two functions. This is just for representational ease We modify the definition of sentence to include equality as term = term is also a sentence

8 Quiz Revisited x (dog(x)  bark(x)) Some dogs bark
All dogs have four legs x (dog(x)  have_four_legs (x) x (dog(x)  legs (x,4) All barking dogs are irritating Do it yourself

9 No dogs purr ¬ x (dog(x)  purr(x)) Fathers are male parents with children x (father(x)  male(x)  has_children(x)) Students are people who are enrolled in courses Do it yourself

10 Inference Rules Universal Elimination x Likes (x, flower)
substituting x by Shirin gives Likes (Shirin, flower) The substitution should be done by a constant term

11  x Likes (x, flower)  Likes (Person, flower)
Inference Rules Existential Elimination (Skolemization)  x Likes (x, flower)  Likes (Person, flower) as long as person is not in the knowledge base Existential Introduction Likes (Shahid, flower) can be written as  x Likes (x, flower)

12 Reasoning in FOL Consider the following problem:
If a perfect square is divisible by a prime p, then it is also divisible by square of p. Every perfect square is divisible by some prime. 36 is a perfect square. Does there exist a prime q such that square of q divides 36?

13 Representation in FOL If a perfect square is divisible by a prime p, then it is also divisible by square of p. x,y perfect_sq (x)  prime (y)  divides (x,y)  divides (x, square (y)) Every perfect square is divisible by some prime. x y perfect_sq (x)  prime (y)  divides (x,y)

14 y prime (y)  divides (36,square(y))
Representation in FOL 36 is a perfect square. perfect_sq (36) Does there exist a prime q such that the square of q divides 36? y prime (y)  divides (36,square(y))

15 The Knowledge base x,y perfect_sq (x)  prime (y)
 divides (x,y)  divides (x, square (y)) x y perfect_sq (x)  prime (y)  divides (x,y) perfect_sq (36)

16 Inferencing From 2 and Universal Elimination
(4) y perfect_sq (36)  prime (y)  divides (36, y) From 4 and Existential Elimination (5) perfect_sq (36)  prime (P)  divides (36, P) From (1) and (5) (6) divides (36, square(P))

17 Inferencing (contd.) From (5) and (6)
(7) prime (P)  divides (36, square(P)) From (7) and Existential Introduction y prime (y)  divides (36, square(y))

18 Inferencing (contd.) However, inferencing would have been easier if the knowledge base consists of the following sentences perfect_sq(36) prime(P) divides(36,P) x,y perfect_sq (x)  prime (y)  divides (x,y)  divides (x, square (y))

19 Horn Sentences atomic sentences perfect_sq (36)
implication with a conjunction of atomic sentences on the left and a single atom on the right x,y perfect_sq (x)  prime (y)  divides (x,y)  divides (x, square (y)) No Existential Quantifier

20 Conversion to Horn Sentences
Existential Quantifiers can be removed using Existential Elimination (Skolemization) If the existential quantifier is outside any universal quantifier, a Skolem constant is introduced. E.g. y prime (y)  prime(P), where P is a Skolem constant Otherwise a Skolem function is introduced. E.g. x y prime (y)  divides (x,y)  x prime(PD(x))  divides (x,PD(x)) , where PD(x) is a Skolem function

21 Conversion to Horn Sentences
And-Elimination prime (P)  divides (x,P) can be written as two clauses prime (P) divides (x,P)

22 Substitution Substitution replaces variables with constants.
SUBST ({x/49}, Perfect_sq(x)) = Perfect_sq(49) SUBST ({x/49, y/7}, Divides(x,y)) = Divides(49, 7)

23 Unification Unification is the Process of finding a substitution that makes two atomic sentences identical. UNIFY (Prime(7), Prime(x)) = {x/7} UNIFY (Divides(49,x), Divides (y,7)) = {y/49, x/7} UNIFY (Prime(7),Prime(17) – Impossible! UNIFY (Divides(49,x), Divides (x,7)) – Impossible!     

24 Inference through Resolution in First Order Predicate Logic

25 Resolution – A technique of Inference
A sound inference mechanism Principle: Suppose x is a literal and S1 and S2 are two sets of propositional sentences represented n clausal form If we have (x V S1) AND (x V S2 ) Then we get S1 V S2 Here S1 V S2 is the resolvent, x is resolved upon

26 An Example If a triangle is equilateral then it is isosceles
If a triangle is isosceles then two sides AB and AC are equal If AB and AC are equal then angle B and angle C are equal ABC is an equilateral triangle Angle B is equal to angle C -- Prove

27 Equilateral (ABC)  Isosceles (ABC)
If a triangle is equilateral then it is isosceles Equilateral (ABC)  Isosceles (ABC) If a triangle is isosceles then two sides AB and AC are equal Isosceles (ABC)  Equal (AB,AC) If AB and AC are equal then angle B and angle C are equal Equal (AB,AC)  Equal (B,C) ABC is an equilateral triangle Equilateral (ABC)

28 1. Equilateral (ABC)  Isosceles (ABC)
Clausal Form 1. Equilateral (ABC)  Isosceles (ABC)  Equilateral (ABC) V Isosceles (ABC) 2. Isosceles (ABC)  Equal (AB,AC)  Isosceles (ABC) V Equal (AB,AC) 3. Equal (AB,AC)  Equal (B,C) Equal (AB,AC)  Equal (B,C) 4. Equilateral (ABC)

29 Proof by refutation To prove Angle B is equal to Angle C Equal (B,C)
Let us disprove Not equal (B,C) Equal (B,C) Let us try to disprove this

30  Equal (AB,AC) Isosceles (ABC) Equilateral (ABC) V Isosceles (ABC)
Isosceles (ABC) V Equal (AB,AC) Equal (AB,AC) V Equal (B,C) Equilateral (ABC) Equal (AB,AC) V Equal (B,C) Equal (B,C) Isosceles (ABC) V Equal (AB,AC)  Equal (AB,AC) Isosceles (ABC)

31  Equal (AB,AC) V Equal (B,C)
Isosceles (ABC) Equilateral (ABC) V Isosceles (ABC)  Isosceles (ABC) V Equal (AB,AC)  Equal (AB,AC) V Equal (B,C) Equilateral (ABC) Equilateral (ABC) V Isosceles (ABC) Equilateral (ABC) Equilateral (ABC) Null clause

32 Procedure for Resolution
Convert given propositions into clausal form Convert the negation of the sentence to be proved into clausal form Combine the clauses into a set Iteratively apply resolution to the set and add the resolvent to the set Continue until no further resolvents can be obtained or a null clause is obtained

33 What is it for Predicate Logic

34 A Few Statements All people who are graduating are happy.
All happy people smile. Someone is graduating. Is someone smiling? (Conclusion)

35 Solving the problem We intend to code the problem in predicate calculus. Use resolution refutation to solve problem Solving ≈ whether the conclusion can be answered from the given set of sentences.

36 Selecting the Predicates
graduating (x) : x is graduating Happy (x) : x is happy Smiling (x) : x is smiling

37 Encoding sentences in Predicate Logic
All people who are graduating are happy (x) [graduating (x)  happy (x)] All happy people smile (x) [happy (x)  smiling (x)] Someone is graduating (x) graduating (x) Is someone smiling (x) smiling (x)

38 Predicates (x) graduating (x)  happy (x)
(x) happy (x)  smiling (x) (x) graduating (x)  (x) smiling (x) ( Negating the conclusion)

39 Converting to Clausal form
Step 1: Eliminate  (x)  graduating (x)  happy (x) (x)  happy (x)  smiling (x) (x) graduating (x)  (x) smiling (x)

40 Converting to Canonical form
Step 2: Reduce the scope of negation (x)  graduating (x)  happy (x) (x)  happy (x)  smiling (x) (x) graduating (x) (x)  smiling (x)

41 Converting to Canonical form
Step 3: Standardize variables apart (x)  graduating (x)  happy (x) (y)  happy (y)  smiling (y) (z) graduating (z) (w)  smiling (w)

42 Converting to Canonical form
Step 4: Move all quantifiers to the left (x)  graduating (x)  happy (x) (y)  happy (y)  smiling (y) (z) graduating (z) (w)  smiling (w)

43 Converting to Canonical form
Step 5: Eliminate  ( Skolemization) (x)  graduating (x)  happy (x) (y)  happy (y)  smiling (y) graduating (name1) ( name1 is the skolemization constant) (w)  smiling (w)

44 Converting to Canonical form
Step 6. Drop all   graduating (x)  happy (x)  happy (y)  smiling (y) graduating (name1)  smiling (w)

45 Converting to Canonical form
Step 7. Convert to conjunct of disjuncts form Step 8. Make each conjunct a separate clause. Step 9. Standardize variables apart again. These steps do not change the set of clauses any further (in the present problem)

46 Resolution 4. smiling (w) 2.  happy (y)  smiling (y) {w/y}
5.  happy (w) 1.  graduating (x)  happy (x) {w/x} 6.  graduating (w) 3. graduating (name1) {name1/w} 7. Null clause

47 Quiz Solve the problem with resolution
If a perfect square is divisible by a prime p, then it is also divisible by square of p. Every perfect square is divisible by some prime. 36 is a perfect square. Does there exist a prime q such that square of q divides 36?

48 Answer Extraction

49 Find the Package Example (Nilsson)
We know that All packages in room 27 are smaller than those in room 28 Package A is either in room 27 or in room 28 Package B is in room 27 Package B is not smaller than Package A Where is Package A?

50 Answer extraction Suppose we wish to prove whether KB |= (u)f(u)
We are probably interested in knowing the w for which f(u) holds. Add Ans(u) literal to each clause coming from the negation of the theorem to be proven; stop resolution process when there is a clause containing only Ans literal

51 ¬P(x)  ¬ P(y)  ¬ I (x, 27)  ¬ I (y, 28)  S(x,y) 2. P(A) 3. P(B)
All packages in Room 27 are smaller than those in room 28 ¬P(x)  ¬ P(y)  ¬ I (x, 27)  ¬ I (y, 28)  S(x,y) 2. P(A) 3. P(B) 4. I(A,27)  I (A,28) 5. I(B,27) 6. ¬S (B,A) In which room is A? That is, Prove (u) I (A, u)

52 @Anupam Basu


Download ppt "Reasoning using First-Order Logic"

Similar presentations


Ads by Google