Dave Touretzky Read R&N Ch

Slides:



Advertisements
Similar presentations
Artificial Intelligence 8. The Resolution Method
Advertisements

Some Prolog Prolog is a logic programming language
Inference in first-order logic
First-Order Logic.
Inference Rules Universal Instantiation Existential Generalization
Standard Logical Equivalences
ITCS 3153 Artificial Intelligence Lecture 15 First-Order Logic Chapter 9 Lecture 15 First-Order Logic Chapter 9.
Inference in first-order logic Chapter 9. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward.
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
Methods of Proof Chapter 7, second half.. Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules: Legitimate (sound)
Inference in FOL All rules of inference for propositional logic apply to first-order logic We just need to reduce FOL sentences to PL sentences by instantiating.
First-Order Logic Inference
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Inference in FOL Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 9 Spring 2004.
Inference in first-order logic Chapter 9. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward.
Inference in FOL Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 9 Fall 2004.
Logic. Knowledge-based agents Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):
Inference in FOL Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 9 Spring 2005.
1 Inference in First-Order Logic. 2 Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward chaining.
INFERENCE IN FIRST-ORDER LOGIC IES 503 ARTIFICIAL INTELLIGENCE İPEK SÜĞÜT.
Inference in First-Order Logic CS 271: Fall 2007 Instructor: Padhraic Smyth.
Inference in first-order logic Chapter 9. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward.
CHAPTERS 7, 8 Oliver Schulte Logical Inference: Through Proof to Truth.
First-Order Logic Semantics Reading: Chapter 8, , FOL Syntax and Semantics read: FOL Knowledge Engineering read: FOL.
Inference in first- order logic. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward chaining.
First Order Predicate Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Unification Algorithm Input: a finite set Σ of simple expressions Output: a mgu for Σ (if Σ is unifiable) 1. Set k = 0 and  0 = . 2. If Σ  k is a singleton,
Inference in First-Order Logic 부산대학교 전자전기컴퓨터공학과 인공지능연구실 김민호
Logic (Chapters 7-9).
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
1 Inference in First-Order Logic CS 271: Fall 2009.
1 Inference in First Order Logic CS 171/271 (Chapter 9) Some text and images in these slides were drawn from Russel & Norvig’s published material.
An Introduction to Artificial Intelligence – CE Chapter 9 - Inference in first-order logic Ramin Halavati In which we define.
Inference in first-order logic
Inference in First Order Logic. Outline Reducing first order inference to propositional inference Unification Generalized Modus Ponens Forward and backward.
First-Order Logic Reading: C. 8 and C. 9 Pente specifications handed back at end of class.
1 Propositional Logic Limits The expressive power of propositional logic is limited. The assumption is that everything can be expressed by simple facts.
Inference in First-Order Logic Chapter 9. Outline Reducing first-order inference to propositional inference Unification Generalized Modus Ponens Forward.
1 Chaining in First Order Logic CS 171/271 (Chapter 9, continued) Some text and images in these slides were drawn from Russel & Norvig’s published material.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
EA C461 Artificial Intelligence
Logical Inference 2 Rule-based reasoning
Announcements No office hours today!
Presented By S.Yamuna AP/CSE
Inference in first-order logic
Inference in First-Order Logic
EA C461 – Artificial Intelligence Logical Agent
Resolution in the Propositional Calculus
Knowledge-Based Systems Chapter 17.
Logical Inference 2 Rule-based reasoning
Logical Inference: Through Proof to Truth
Inference in First-Order Logic
Inference in first-order logic part 1
Example of Knowledge Base
Artificial intelli-gence 1:Inference in first-order logic
Artificial Intelligence
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Artificial intelligence: Inference in first-order logic
Artificial Intelligence Inference in First Order Logic
Notes 9: Inference in First-order logic
Inference in first-order logic
Inference in first-order logic part 1
Logic: Top-down proof procedure and Datalog
Biointelligence Lab School of Computer Sci. & Eng.
CS 188: Artificial Intelligence
Methods of Proof Chapter 7, second half.
This Lecture Substitution model
Propositional Logic CMSC 471 Chapter , 7.7 and Chuck Dyer
First-Order Logic Inference
Presentation transcript:

Dave Touretzky Read R&N Ch. 9.1-9.4 Inference in FOL Dave Touretzky Read R&N Ch. 9.1-9.4

Review: How to do automated inference in FOL Reduction to propositional inference — previous lecture Models are potentially infinite But any true sentence can be proved in a finite model Horn theories: Forward chaining Backward chaining Resolution theorem proving — next lecture This lecture

Review: propositional Modus Ponens α ⇒ β , α ----------------- β Here, α and β can be any propositional formula. What happens when we add variables?

Variable substitution drives inference in FOL Given a sentence Man(x) ⇒ Mortal(x) and another sentence Man(socrates) Apply the substitution θ = { x / socrates } to derive Man(socrates) ⇒ Mortal(socrates) Then we can apply Modus Ponens to conclude Mortal(socrates)

