You are on page 1of 66

First-Order Logic

Study Material: •Section 2.2-2.4,Chapter 2 in Luger, Artificial Intelligence: Structures and Strategies •Example 3.3.5, Chapter 3 in Luger, Artificial Intelligence: Structures and Strategies, pp 115-116

CP468, Dr. Reem K. Al-Halimi

1

Propositional Logic
 Simple logic in which all sentences are assertions with

truth values.
 e.g. “it is raining”

 We cannot access the components of an individual

assertion
 e.g. if P represents “A bug is in my soup” we cannot

access the “bug” or “soup” components

 No variables are allowed

cannot create general

assertions about entities.
CP468, Dr. Reem K. Al-Halimi 2

Example 2 Blocks World
Goal: to create a set of expressions that is to represent a static snapshot of the blocks world. Assumption: predicates evaluated top-down, and left-right.
b c

a

d

CP468, Dr. Reem K. Al-Halimi

17

Dr.Example 2 Blocks World block X is on block Y on(X. Y) block X is on the table on_table(X) block X has nothing on top of it clear(x) the robot’s hand is empty hand_empty b c a d CP468. Reem K. Al-Halimi 18 .

<d. <b.<c.a>.<c.b>.c>.d>.d>} CP468.Y)? {<a.d} What are the possible interpretations for b c a d X and Y for on(X.c.a>.Y) true in this world? {<b.<d.c>.b.<b. <a. <c.a>.b>.d>. Reem K. Al-Halimi 19 .d>.<b. <c.<a.b>} Which interpretations make on(X.Example 2 Blocks World What is the domain of the variables X and Y in this world for the previous expressions? D={a. Dr.a>.

d) clear(b) clear(c) hand_empty CP468. Al-Halimi b c a d 20 .a) ontable(a) ontable(d) on(c.Example 2 Blocks World A description of this blocks world: on(b. Dr. Reem K.

Dr. Reem K.  the relations between them  and the functions that can be applied to them  Interpretations map the symbols of a language to the model:  constant symbols are mapped to objects  function symbols are mapped to functions  predicate symbols are mapped relations in the model.Models and Interpretations  Models are mathematical abstractions of the “possible world”.  Models are defined by:  a set of objects. CP468. Al-Halimi 21 .  Interpretations and models together determine the truth of a sentence.  “m is a model of sentence s” means “sentence s is true in m”.

Al-Halimi 22 . we say I satisfies S.Interpretations  If an interpretation I makes S true. we say S is satisfiable. Reem K.  If there is no interpretation I that makes S true. Dr. we say S is unsatisfiable: ∃X (p(X) ∧ ¬p(X)) CP468.  If there is at least one interpretation I that makes S true.

S1 entails sS2 if and only if the sentence (S1→S2) is valid. Dr.Interpretations  If a sentence S is T under all interpretations. (proof?) CP468. Reem K. S is said to be valid. Al-Halimi 23 .  Examples:  ∀X (p(X) ∨¬p(X))  true  The deduction theorem For any sentences s1 and S2.

Al-Halimi 24 .Interpretations valid: All interpretations make S true satisfiable There is an interpretation that makes S true unsatisfiable No interpretation makes S true CP468. Dr. Reem K.

Assumption: predicates evaluated topdown. Reem K. Al-Halimi b c a d The blocks world in this figure is a model for this interpretation 25 .Example 2 Blocks World Goal: to create a set of expressions that is to represent a static snapshot of the blocks world. on(b. and left-right.d) clear(b) clear(c) hand_empty CP468.a) ontable(a) ontable(d) on(c. Dr.

Y)) CP468. Dr.Y) ⇒ stack(X.X)) ⇒ clear(X)) conditions action How can we stack a block on top of another? ∀X ∀Y (hand_empty ∧ clear(X) ∧ clear(Y) ∧ pick_up(X) ∧ put_down(X.Example 2 Blocks World When is a block clear? b c a d A block in our world is clear if there are no other blocks on top of it ∀X ((¬∃Y on(Y. Al-Halimi 26 .X)) ⇒ clear(X)) How can we clear a block clear? ∀X ((¬∃Y on(Y. Reem K.

X/c} CP468. Reem K.X) ⇒ ¬ ontable(Y))   ∀X (((¬∃Y on(Y.X)) ⇒ clear(X)) (assuming the definition is used in KB) clear(a) => repsonse should be F ∃X clear(X) => response: {X/b. Al-Halimi definitions  queries/goals   Substitution list 27 .X))) theorems (entailed by axioms ) ∀X ((¬∃Y on(Y.Using FOL to Represent a Domain  Domain: A part of the world of which we would like to express some knowledge. Dr.X)) ⇒ clear(X)) ∧ (clear(X) ⇒(¬∃Y on(Y.  Components:  assertions   axioms (basic sentences that do not need to be proven) facts about the domain on(a. b)  properties of objects or predicates (possibly partial) ∀X ∀Y(on(Y.

Al-Halimi 28 .Knowledge Endgineering  “The general process of knowledge base construction” (Russell and Norvig. 2003) CP468. Reem K. Dr.

Encode general knowledge about the domain Encode a description of the specific problem instance Pose queries to the inference procedure and get answers. 2. 6. Dr. and constants. Reem K. 5. 4.Knowledge Endgineering Process 1. 7. Al-Halimi 29 . functions. 3. Debug the knowledge base CP468. Identify the task Assemble the relevant information Decide on a vocabulary of predicates.

000/year plus an additional $4. Al-Halimi 30 . Individuals with an inadequate savings account should make increasing their savings a first priority. Individuals with an adequate savings account and an adequate income should consider investing in the stock market. at least $15.000 per dependent.  An adequate income must be steady. or a combination of the two.Example 3 A Logic-Based Financial Advisor  Goal: to help the user decide whether to invest in a savings account. Dr. Individuals with an adequate savings account and a lower income should consider splitting their surplus income between savings and stocks. the stock market only. CP468.  the adequacy of their savings account is determined by the number of dependents: s/he has to have at least $5000/dependent. Reem K. 3.  Recommendations will be based on the investor’s current savings and their income according to the criteria: 1. 2.

Dr. or a combination of the two.Example 3 A Logic-Based Financial Advisor 1. CP468. the stock market only. Al-Halimi 31 . Reem K. Identify the task  Goal: to help the user decide whether to invest in a savings account.

at least $15.  An adequate income must be steady. Al-Halimi 32 .Example 3 A Logic-Based Financial Advisor 2.  the adequacy of their savings account is determined by the number of dependents: s/he has to have at least $5000/dependent. 3. 2. CP468. Reem K. Assemble the relevant information  Recommendations will be based on the investor’s current savings and their income according to the criteria: 1. Individuals with an adequate savings account and a lower income should consider splitting their surplus income between savings and stocks.000/year plus an additional $4.000 per dependent. Dr. Individuals with an adequate savings account and an adequate income should consider investing in the stock market. Individuals with an inadequate savings account should make increasing their savings a first priority.

Individuals with an inadequate savings account should make increasing their savings a first priority. Reem K. Decide on a vocabulary of predicates.  Recommendations will be based on the investor’s current savings and their income according to the criteria: 1.  An adequate income must be steady. Individuals with an adequate savings account and a lower income should consider splitting their surplus income between savings and stocks. and constants. Individuals with an adequate savings account and an adequate income should consider investing in the stock market. Al-Halimi 33 . 2.000 per dependent. 3.  the adequacy of their savings account is determined by the number of dependents: s/he has to have at least $5000/dependent. functions.Example 3 A Logic-Based Financial Advisor 3. CP468. Dr. at least $15.000/year plus an additional $4.

 the investor’s current savings  Concepts adequate/inadequate adequate/inadequate steady/unsteady savings stock combination (savings and stock)  the investor’s income    investment      the number of dependents An adequate income must be steady CP468.Example 3 A Logic-Based Financial Advisor 3. Reem K. functions. Dr. and constants. Al-Halimi 34 . Decide on a vocabulary of predicates.

Concept the investor’s current savings the investor’s income adequate inadequate Name amount_saved earnings adequate inadequate Symbol Type Function Symbols Constants savings stock combination steady unsteady Predicate Symbols invest CP468. Al-Halimi savings stock combination steady unsteady invest dependents dependents 35 . Decide on a vocabulary of predicates.Example 3 A Logic-Based Financial Advisor 3. Reem K. and constants. functions. Dr.

Dr. Al-Halimi 36 .Example 3 A Logic-Based Financial Advisor 4. Encode general knowledge about the domain  Decisions are based on  savings_account(adequate)  savings_account(inadequate)  income(adequate)  income(inadequate)  decisions:  invest(savings)  invest(stocks)  invest(combination) CP468. Reem K.

Reem K. Encode general knowledge about the domain  Decision criteria: 1. Dr. savings_account(adequate) ∧ income(adequate) ⇒ invest(stocks) 3. savings_account(inadequate) ⇒ invest(savings) 2. Al-Halimi 37 .Example 3 A Logic-Based Financial Advisor 4. savings_account(adequate) ∧ income(inadequate) ⇒ invest(combination) CP468.

Example 3 A Logic-Based Financial Advisor
4.

Encode general knowledge about the domain

 adequate savings?
 “the adequacy of their savings account is determined by the

number of dependents: s/he has to have at least $5000/dependent.”

  

How many dependents?  Y such that dependents(Y) is true What is the minimum savings required?  minsavings(Y) = 5000*Y What are the actual savings?  amount_saved(X) Are the actual savings greater than the minimum?  greaterThan(X, minsavings(Y))
CP468, Dr. Reem K. Al-Halimi 38

Example 3:A Logic-Based Financial Advisor
3.

Decide on a vocabulary of predicates, functions, and constants.
Concept the investor’s current savings the investor’s income Name amount_saved earnings

Symbol Type Function Symbols

minimum adequate savings
Constants adequate inadequate savings stock combination steady unsteady Predicate Symbols invest

minsavings
adequate inadequate savings stock combination steady unsteady invest

dependents
CP468, Dr. Reem K. Al-Halimi

dependents
39

test if one number is greater than another greaterThan

Example 3 A Logic-Based Financial Advisor
4. Encode general knowledge about the domain
 adequate savings?  Are the savings adequate (check all amounts saved)?

∀X amount_saved(X) ∧ ∃ Y (dependents(Y) ∧ greaterThan(X, minsavings(Y)) ⇒ savings_account(adequate) ∀X amount_saved(X) ∧ ∃ Y (dependents(Y) ∧ ¬greaterThan(X, minsavings(Y)) ⇒ savings_account(inadequate)

CP468, Dr. Reem K. Al-Halimi

40

000 per dependent”  What is the minimum savings required?  minincome(Y) = 15000 + 4000*Y  What are the actual savings?  earnings(X. at least $15. Z)  Are the actual earnings greater than the minimum?  greaterThan(X. Al-Halimi 41 . minincome(Y)) CP468. Encode general knowledge about the domain  adequate income?  “An adequate income must be steady.000/year plus an additional $4. Dr.Example 3 A Logic-Based Financial Advisor 4. Reem K.

and constants. one number is greater than another greaterThan . Al-Halimi test if Dr. Reem K. functions. Decide on a vocabulary of predicates.Example 3:A Logic-Based Financial Advisor 3. Concept Name Symbol Type Function Symbols the investor’s current savings the investor’s income minimum adequate savings minimum adequate income amount_saved earnings minsavings minincome Constants adequate inadequate savings stock adequate inadequate savings stock combination steady unsteady Predicate Symbols invest combination steady unsteady invest dependents dependents 42 CP468.

000 per dependent”  Are the savings adequate (check all amounts saved)?  ∀X earnings(X. Reem K. Dr. Al-Halimi 43 . minincome(Y)) ⇒ income(adequate)  ∀X earnings(X. minincome(Y)) ⇒ income(inadequate)  ∀X earnings(X. steady) ∧ ∃ Y (dependents(Y) ∧ ¬ greaterThan(X.000/year plus an additional $4. steady) ∧ ∃ Y (dependents(Y) ∧ greaterThan(X. at least $15. unsteady) ⇒ income(inadequate) CP468. Encode general knowledge about the domain  adequate income?  “An adequate income must be steady.Example 3 A Logic-Based Financial Advisor 4.

Example 3 A Logic-Based Financial Advisor 5. an investor with three children. Al-Halimi 44 . we add his/her information to the knowledge base:  e.g. Encode a description of the specific problem instance  Given a particular investor. steady) amount_saved(22000) dependents(3) CP468.000 in steady income: earnings(25000. Reem K. and $25.000 in savings. $22. Dr.

Example 3 A Logic-Based Financial Advisor 6. Reem K. What type of investment should the customer make? ∃ X invest(X) How can the system find out the answer? CP468. Dr. Pose queries to the inference procedure and get answers. Al-Halimi 45 .

Dr. Al-Halimi 46 . Reem K.Components of First-Order Logic Proof System  In propositional logic we could test an assumption using a truth table.  We can use the same approach for sentences not containing variables CP468.

Dr. the school will be open W O (2)  It is sunny S (3)  Will the school be open? i. and 3 above? CP468. the weather will be warm S W (1)  if it is warm. Al-Halimi 47 .Components of First-Order Logic Proof System  Let us take an example:  if it is sunny. 2. is true that in every world in which all of the above sentences are true that O is true as well? Does O logically follow from sentences 1.e. Reem K.

Al-Halimi 48 .Components of First-Order Logic Proof System S T T T T F F F F W T T F F T T F F O F T T F T F T F S→W T T F F T T T T W →O F T T T T F T T CP468. Dr. Reem K.

Al-Halimi 49 . Reem K. Dr.Components of First-Order Logic Proof System S T T T T F F F F W T T F F T T F F O F T T F T F T F S→W T T F F T T T T W →O F T T T T F T T CP468.

Components of First-Order Logic Proof System S T T T T F F F F W T T F F T T F F O F T T F T F T F S→W T T F F T T T T W →O F T T T T F T T Yes! The School will be open! CP468. Reem K. Dr. Al-Halimi 50 .

 this cannot necessarily be done in first-order logic. Reem K. Dr. Why not?  Solution? Use rules to create new conclusions from given predicates CP468. Al-Halimi 51 .Components of First-Order Logic Proof System  In propositional logic we could test an assumption using a truth table.

Reem K. Dr. Al-Halimi 52 .Components of First-Order Logic Proof System  Logical inference is the ability to infer new correct expressions from a set of true assertions.  A proof procedure is a combination of an inference rule and an algorithm for applying that rule on a set of logical expressions to generate new sentences CP468.

Al-Halimi 53 . Knowledge Base Inference Engine CP468.Knowledge-Based System (from previous lectures)  Consists of  world knowledge (knowledge base)  and a way to reason about this knowledge. Dr. Reem K.

Dr. Reem K. Knowledge Chirpy is a bird Birds have Basewings Inference Engine CP468.Knowledge-Based System  World knowledge is expressed as in a set language of trueusing the assertions language’sabout syntax a and problem semantics domain. rules. Al-Halimi 54 .

Reem K. Chirpy is a bird Knowledge Birds have wings Base Chirpy has wings Inference Engine CP468. Al-Halimi 55 .Knowledge-Based System  Inference rules are used to reason about the world in order to determine when a predicate expression logically follows from a knowledge base. Dr.

S S is true S entails P P S is true interpretations CP468. Dr. Al-Halimi 56 .Using Inference Rules  A sentence (predicate expression) P is said to logically follow from a set of assertions S if and only if every interpretation and variable assignment that makes S true. also makes P true. Reem K.

Reem K. does it logically follow from the facts in KB that ∃ X invest(X) CP468.Using Inference Rules  In our financial advisor problem our question is: given the knowledge base KB. Al-Halimi 57 . Dr.

Al-Halimi 58 . the rule can infer every expression that logically follows from S. Reem K.  An inference rule is complete if. Dr. CP468.Using Inference Rules  An inference rule is sound if every predicate calculus expression produced by the rule from a set S of predicate calculus expressions logically follows from S. given a set S of predicate calculus expressions.

Dr.  Example: lawyer(john) → rich(john) lawyer(john) We can conclude: rich(john) CP468. Reem K.Using Inference Rules Examples  Modus Ponens P→Q P Q  Modus ponens is a sound inference rule. Al-Halimi 59 .

Reem K. Dr.Using Inference Rules Examples  Modus Tollens P→Q ¬Q ¬P  Modus tollens is a sound inference rule.  Example: lawyer(john) → rich(john) ¬rich(john) We can conclude: ¬lawyer(john) CP468. Al-Halimi 60 .

Al-Halimi 61 .  Example: cat(snowball) ∧ white(snowball) We can conclude: cat(snowball ) white(snowball) CP468. Reem K. Dr.Using Inference Rules Examples  Elimination P∧Q P∧Q Q P  Elimination is a sound inference rule.

 Example: cat(snowball ) white(snowball) We can conclude: cat(snowball) ∧ white(snowball) CP468. Reem K. Al-Halimi 62 . Dr.Using Inference Rules Examples  And Introduction P Q P∧Q  And introduction is a sound inference rule.

Reem K.Using Inference Rules Examples  Universal Instantionation ∀X P(X) P(a)  Universal instantiation is a sound inference rule. we can conclude: mortal(russell) CP468. Dr. Al-Halimi 63 .  Example: ∀X mortal(X) if russell is in the domain of X.

Reem K. Al-Halimi 64 .Using Inference Rules Examples ∀X (man(X) → mortal(X)) man(socrates) Prove that Socrates is mortal? ∀X (man(X) → mortal(X)) man(socrates) → mortal(socrates) mortal(socrates) using Universal Instantiation by applying modus ponens CP468. Dr.

 To use the unification algorithm all variables in a logical database must be universally quantified.Using Inference Rules Unification  Unification is an algorithm for determining the substitutions needed to make two or more predicate expressions match. Reem K. Al-Halimi 65 . Dr. CP468.

knows(john. knows(john. Dr. Reem K. Al-Halimi 66 . X) and knows(john. X) and knows(X. X) and knows(Y. mother(Y)) {john/Y. X) and knows(Y. knows(john.Using Inference Rules Unification  unify: 1. bill) {bill/X. knows(john. jane) {jane/X} 3. mortal(X) and mortal(socrates) {socrates/X} 2. mother(john)/X} 5. john/Y} 4. bill) fail Substitution list CP468.

Dr. Reem K. Al-Halimi 67 .Using Inference Rules Unification  substitution list {X/Y} means: X replaces Y in the original expression CP468.

X cannot be replaced by f(X) Why? 3. Once a variable has been bound. a variable cannot be unified with a term containing it. future unifications must take the value of this binding into account. 1. Al-Halimi 68 . Dr. Reem K. e.Using Inference Rules Unification Rules constants cannot be replaced 2.g. CP468.

CP468. 3. 2. 4.1 and 5.3 above. Reem K. Al-Halimi 69 . sentences are bound by 1. recursively unifying the first elements in each. unification fails 5. equal constants return an empty substitution list 3. sentences are represented as lists 2. 4. then applying the substitution list to the rest of each list recursively unifying the remainder of the two lists. Dr. individual variables are bound to whatever occurs in the other sentence. if either expression is empty. creating a single substitution list by composition of the lists from steps 5.Using Inference Rules Unification Algorithm  Basic idea: 1.

Dr. Al-Halimi 70 . 2009 CP468. 6th edition. © Pearson Education Limited. Reem K.Using Inference Rules Unification Algorithm Luger: Artificial Intelligence.

W/Z} and {a/X. Al-Halimi 71 . Reem K. f(b)/W} 2. W/Z} and {V/X} and {a/V.Using Inference Rules Unification Algorithm: Composition  Composition the process of creating a single substitution list from two or more lists by applying one to the other: {X/Y. Dr. f(b)/W} CP468. a/V. a/V. f(b)/W} 1. a/X. f(b)/Z. {a/Y. a/V. composing {X/Y. f(b)/W} composing {V/X} and {a/V. f(b)/W}: {a/X.

sub2) ≠ composition(sub1. sub3)) = composition(composition(sub1. Reem K. sub3)  but not commutative composition(sub1. composition(sub2. Al-Halimi 72 .Using Inference Rules Unification Algorithm: Composition  Composition is associative composition(sub1. Dr. sub2). sub2) CP468.

X) knows(Y.Using Inference Rules Unification Algorithm: Most General Unifier  Unify: knows(john. Dr. CP468. Z/X} S = {john/Y. john/Z}  G is the substitution list with the least restrictions on the variable values => G is called the most general unifier  The unification algorithm described earlier calculates the most general unifier for any given set of expressions . Reem K. john/X.Z) Possible substitutions: G = {john/Y. Al-Halimi 73 .

Using Inference Rules Unification Algorithm  Unify: knows(john. Reem K. X) knows(Y. Dr. Al-Halimi 74 .Z) CP468.

Dr. ()) 9 75 . (Y Z)) return {Z/X} 11 1 unify(knows. Z/X} 12 3 unify(( john X). Al-Halimi return {Z/X} 8 unify(().Using Inference Rules Unification Algorithm unify((knows john X). Reem K. knows ) return {} 2 4 unify(john. (Z)) return {} 10 7 unify(X. (knows Y Z)) return {john/Y. Z) CP468. Y) return {john/Y} 5 6 unify((X).

Al-Halimi 76 . Dr.Using Inference Rules Financial Advisor Example continued  How can we choose which investment is best for the investor?  One approach: Goal-directed. depth-first search  Goal: ∃ X invest(X) CP468. Reem K.

Dr. Reem K. 6th edition. 2009 CP468. © Pearson Education Limited.Using Inference Rules Financial Advisor Example continued Luger: Artificial Intelligence. Al-Halimi 77 .

savings_account(inadequate) ⇒ invest(savings) From Fig 3. CP468. Al-Halimi 78 Luger: Artificial Intelligence. 6th edition. Dr. © Pearson Education Limited. Reem K. 2009 .Using Inference Rules Financial Advisor Example continued 1.26 And/or graph searched by the financial advisor.

minsavings(Y)) ⇒ savings_account(inadequate) Unification result {20000/X} Unification result {2/Y} From Fig 3. CP468. Dr. 2009 .26 And/or graph searched by the financial advisor. 6th edition. Al-Halimi 79 Luger: Artificial Intelligence.Using Inference Rules Financial Advisor Example continued ∀X amount_saved(X) ∧ ∃ Y (dependents(Y) ∧ ¬greaterThan(X. Reem K. © Pearson Education Limited.

Defined models and interpretations. syntax. CP468. and proof systems. and unsatisfiable. Dr. Looked at the use of inference rules and search in a simple expert system through the financial advisor example. Discussed the component of FOL: alphabet. satisfiable. Discussed inference rules and their properties: valid. semantics.Summary  Presented First Order Logic (FOL) as a powerful knowledge        representation language. modus tollens. Presented important sound inference rules: modus ponens. and universal instantiation. Looked at the use of sound inference rules in generating new facts from a given set of assertions. Reem K. and elimination. Looked at the components of a knowledge base and the procedure involved in creating a knowledge-based system. Al-Halimi 80 .