580 likes | 606 Views
CS3243: Introduction to Artificial Intelligence. Semester 2, 2017/2018. Inference in First-Order Logic (FOL). AIMA Chapter 9.1 – 9.3, 9.4.1, 9.5.1 – 9.5.3. Outline. Reduction to propositional inference Unification Generalized Modus Ponens Forward chaining Backward chaining Resolution.
E N D
CS3243: Introduction to Artificial Intelligence Semester 2, 2017/2018
Inference in First-Order Logic (FOL) AIMA Chapter 9.1 – 9.3, 9.4.1, 9.5.1 – 9.5.3
Outline • Reduction to propositional inference • Unification • Generalized Modus Ponens • Forward chaining • Backward chaining • Resolution
Converting from First Order to Propositional Logic • Convert a universal quantifier to a list of propositional rules: becomes • Convert an existential quantifier by adding a new constant (not appearing in KB!) – also known as Skolem constant becomes ; the variable is new.
First Order to Propositional Logic Rules:, , , ,. Atomic sentences (e.g. , ) are now symbols Rules:, , , ,,.
Reduction to Propositional Inference • Every FOL can be propositionalized so as to preserve entailment • A ground sentence is entailed by new KBiff entailed by original KB • Idea:propositionalizeKB and query, apply resolution, return result • Problem: with function symbols, there are infinitely many ground-term substitutions • e.g., • would convert to
Theorem (Herbrand, 1930). If a sentence is entailed by FOL , then it is entailed by a finite subset of the propositionalized Does this remind you of any other algorithm? • Idea: For to do • create a propositionalized by instantiating with depth- terms • see if is entailed by this • What happens if is not entailed? Entailment for FOL is semi-decidable (algorithms exist that say yes to every entailed sentence, but no algorithm exists that also says no to every non-entailed sentence). Similar to the halting problem (Turing, 1936)
Problems with Propositionalization • Generates irrelevant things:Easily implies that … but we will also add the irrelevant • Exponential blowup: a-ary predicate has instantiations with constants. We don’t need all of them!
AIMA uses notation Unification • We can get the inference immediately if we can find a substitution such that and match and Unifier works • outputs a var. substitution s.t. • Standardizing aparteliminates variable name clashes
Unification – Multiple Unifiers • To unify and , or • The first unifier is more general than the second • There is a single most general unifier (MGU) that is unique up to renaming and substitution of variables
Unification Algorithm Given two sentences , find a variable assignment such that • Input: ( is empty at first) • If or if return • If one of the inputs is a variable (say, ), we need to unify a variable with a sentence given . • Otherwise, break up the compound function/list and process their parts recursively.
The UNIFY-VAR function Given a variable , a sentence , and • If has been assigned a value (consult ), return ; if has a value , return . • If appears in return FAIL • If does not appear in return
Unification Example Input:
Generalized Modus Ponens (GMP) • Original Modus Ponens: • Generalized (lifted) Modus Ponens: • There is some substitution such that the premise and the implication are the same (namely ) • … then we can infer that
Generalized Modus Ponens (GMP) These sentences have variables in their universal quantifiers (the elements) • We are given a set of FOL sentences and an implication rule • If there exists some substitution over the variables such that • … then holds!
Soundness of GMP Assume: • there exists a substitution such that for all . • hold, and that We need to prove that holds as well.
s.t.. hold, and Lemma: if then for any substitution Proof: by universal instantiation • By Lemma: • and • We know that • hold, and that • Apply Propositional Logic’s Modus Ponens!
Example KB in FOL “The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.”
Example KB in FOL “The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.”
Example KB in FOL “The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.”
Example KB in FOL “The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.” Existential Instantiation
Example KB in FOL “The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.”
Example KB in FOL “The law says that it is a crime for an American to sell weapons to hostile nations. The country Nono, an enemy of America, has some missiles, and all of its missiles were sold to it by Colonel West, who is American.”
Example KB in FOL Additional Facts • Missiles are weapons: • Enemies are hostile:
Example KB in FOL Want to prove that
Forward Chaining Algorithm • Input: • – a knowledge base coded in FOL • – an FOL sentence • Output: • A variable substitution so that • … or FALSE if no such exists. • At every round, add all newly inferred atomic sentences to . • Repeat until • One of these sentences is • No new sentences can be inferred.
Properties of Forward Chaining • Sound and complete for first-order definite clauses • FC terminates for KB in finite number of iterations if it contains no functions. • May not terminate in general (i.e., with functions) if is not entailed • This is unavoidable: entailment with definite clauses is semidecidable
Inefficiencies of Forward Chaining Matching rules and known facts is costly
Matching Rule Premises to Known Facts is Costly Predicate indexing: constant time to retrieve known facts • : find all facts (e.g., ) that unify with . Conjunct ordering problem: apply minimum-remaining-values heuristic of CSP • e.g., if there are many objects owned by and very few missiles, it may be better to start with conjunct
Inefficiencies of Forward Chaining Redundant rule matching
Redundant Rule Matchings • Incremental forward chaining: Match rule at iteration only if a conjunct in its premise unifies with new fact inferred at iteration • e.g., matches against again in 2nd iteration; but, is already known. • Rete (“Ree-Tee”) algorithm:Instead of discarding partially matched rules, keep track of conjuncts matched against new facts to avoid duplicate work. e.g., is partially matched against in first iteration.
Inefficiencies of Forward Chaining Generating Irrelevant Facts
Backward Chaining Algorithm At least one of the rules in the needs to imply All elements of need to be true
Backward Chaining: Proof Tree Call FOL-BC-OR on and FETCH-RULE on
Backward Chaining: Proof Tree Unify and , result in
Backward Chaining: Proof Tree Call FOL-BC-AND on the list of rules
Backward Chaining: Proof Tree gets unified with in the with existing substitution
Backward Chaining: Proof Tree gets unified with in the with existing substitution
Backward Chaining: Proof Tree We call FOL-BC-OR on and fetch the rule
Backward Chaining: Proof Tree Unifying we get
Backward Chaining: Proof Tree Unify on and outputs .
Backward Chaining: Proof Tree Fetch UNIFY to get and
Backward Chaining: Proof Tree no contradiction with so we are good!
Backward Chaining: Proof Tree Fetch UNIFY to get
Backward Chaining: Proof Tree UNIFY with , get no contradiction with current assignment to .
Properties of Backward Chaining • Depth-first search: space is linear in size of proof • Incomplete due to infinite loops: fix by checking current goal against every goal on stack • Inefficient due to repeated subgoals (both success and failure): fix by caching solutions to previous subgoals • Widely used for logic programming