1 / 58

First Order Logic (Syntax, Semantics and Inference)

First Order Logic (Syntax, Semantics and Inference). Knowledge based agents can represent the world it is in and can deduce the actions to take In most programming languages the data and operations are tied closely

ossie
Download Presentation

First Order Logic (Syntax, Semantics and Inference)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. First Order Logic (Syntax, Semantics and Inference)

  2. Knowledge based agents can represent the world it is in and can deduce the actions to take In most programming languages the data and operations are tied closely Each update to a data structure is done via a domain-specific procedure whose details are derived by the programmer from his own knowledge of the domain Is there a way to say “pit is in [1,2] or [2,1]” ? Propositional logic could represent the partial information, with negation and disjunction

  3. Propositional Logic is “compositional” Propositional logic is less expressive when the world consists many objects (why?) But english/.../.. are very much expressive Why not use engilsh for our representation? Ambiguous & not compositional

  4. First-order logic Propositional logic assumes the world contains facts, (ontological commitment) First-order logic (like natural language) assumes the world contains Objects: people, houses, numbers, colors, baseball games, wars, … Relations: red, round, prime, brother of, bigger than, part of, comes between, … Functions: father of, best friend, one more than, plus, …

  5. Ontological Commitments Propositional Logic : facts which hold ot does not. FOL : Objects and relations Epistemological Commitments (possible states of knowledge w.r.t each facts) Propositional Logic : true/false FOL : true/false

  6. Syntax of FOL: Basic elements Constants KingJohn, 2, ... Predicates Brother, >,... Functions Sqrt, LeftLegOf,... Variables x, y, a, b,... Connectives , , , ,  Equality = Quantifiers , 

  7. Atomic sentences Sentence = AtomicSentence | (Sentence Connective Sentence) | Quantifier Variables,…. Sentence | Sentence Atomic sentence = predicate (term1,...,termn) | term1 = term2 Term = function (term1,...,termn) | constant | variable E.g., Brother(KingJohn,RichardTheLionheart) > (Length(LeftLegOf(Richard)), Length(LeftLegOf(KingJohn)))

  8. Truth in first-order logic Sentences are true with respect to a model (possible world) and an interpretation Model contains objects (domainelements) and relations among them Interpretation specifies referents for constantsymbols→objects predicatesymbols→relations functionsymbols→ functional relations An atomic sentence predicate(term1,...,termn) is true iff the objects referred to by term1,...,termn are in the relation referred to by predicate

  9. Universal quantification <variables> <sentence> Everyone at England is smart: x At(x, England)  Smart(x) x P is true in a model m iff P is true with x being each possible object in the model Roughly speaking, equivalent to the conjunction of instantiations of P At(KingJohn,England)  Smart(KingJohn)  At(Richard, England)  Smart(Richard)  At(England, England)  Smart(England)  ...

  10. A common mistake to avoid Typically,  is the main connective with  Common mistake: using  as the main connective with : x At(x, England)  Smart(x) means “Everyone is at England and everyone is smart”

  11. Existential quantification <variables> <sentence> Someone at England is smart: x At(x, England)  Smart(x) xP is true in a model m iff P is true with x being some possible object in the model Roughly speaking, equivalent to the disjunction of instantiations of P At(KingJohn, England)  Smart(KingJohn)  At(Richard, England)  Smart(Richard)  At(England, England)  Smart(England)  ...

  12. Another common mistake to avoid Typically,  is the main connective with  Common mistake: using  as the main connective with : x At(x,England)  Smart(x) is true if there is anyone who is not at England!

  13. Properties of quantifiers x y is the same as y x x y is the same as y x

  14. Properties of quantifiers x y is the same as y x x y is the same as y x x y is not the same as y x x y Loves(x,y) “There is a person who loves everyone in the world” y x Loves(x,y) “Everyone in the world is loved by at least one person”

  15. Properties of quantifiers x y is the same as y x x y is the same as y x x y is not the same as y x x y Loves(x,y) “There is a person who loves everyone in the world” y x Loves(x,y) “Everyone in the world is loved by at least one person” Quantifier duality: each can be expressed using the other x Likes(x,IceCream) x Likes(x,IceCream) x Likes(x,Broccoli) x Likes(x,Broccoli)

  16. Interacting with FOL KBs Suppose a wumpus-world agent is using an FOL KB and perceives a smell and a breeze (but no glitter) at t=5: Tell(KB,Percept([Smell,Breeze,None],5)) Ask(KB,a BestAction(a,5)) i.e., does the KB entail some best action at t=5? Answer: Yes, {a/Shoot} ← substitution (binding list) Given a sentence S and a substitution σ, Sσ denotes the result of plugging σ into S; e.g., S = Smarter(x,y) σ = {x/Hillary,y/Bill} Sσ = Smarter(Hillary,Bill) Ask(KB,S) returns some/all σ such that KB╞ Sσ

  17. Universal instantiation (UI) Every instantiation of a universally quantified sentence is entailed by it: vαSubst({v/g}, α) for any variable v and ground term g E.g., x King(x) Greedy(x) Evil(x) yields: King(John) Greedy(John) Evil(John) King(Richard) Greedy(Richard) Evil(Richard) King(Father(John)) Greedy(Father(John)) Evil(Father(John)) . . … substitutions are {x/Richard} , {x/John}, {x/ Father(John)} We can infer any sentence by replacing the variable with the ground term

  18. Existential instantiation (EI) For any sentence α, variable v, and constant symbol k that does not appear elsewhere in the knowledge base: vα Subst({v/k}, α) E.g., xCrown(x) OnHead(x,John) yields: Crown(C1) OnHead(C1,John) provided C1 is a new constant symbol, called a Skolem constant

  19. Reduction to propositional inference Suppose the KB contains just the following: x King(x)  Greedy(x)  Evil(x) King(John) Greedy(John) Brother(Richard,John) Instantiating the universal sentence in all possible ways, we have: King(John)  Greedy(John)  Evil(John) King(Richard)  Greedy(Richard)  Evil(Richard) King(John) Greedy(John) Brother(Richard,John) The new KB is propositionalized: proposition symbols are King(John), Greedy(John), Evil(John), King(Richard), etc.

  20. Reduction contd. Idea: propositionalize KB and query, apply resolution, return result Problem: with function symbols, there are infinitely many ground terms, e.g., Father(Father(Father(John))) Theorem: Herbrand (1930). If a sentence αis entailed by an FOL KB, it is entailed by a finite subset of the propositionalized KB Idea: For n = 0 to ∞ do Create a propositional KB by instantiating with depth-n terms See if α is entailed by this KB.

  21. Reduction contd. Problem: Works if α is entailed, loops if α is not entailed Theorem: Turing (1936), Church (1936) Entailment for FOL is semidecidable algorithms exist that say yes to every entailed sentence, but no algorithm exists that also says no to every nonentailed sentence.

  22. Problems with Propositionalization Propositionalization seems to generate lots of irrelevant sentences. E.g., from: x King(x)  Greedy(x)  Evil(x) King(John) y Greedy(y) Brother(Richard,John)

  23. Forward Chaining

  24. Unification We can get the inference immediately if we can find a substitution θ such that King(x) and Greedy(x) match King(John) and Greedy(y) θ = {x/John,y/John} works Unify(α,β) = θ if αθ = βθ p q θ Knows(John,x) Knows(John,Jane) {x/Jane} Knows(John,x) Knows(y,OJ) {x/OJ, y/John} Knows(John,x) Knows(y,Mother(y)) {y/Jane, x/Mother(y)} Knows(John,x) Knows(x,OJ) {Fail} Standardizing aparteliminates overlap of variables, e.g., Knows(z17,OJ)

  25. Unification To unify Knows(John,x) and Knows(y,z), θ = {y/John, x/z } or θ= {y/John, x/John, z/John} The first unifier is more general than the second, places fewer restriction on the values of the variables There is a single most general unifier (MGU) that is unique up to renaming of variables. MGU = { y/John, x/z }

  26. First Order Definite Clauses Exactly one positive literal Atomic literal Implication whose antecedent is conjunction of positive literal and a single positive literal as consequent Examples King(x) Λ Greedy(x) Evil(x) King(John) Greedy(y)

  27. Generalized Modus Ponens p1', p2', … , pn', ( p1 p2 …  pnq) qθ p1' is King(John) p1 is King(x) p2' is Greedy(y) p2 is Greedy(x) θ is {x/John,y/John} q is Evil(x) q θ is Evil(John) Lifted version of modus ponens GMP used with KB of definite clauses All variables assumed universally quantified

  28. An Example KB Consider the passage 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. The KB should answer the query Is Col. West a criminal?

  29. An Example KB (contd…) ... it is a crime for an American to sell weapons to hostile nations: American(x)  Weapon(y)  Sells(x,y,z)  Hostile(z)  Criminal(x) Nono … has some missiles, i.e., x Owns(Nono,x)  Missile(x): Owns(Nono,M1) and Missile(M1) … all of its missiles were sold to it by Colonel West Missile(x)  Owns(Nono,x)  Sells(West,x,Nono) Missiles are weapons: Missile(x)  Weapon(x) An enemy of America counts as "hostile“: Enemy(x,America)  Hostile(x) West, who is American … American(West) The country Nono, an enemy of America … Enemy(Nono,America) No Function Symbols in the KB >> Datalog KB

  30. Forward Chaining Algorithm

  31. Forward chaining - Example

  32. Forward chaining - Example

  33. Forward chaining - Example

  34. Forward Chaining Algorithm - discussion No new sentences can be added to the KB after it has generated criminal(west) Fixed point of inference process Sound Complete (?) Datalog KB k- maximum arity of predicates, n – constant symbols, p- predicates  pnk distinct ground facts KB with function symbols Use Herbrand’s theorem, if the query has answer. Remember, entailment with FOL is semidecidable

  35. Forward Chaining Algorithm - discussion Efficiency concerns Notice the inner-loop generate all possible θ Expensive pattern matching Algorithm rechecks every rule in every iteration to see if the premises are satisfied Generates many facts which are irrelevant to the goal

  36. Addressing Efficiency ConcernsMatching against known rules only To apply the rule, Missile(x)  Weapon (x) Look for the rules that unify only with Missile(x) Use Indexed KB Missile(x) Λ Owns(Nono,x)  Sells(West, x, Nono) Owns(Nono,x)Nono may own thousands of objects Find all missiles first, then see if these missiles are owned by Nono : conjunct ordering Remember heuristic : Most constrained variable

  37. Addressing Efficiency ConcernsMatching against known rules only Colorable() is inferred iff the CSP has a solution CSPs include 3SAT as a special case, hence matching is NP-hard Forward chaining has an NP Hard Matching Problem in its inner loop  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 (Red,Green) Diff(Green,Red) Diff(Green,Blue) Diff(Blue,Red) Diff(Blue,Green)

  38. Addressing Efficiency ConcernsMatching against known rules only > Most Rules in real world are small and simple, upper bounds on the rule size and arity. > Data complexity > Consider only subclasses of databases for which matching is efficient  datalog KB Use better algorithm that avoids redundant matchings

  39. Addressing Efficiency ConcernsIncremental Forward Chaining Every fact inferred at iteration t will use at least one fact derived at iteration t-1 At iteration t, consider only rules whose premise include conjuncts which unifies with a fact derived at iteration t-1 With indexing, we may find out all rules which may trigger at iteration t Rete Algorithm

  40. Backward Chaining

  41. Backward chaining algorithm SUBST(COMPOSE(θ1, θ2), p) = SUBST(θ2, SUBST(θ1, p))

  42. Backward chaining example

  43. Backward chaining example

  44. Backward chaining example

  45. Backward chaining example

  46. Backward chaining example

  47. Backward chaining example

  48. Backward chaining example

  49. Backward chaining example

  50. Properties of backward chaining Depth-first recursive proof 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 using caching of previous results (extra space) Widely used for logic programming

More Related