15381: Artificial Intelligence Behrang Mohit and Davide Fossati Inference in Logical Agents First Order Logic Some slides, graphics and ideas are borrowed or adapted from courses offered by Stuart Russell, Hwee Tou Ng, Rebecca Hwa and Milos Hauskrecht. Last class: Knowledge bases • Knowledge Base (KB): set of sentences in a formal language • Domain specific • Inference engine: A set of procedures that use representaConal language to infer new facts from the known ones • Inferences typically require search • Inference rules are domain independent 1 Last class: Proposi=onal Logic • A simple logic among proposiConal symbols • ProposiCon: a statement that is either true or false • CMUQ is located in EducaCon City (True) • Syntax: ~p, p∨q, p∧q, p ⇒ q, p ⇔ q 3 Last class: Inference • Proof methods divide into (roughly) two kinds: • Model checking • truth table enumeraCon (always exponenCal in n) • ApplicaCon of inference rules • LegiCmate (sound) generaCon of new sentences from old • Proof = a sequence of inference rule applicaCons Can use inference rules as operators in a standard search algorithm 2 Forward and backward chaining • Challenge: Too many inference rules • RestricCng and converCng the knowledge form. • Horn Form (restricted) KB = conjuncCon of Horn clauses • Horn clause = • proposiCon symbol; or • (conjuncCon of symbols) ⇒ symbol • E.g., C ∧ (B ⇒ A) ∧ (C ∧ D ⇒ B) Forward and backward chaining • Modus Ponens (for Horn Form): complete for Horn KBs α1, … ,αn, α1 ∧ … ∧ αn ⇒ β β • Can be used with forward chaining or backward chaining. • These algorithms are very natural and run in linear Cme 3 Forward chaining • Idea: fire any rule whose premises are saCsfied in the KB, • add its conclusion to the KB, unCl query is found Forward chaining algorithm • Forward chaining is sound and complete for Horn KB 4 Forward chaining example Forward chaining example 5 Forward chaining example Forward chaining example 6 Forward chaining example Forward chaining example 7 Forward chaining example Forward chaining example 8 Backward chaining Idea: work backwards from the query q: to prove q by BC, check if q is known already, or prove by BC all premises of some rule concluding q Avoid loops: check if new subgoal is already on the goal stack Avoid repeated work: check if new subgoal Backward chaining example 9 Backward chaining example Backward chaining example 10 Backward chaining example Backward chaining example 11 Backward chaining example Backward chaining example 12 Backward chaining example Backward chaining example 13 Backward chaining example Forward vs. backward chaining • FC is data-‐driven, automaCc, unconscious processing, • May do lots of work that is irrelevant to the goal • BC is goal-‐driven, appropriate for problem-‐solving, • e.g., Where are my keys? How do I get into a PhD program? • Complexity of BC can be much less than linear in size of KB 14 Pros and cons of proposi=onal logic ProposiConal logic allows disjuncCve/negated informaCon • (unlike most data structures and databases) ProposiConal logic is composiConal: • meaning of B1,1 ∧ P1,2 is derived from meaning of B1,1 and of P1,2 Pros and cons of proposi=onal logic Meaning in proposiConal logic is context-‐independent • (unlike natural language, where meaning depends on context) ProposiConal logic has very limited expressive power • (unlike natural language) • E.g., cannot say "pits cause breezes in adjacent squares“ • except by wriCng one sentence for each square 15 Limita=ons of proposi=onal logic • World we want to represent and reason about consists of a number of objects with variety of properCes and relaCons • Two cases that are hard for proposiConal logic to represent • Statements about similar objects, or relaCons • Statement referring groups of objects 31 Limita=ons of proposi=onal logic • Statements about similar object, or relaCons need to be enumerated • Example: Seniority of people Tariq is older than Zeinab ∧Zeinab is older than Ali Tariq is older than Ali Khaled is older than Zeinab ∧Zeinab is older than Ali Khaled is older than Ali Problem: What if we have many people? Many rules to do 32 inference. 16 Limita=ons of proposi=onal logic • Example: Seniority of people Tariq is older than Zeinab ∧Zeinab is older than Ali Tariq is older than Ali Khaled is older than Zeinab ∧Zeinab is older than Ali Khaled is older than Ali • Problem: What if we have many people? • Solu=on: Introduce variables PersonA is older than PersonB ∧PersonB is older than PersonC 33 PersonA is older than PersonC Limita=ons of proposi=onal logic • Statement referring groups of objects require exhausCve enumeraCon of objects. • Example: • We want to express: Every student likes vacaCon • In proposiConal logic: • Abdulla likes vacaCon ∧ • Lamana likes vacaCon ∧ • Khaled likes vacaCon ∧ … • SoluCon: Allow quanCficaCon in statements 34 17 Limita=ons of proposi=onal logic • Statement referring groups of objects require exhausCve enumeraCon of objects. • Example: • We want to express: Every student likes vacaCon • In proposiConal logic: • • • Abdulla likes vacaCon ∧ Lamana likes vacaCon ∧ Khaled likes vacaCon ∧ … 35 First-‐order logic • ProposiConal logic assumes the world contains facts, • first-‐order logic (like natural language) assumes the world contains • Objects: people, houses, numbers, colors, baseball games, wars, … • RelaCons: red, round, prime, brother of, bigger than, part of, comes between, … • FuncCons: best friend, one more than, plus, … • QuanCfiers: statement for group objects 18 Syntax of FOL: Basic elements • • • • • • • Constants KingJohn, 2, CMUQ,... Predicates Brother, >,... FuncCons Sqrt, LekLegOf,... Variables x, y, a, b,... ConnecCves ¬, ⇒, ∧, ∨, ⇔ Equality = QuanCfiers ∀, ∃ Atomic sentences Atomic sentence: or predicate (term1,...,termn) term1 = term2 Term: func6on (term1,...,termn) or constant or variable • E.g., Brother(KingJohn, RichardTheLionheart) • > (Length(LeELegOf(Richard)), Length(LeELegOf(KingJohn))) 19 Complex sentences • Complex sentences are made from atomic sentences using connecCves ¬S, S1 ∧ S2, S1 ∨ S2, S1 ⇒ S2, S1 ⇔ S2 E.g. Sibling(KingJohn,Richard) ⇒ Sibling(Richard,KingJohn) >(1,2) ∨ ≤ (1,2) >(1,2) ∧ ¬ >(1,2) Truth in first-‐order logic • Sentences are true with respect to a model and an interpretaCon • Model contains objects (domain elements) and relaCons among them • InterpretaCon specifies referents for constant symbols predicate symbols funcCon symbols → → → objects relaCons funcConal relaCons • An atomic sentence predicate(term1,...,termn) is true iff the objects referred to by term1,...,termn are in the relaCon referred to by predicate 20 Universal quan=fica=on • ∀<variables> <sentence> Everyone at CMUQ is smart: ∀x At(x, CMUQ) ⇒ Smart(x) • ∀x P is true in a model m iff P is true with x being each possible object in the model Universal quan=fica=on • ∀<variables> <sentence> • Roughly speaking, equivalent to the conjuncCon of instanCaCons of P ∧ ∧ ∧ ... At(KingJohn, CMUQ) ⇒ Smart(KingJohn) At(Richard, CMUQ) ⇒ Smart(Richard) At(CMUQ, CMUQ) ⇒ Smart(CMUQ) 21 A common mistake to avoid • Typically, ⇒ is the main connecCve with ∀ • Common mistake: using ∧ as the main connecCve with ∀: ∀x At(x, CMUQ) ∧ Smart(x) means “Everyone is at CMUQ and everyone is smart” Existen=al quan=fica=on • ∃<variables> <sentence> • Someone at EC is smart: • ∃x At(x, EC) ∧ Smart(x) • ∃x P is true in a model m iff P is true with x being some possible object in the model 22 Existen=al quan=fica=on • ∃<variables> <sentence> • Roughly speaking, equivalent to the disjuncCon of instanCaCons of P At(KingJohn, EC) ∧ Smart(KingJohn) ∨ At(Richard, EC) ∧ Smart(Richard) ∨ At(EC, EC) ∧ Smart(EC) ∨ ... Another common mistake to avoid • Typically, ∧ is the main connecCve with ∃ • Common mistake: using ⇒ as the main connecCve with ∃: ∃x At(x, EC) ⇒ Smart(x) is true if there is anyone who is not at EC! 23 Proper=es of quan=fiers • ∀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 Prac=cing with transla=on • • • • • • There is a person who loves everybody Everybody loves Raymond Everybody loves somebody There is somebody whom everybody loves. There is somebody who Raymond doesn't love. There is somebody whom no one loves. 48 24 Prac=cing with transla=on • • • • • • There is a person who loves everybody Everybody loves Raymond Everybody loves somebody There is somebody whom everybody loves. There is somebody who Raymond doesn't love. There is somebody whom no one loves. 49 Proper=es of quan=fiers • ∀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” 25 Proper=es of quan=fiers • QuanCfier duality: each can be expressed using the other • Everybody loves ice cream • ∀x Likes(x,IceCream) ? • Someone likes brccoli • ∃x Likes(x,Broccoli) ? Proper=es of quan=fiers • QuanCfier duality: each can be expressed using the other • Everybody loves ice cream • ∀x Likes(x,IceCream) ¬∃x ¬Likes(x,IceCream) • Someone likes brccoli • ∃x Likes(x,Broccoli) ¬∀x ¬Likes(x,Broccoli) 26 Equality • term1 = term2 is true under a given interpretaCon if and only if term1 and term2 refer to the same object • E.g., definiCon of Sibling in terms of Parent: ∀x,y Sibling(x,y) ⇔ [¬(x = y) ∧ ∃m,f ¬ (m = f) ∧ Parent(m,x) ∧ Parent(f,x) ∧ Parent(m,y) ∧ Parent(f,y)] Using FOL: The kinship domain • Brothers are siblings ∀x,y Brother(x,y) ⇔ Sibling(x,y) • One's mother is one's female parent ∀m,c Mother(c) = m ⇔ (Female(m) ∧ Parent(m,c)) • “Sibling” is symmetric ∀x,y Sibling(x,y) ⇔ Sibling(y,x) 27
© Copyright 2026 Paperzz