550 likes | 670 Views
Knowledge Representation & Reasoning. Lecture 4 & 5 : Predicate Logic or First Order Logic (FOL). Motivation. Propositional logic is declarative Propositional logic allows partial/disjunctive/negated information (unlike most data structures and databases)
E N D
Knowledge Representation & Reasoning Lecture 4 & 5 : Predicate Logic or First Order Logic (FOL)
TP2623, shereen@ftsm.ukm.my Motivation Propositional logic is declarative • Propositional logic allows partial/disjunctive/negated information • (unlike most data structures and databases) • Propositional logic is compositional: • meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2 • Meaning in propositional logic is context-independent • (unlike natural language, where meaning depends on context) • Propositional logic has very limited expressive power • (unlike natural language) • E.g., cannot say “pits cause breezes in adjacent squares” • except by writing one sentence for each square
TP2623, shereen@ftsm.ukm.my Predicates and Constants • Let's consider the statements: Mariam is female Johan is male Mary and John are siblings • In propositional logic the above statements are atomic propositions: P = Mariam-is-female Q = Johan-is-male R = Mariam-and-Johan-are-siblings • In FOL atomic statements use predicates, with constants as argument: female(mariam) male(johan) siblings(mariam,johan)
TP2623, shereen@ftsm.ukm.my Variables and Quantifiers • Let's consider the statements: Everybody is male or female A male is not a female • In FOL predicates may have variables as arguments, whose value is bounded by quantifiers: • x. Male(x) Female(x) • x. Male(x) Female(x) • Deduction (why?): Mariam is not male male(mariam)
TP2623, shereen@ftsm.ukm.my Functions Let’s consider the statement: • The father of a person is male In FOL, objects of the domain may be denoted by functions applied to (other) objects: x. male(father(x))
TP2623, shereen@ftsm.ukm.my FOL Syntax • User define these primitives • Constant symbols (i.e. the “individuals” in the world), e.g. Mariam, 3 • Function symbols (mapping individuals to individuals), e.g. father-of(mariam)=johan; colour-of(sky)=blue • Predicate symbols (mapping from individuals to truth value), e.g. greater(5,3), green(grass), colour(grass,green)
TP2623, shereen@ftsm.ukm.my FOL Syntax • FOL supplies these primitives • Variable symbols. e.g. x, y • Connectives. Same as PL • Quantifiers: Universal () and existential () • corresponds to conjunction () • corresponds to disjunction () • usually used with “implies” to form (if then rules) • usually used with “and” to specify a list of properties or facts about an individual • Switching the order of does not change the meaning • Switching the order of does not change the meaning • Switching the order of and does change the meaning
TP2623, shereen@ftsm.ukm.my Summary of FOL Syntax: Basic Elements • Constants Mariam, 2, UKM,... • Predicates Brother, >,... • Functions Sqrt, LeftSideOf,... • Variables x, y, a, b,... • Connectives , , , , • Equality = • Quantifiers ,
TP2623, shereen@ftsm.ukm.my Atomic Sentences • Sentences are built from terms and atoms: • A term is a logical expression that refers to an object Term = function (term1,...,termn) or constant or variable • An atomic sentence is an n-place predicate of n terms Atomic sentence = predicate (term1,...,termn) or term1 = term2 • A well formed formula (wff) is an atomic sentence containing no free variables, i.e. all variables are “bound” by universal or existential quantifiers.
TP2623, shereen@ftsm.ukm.my Atomic sentence • Atomic sentence can have complex terms Friend-of(Father(Ahmad), Father(Ali)) Ahmad’s father is a friend of Ali’s father • We can use logical connectives to construct more complex sentences x (Pemandu(x) ⌐Penumpang(x)) Untuksetiap yang menjadipemandumerekaadalahbukanpenumpang x,y (Melatih(x,y) (Jurulatih(x) Pelatih(y))) x,y (DrivingExperience(x,y) (Driver(x) Passenger(y))) Untuksetiap yang melatihorang lain, seorangakanmenjadijurulatihdanseoranglagimenjadipelatih
TP2623, shereen@ftsm.ukm.my Universal quantification • <variables> <sentence> Everyone at UKM is smart: x. At(x,UKM) Smart(x) • x P is true in a model m,iffP is true with x being each possible object in the model • Roughly speaking, equivalent to the conjunction of instantiations of P At(Ahmad,UKM) Smart(Ahmad) At(Ali, UKM) Smart(Ali) At(Aminah, UKM) Smart(Aminah) ...
TP2623, shereen@ftsm.ukm.my A common mistake to avoid • Typically, is the main connective with • Common mistake: using as the main connective with : x At(x,UKM) Smart(x) means “Everyone is at UKM and everyone is smart”
TP2623, shereen@ftsm.ukm.my Existential quantification • <variables> <sentence> • Someone at UKM is smart: • x At(x,UKM) 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(Ahmad,UKM) Smart(Ahmad) At(Ali,UKM) Smart(Ali) At(Aminah,UKM) Smart(Aminah) ...
TP2623, shereen@ftsm.ukm.my Another common mistake to avoid • Typically, is the main connective with • Common mistake: using as the main connective with : x At(x,UKM) Smart(x) is true if there is anyone who is not at UKM! Also means that some people at UKM are smart, but also say that some people who are not at UKM are also smart.
TP2623, shereen@ftsm.ukm.my Properties of quantifiers • x y is the same as yx • x y is the same as yx • x y is not the same as yx • x y Loves(x,y) • “There is a person who loves everyone in the world” • yx 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) • Everyone likes ice cream There is no one who does not like ice cream • x Likes(x,Broccoli) xLikes(x,Broccoli) • Someone likes broccoli not all people does not like broccoli
TP2623, shereen@ftsm.ukm.my Equality • term1 = term2is true under a given interpretation if and only if term1and term2refer to the same object • E.g., definition of Sibling in terms of Parent: x,ySibling(x,y) [(x = y) m,f (m = f) Parent(m,x) Parent(f,x) Parent(m,y) Parent(f,y)]
TP2623, shereen@ftsm.ukm.my Translating language to FOL • Semua petani suka matahari • Semua cendawan ungu adalah beracun • Tiada cendawan ungu yang beracun • Terdapat dua cendawan ungu • Ali tidak tinggi
TP2623, shereen@ftsm.ukm.my Example FOL • Hubungan keluarga • Ibu, suami, isteri, IbuBapa(parent) dll • Ibu kepada inidvidu adalah merupakan IbuBapa perempuan individu tersebut m,c Ibu(c) = m (Perempuan(m) IbuBapa(m,c)) • Lelaki & perempuan adalah hubungan disjoint xLelaki(x) Perempuan(x) • IbuBapa dan anak adalah hubungan inverse(berbalik) p,cIbuBapa(p,c)Child(c,p) • Datok ialah IbuBapa kepada IbuBapa seorang individu g,cDatok(g,c) p IbuBapa(g,p) ∧IbuBapa(p,c)
TP2623, shereen@ftsm.ukm.my Bird Example • Every normal bird can fly • An ostrich is a bird and not a normal bird • A whirlybird is not a normal bird • A whirlybird is not a bird • Every object that is not a bird that is not normal is either a normalbird or a whirlybird • Tweety is a bird • Tweety is not a normal bird • Tweety has her wings clipped • There are precisely two individuals that are parents of Tweety,and they are both normal birds.
TP2623, shereen@ftsm.ukm.my Interpreting the Bird Example • Domain • {birds whirlybird} • Assign Constants • Tweety • Assign Functions • none • Assign Predicate Symbols • Bird(x) • Normal(x) • Can-fly(x) • Ostrich(x) • Whirlybird(x) • Clipped-wings(x) • Parent(x, Tweety) • Equals(x, y) • Every normal bird can fly • An ostrich is a bird and not a normal bird • A whirlybird is not a normal bird • A whirlybird is not a bird • Every object that is not a bird that is not normal is either a normalbird or a whirlybird • Tweety is a bird • Tweety is not a normal bird • Tweety has her wings clipped • There are precisely two individuals that are parents of Tweety,and they are both normal birds.
TP2623, shereen@ftsm.ukm.my Bird Example • Every normal bird can fly x [ (Bird(x) Normal(x)) Can-fly(x) ] • An ostrich is a bird and not a normal bird x [ (Ostrich(x) (Bird(x) Normal (x)) ] • A whirlybird is not a normal bird x [ (Whirlybird(x) (Bird(x) Normal (x) ) ] • A whirlybird is not a bird x [ (Whirlybird(x) Bird(x)) ]
TP2623, shereen@ftsm.ukm.my Bird Example • Every object that is not a bird that is not normal is either a normal bird or a whirlybird x [(Bird(x) Normal(x)) ((Normal (x) (Bird(x)) Whirlybird(x))] • Tweety is a bird Bird(Tweety) • Tweety is not a normal bird (Normal (Tweety) Bird(Tweety)) • Tweety has her wings clipped Clipped-wings(Tweety)
TP2623, shereen@ftsm.ukm.my Bird Example • There are precisely two individuals that are parents of Tweety, and they are both normal birds. x y [Equals(x, y) Parent(x, Tweety) Parent(y, Tweety) [z (parent(z, Tweety) (equals (z, x) Equals (z, y))) ] ] x [ (Parent(x, Tweety) (normal(x) Bird (x)) ]
TP2623, shereen@ftsm.ukm.my Exercise Translate the following sentences into FOL • Everything is bitter or sweet. (Semua benda adalah pahit atau manis) • Either everything is bitter or everything is sweet. (Sama ada semua pahit atau semua benda manis) • There is somebody who is loved by everyone. (Ada seseorang yang disukai oleh semua) • If someone is noisy, everybody is annoyed.(Jika seseorang bising, maka semua orang lain akan marah)
TP2623, shereen@ftsm.ukm.my Background • Inference rules for PL apply to FOL. For example: modus ponens, and-introduction, and-elimination • New rules for use with quantifiers: • Universal instantiation • Existential instantiation • Existential elimination
TP2623, shereen@ftsm.ukm.my INFERENCE IN FIRST-ORDER LOGIC • Reducing first-order inference to propositional inference • Unification • First-order inference algorithms • Forward chaining • Deductive database and production systems • Backward chaining and logic programming • Resolution-based theorem proving
TP2623, shereen@ftsm.ukm.my Propositional vs First-Order Inference • Inference rules for quantifiers • Infer the following sentences: King(John) ^ Greedy(John) => Evil(John) King(Richard) ^ Greedy(Richard) => Evil(Richard) King(Father(John)) ^ Greedy(Father(John)) => Evil(Father(John)) …
TP2623, shereen@ftsm.ukm.my Universal Instantiation (UI) Rule • Infer any sentence obtained by substituting a ground term for the variable. • Ground term: a term without variables (i.e g). Where Subst(θ,α) is the result of applying the substitution θ to the sentence α for any variable v and ground term g • E.g. The three sentences given earlier: {x/John}, {x/Richard}, and {x/Father(John)}
TP2623, shereen@ftsm.ukm.my Existential Instantiation (EI) Rule • For any sentence α, variable v, and constant symbol k that does not appear elsewhere in KB, E.g. yields Crown(C1) ^ OnHead(C1, John) Provided that C1 is a new constant symbol, called a Skolem constant. • The existential sentence says that there is some object satisfying a condition, and the instantiation process is just giving a name to the object.
TP2623, shereen@ftsm.ukm.my Inference rules for quantifiers (Cont’d) • UI can be applied several times to add new sentences; the new KB is logically equivalent to the old. • EI can be applied once to replace the existential sentence; the new KB is not logically equivalent to the old, but is satisfiable iff the old KB is satisfiable, called inferentially equivalent.
TP2623, shereen@ftsm.ukm.my Reduction to Propositional inference • Suppose the KB contains just the following: King(John) Greedy(John) Brother(Richard, John) • Apply UI to the first sentence using all possible ground term substitution from the vocabulary of the KB, e.g. {x/John} and {x/Richard}: King(John) ^ Greedy(John) => Evil(John) King(Richard) ^ Greedy(Richard) => Evil(Richard) • And discard the universally quantified sentence.
TP2623, shereen@ftsm.ukm.my Unification • Unification is a process of finding substitutions that make different logical expressions look identical. • UNIFY algorithm takes two sentences and return a unifier for them if one exist: UNIFY(p,q) = θ where SUBST(θ,p) = SUBST(θ,q) • 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}
Unification (Cont’d) TP2623, shereen@ftsm.ukm.my • E.g. Query: Knows(John, x): • Whom does John know? • Answers: Find all sentences in the KB that unify with Knows(John, x). • Results of unification with four diff sentences in KB: • Standardizing apart eliminates overlap of variables, e.g. Knows(z17, Elizabeth)
TP2623, shereen@ftsm.ukm.my Generalized Modus Ponens (GMP) • First-order inference rule King(John) Greedy(John) • Inference process for John is evil: • Find some x such that x is a king and x is greedy • Infer that this x is evil • If there is some substitution θ that makes the premise of the implication identical to the sentences already in the KB, then assert the conclusion of the implication, after applying θ.
TP2623, shereen@ftsm.ukm.my GMP (Cont’d) • More general inference step, where everyone is also greedy: • Conclusion: Evil(John) • John is a king • John is greedy (because everyone is greedy) • For atomic sentences pi, pi’, and q, where there is a substitution θ such that SUBST(θ,pi’) = SUBST(θ, pi), for all i,
TP2623, shereen@ftsm.ukm.my GMP (Cont’d) • There are n+1 premises to this rule: • n atomic sentences pi’ • 1 implication • The conclusion is the result of applying the substitution θ to the consequent q. • E.g.: 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) SUBST(θ,q) is Evil(John)
TP2623, shereen@ftsm.ukm.my Example knowledge base • 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. • Prove that Col. West is a criminal
TP2623, shereen@ftsm.ukm.my Example knowledge base 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)
TP2623, samn@ftsm.ukm.my Forward chaining algorithm
TP2623, shereen@ftsm.ukm.my Forward chaining proof
TP2623, shereen@ftsm.ukm.my Forward chaining proof
TP2623, shereen@ftsm.ukm.my Forward chaining proof
TP2623, shereen@ftsm.ukm.my Properties of forward chaining • Sound and complete for first-order definite clauses • Datalog = first-order definite clauses + no functions • FC terminates for Datalog in finite number of iterations • May not terminate in general if α is not entailed Forward chaining is widely used in deductive databases
TP2623, shereen@ftsm.ukm.my Backward chaining algorithm SUBST(COMPOSE(θ1, θ2), p) = SUBST(θ2, SUBST(θ1, p))
TP2623, shereen@ftsm.ukm.my Backward chaining example
TP2623, shereen@ftsm.ukm.my Backward chaining example
TP2623, shereen@ftsm.ukm.my Backward chaining example
TP2623, shereen@ftsm.ukm.my Backward chaining example
TP2623, shereen@ftsm.ukm.my Backward chaining example