Generalized Modus Ponens Let pi, pi’, be atomic sentences where there is a substitution θ such that SUBST(θ,pi’) = SUBST(θ,pi) for 1 ≤ i ≤ n. Let q also be an atomic sentence. Then the Generalized Modus Ponens inference rule is: p1’, p2’, …, pn’ , p1 ∧ p2 ∧ … ∧ pn ⇒ q --------------------------------------------------------- SUBST(θ,q) This is a lifted (more abstract) version of Modus Ponens, allowing us to move beyond ground (variable-free) statements. Why the restriction to atomic sentences?

Lifted inference algorithms We can develop lifted versions of: Forward chaining Backward chaining Resolution theorem proving More efficient than universal instantiation: can focus on just the sentences relevant to our inference rules. But where does the substitution θ come from?

Unification Given two sentences p and q, a unifier θ of p and q is a substitution such that SUBST(θ,p) = SUBST(θ,q) Knows(john, x) Knows(john, jane) θ = { x / jane } Knows(john, x) Knows(y, bill) θ = { x / bill, y / john } Knows(john, x) Knows(y, mother(y)) θ = { y / john, x / mother(john) } Knows(john, x) Knows(x, elizabeth) fail even though everyone knows Liz Standardizing apart: Knows(john, x1) Knows(x2, elizabeth) θ = { x1 / elizabeth, x2 / john }

Most general unifier What are the legal unifiers of Knows(john, x) Knows(y, z) θ = { x / john, y / john, z / john } gives Knows(john, john) θ = { y / john, x / z} ⇠ MGU gives Knows(john, z) Every pair of sentences has a MGU that is unique up to variable renaming. The MGU is what we want to use for inference.

Occurs check A variable cannot unify with a formula that contains that variable. For example: f(x) cannot unify with f(f(x)) θ = { x / f(x) } Occurs checks make unification quadratic in the length of the expression. Some inference systems skip them, for efficiency’s sake.

Unifying a variable with something function UNIFY-VAR(var, x, θ) returns a substitution if { var / val } ∊ θ then return UNIFY(val, x, θ) else if { x / val } ∊ θ then return UNIFY(var, val, θ) else if OCCUR-CHECK?(var, x) then return failure else return θ + { var / x }

function UNIFY(x, y, θ={ }) returns a most general unifier inputs: x, y: variables, constants, lists, or compound expressions θ: a substitution if θ = failure then return failure else if x = y then return θ else if VARIABLE?(x) then return UNIFY-VAR(x, y, θ) else if VARIABLE?(y) then return UNIFY-VAR(y, x, θ) else if COMPOUND?(x) and COMPOUND(y) then return UNIFY(x.args, y.args, UNIFY(x.op, y.op, θ)) else if LIST?(x) and LIST?(y) then return UNIFY(x.rest, y.rest, UNIFY(x.first, y.first, θ)) else return failure

Try out the unification code in logic2.py >> unify(expr(‘Knows(John,x)’), expr(‘Knows(y,z)’), { }) { x: z, y: John } >> unify(expr(‘f(x)’), expr(‘f(f(A))’), { }) { x: f(A) } >> unify(expr(‘f(x)’), expr(‘f(f(x))’), { }) None

Database fetch Find all the facts in a database that unify with a query. Employs(IBM, Richard) Does IBM employ Richard? Employs(x, Richard) Who employs Richard? Employs(IBM, y) Who does IBM employ? Employs(x,y) Who employs whom? If the database contains many different kinds of facts, indexing can make retrieval more efficient. Can index on the predicate, or on predicate/argument combinations.

Subsumption relations among queries Every ground term is the base of a lattice of increasingly abstract queries. Could index on some of these combinations, depending on utility.

Forward Chaining

Forward chaining algorithm Start with a set of atomic sentences and definite clauses Repeatedly apply Modus Ponens until either: the desired answer is reached, or no further inferences can be made

First order definite clauses All terms are positive literals. Facts: P(a), R(b,c), S(x,d) Implications: p1 ∧ p2 ∧ … ∧ pn⇒ q Example: King(x) ∧ Greedy(x) ⇒ Evil(x) King(John) Greedy(y) MGU: { x / John, y / x }

Forward chaining example American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Missile(x) ⇒ Weapon(x) Missile(m1) Owns(nono, m1) Missile(x) ∧ Owns(nono, x) ⇒ Sells(west, x, nono) Enemy(x, america) ⇒ Hostile(x) American(west) Enemy(nono, america)

Forward chaining derivation of Criminal(west) 1 2 5 6

Datalog knowledge bases Datalog: language with first order definite clauses and no function symbols. Represents the kind of information found in relational databases. For a Datalog knowledge base, forward chaining is: Sound: all inferences are valid Complete: all valid inferences are derivable Limited to p×nk ground instances (p = # predicates, k = max arity, n = # const) On the other hand, if we allow function symbols, then forward chaining may never terminate. Entailment is only semi-decidable, even when our language is restricted to definite clauses.

Inference as constraint satisfaction (NP hard) Diff(wa,nt) ∧ Diff(wa,sa) ∧ Diff(nt,q) ∧ Diff(nt,sa) ∧ Diff(q,nsw) ∧ Diff(q,sa) ∧ Diff(nsw,v)∧ Diff(nsw,sa) ∧ Diff(v,sa) ⇒ Colorable() Diff(red,blue) Diff(blue,red) Diff(red,green) Diff(green,red) Diff(blue,green) Diff(green,blue) Since CSPs include 3-SAT as a special case, we see that matching a definite clause against a set of facts is NP-hard.

Making forward chaining more efficient (1) On each iteration i of the forward chaining algorithm, every new fact must be derived from at least one new fact that was derived on iteration i-1. (Why?) Therefore, we need only consider rules that mention at least one fact derived at step i-1. If there are many rules, we can use indexing to efficiently locate the relevant ones.

Making forward chaining more efficient (2) Rules with many antecedents may not fully match on iteration i, but after more inference is done, they could fully match later. Instead of recomputing matches from scratch on each iteration, cache the results of partial matches and incrementally update them on each iteration. The rete algorithm used in the OPS-5 production system language works this way. Cognitive architectures such as ACT and SOAR tend to have many rules and only small numbers of facts. Some production systems have tens of millions of rules but can run in real time thanks to efficient matching.

Making forward chaining efficient (3) Use tricks to ensure that only variable bindings relevant to the goal are considered by the inference algorithm. Example: if we want to know if Criminal(west) is true, modify the inference rule by including a reference to a “magic” set: Magic(x) ∧ American(x) ∧ Weapon(y) ∧ Sells(x,y,z) ∧ Hostile(z) ⇒ Criminal(x) Then add: Magic(west) Now the rule is blocked from proving that anyone else is a criminal. Finding optimal magic sets is NP-hard, but heuristics exist.

Backward Chaining

Backward chaining algorithm Depth first search: Find rules that prove the goal. For each such rule, try to recursively prove each LHS clause. Propagate variable substitutions at each step.

function BACKWARD-CHAINING(KB, query) returns a generator of substitutions return TRY-ALL-RULES(KB, query, { }) generator TRY-ALL-RULES(KB, goal, θ) yields a substitution for each rule (lhs ⇒ rhs) in FETCH-RULES-FOR-GOAL(KB, goal) do (s_lhs, s_rhs) ← STANDARDIZE-VARIABLES(lhs,rhs) for each θ’ in PROVE-ALL-TERMS(KB, s_lhs, UNIFY(s_rhs, goal, θ) do yield θ’

generator PROVE-ALL-TERMS(KB, terms, θ) yields a substitution if θ = failure then return else if LENGTH(terms) = 0 then yield θ else do first_term, rest_terms ← FIRST(terms), REST(terms) for each θ’ in TRY-ALL-RULES(KB, SUBST(θ, first_term), θ) do for each θ’’ in PROVE-ALL-TERMS(KB, rest_terms, θ’) do yield θ’’

Backward chaining proof of Criminal(west)

Pros and cons of backward chaining Focuses attention on rules relevant to the goal Space linear in the size of the proof Cons: May try to establish the same goal repeatedly (tree search) Not complete due to possibility of infinite recursion

Logic programming Can we use logic as the basis of a programming language? Pattern matching is a powerful primitive. Languages like Perl provide regular expression matching. Logic programming languages use unification. Depth-first search with automatic backtracking is handy for some problems. Prolog is the most common logic programming language.

How Prolog differs from pure logic Database semantics used for equality and negation Built-in arithmetic functions; don’t need Peano’s axioms Side effects, e.g., for i/o, or for updating the KB No occur check, so inference is unsound (but quick) Depth-first backward chaining with no checks for infinite recursion Rule order matters Programmer has some control of backtracking via cut operator

Prolog syntax First order logic: P(x) ∧ Q(x,y) ∧ R(y) ⇒ S(x,y) reverse: S(x,y) ⇐ P(x) ∧ Q(x,y) ∧ R(y) Prolog: s(X,Y) :- p(X), q(X,Y), r(Y).

Rule order matters path(X,Z) :- link(X,Z). path(X,Z) :- path(X,Y), link(Y,Z)

Rule order matters path(X,Z) :- path(X,Y), link(Y,Z) path(X,Z) :- link(X,Z). Infinite recursion!

Depth-first backtracking search can be expensive path(X,Z) :- link(X,Z). path(X,Z) :- path(X,Y), link(Y,Z) Finding a path from A1 to J4 requires 877 inferences.

Constraint logic programming Backtracking search works only for finite-domain CSPs. What if we want to reason about inequalities? triangle(X,Y,Z) :- X>0, Y>0, Z>0, X+Y>=Z, Y+Z>=X, X+Z>=Y. Constraint logic programming allows variables to be constrained rather than bound. Combines constraint satisfaction techniques with logic, deductive databases, and linear programming.