390 likes | 528 Views
Inference in FOL [AIMA Ch. 9]. R e du c i n g f i rs t - o r d e r i n fe re n ce to p r opo s i t i o n al i n fe re n ce U n i f i c at i o n Ge n e r a li z ed M odu s P on e n s F o r w ard a n d b ack w a r d c h a i n i n g L og i c p r o g r a mm i n g R es o l u t i o n.
E N D
Inference in FOL [AIMA Ch. 9] • Reducingfirst-orderinferencetopropositionalinference • Unification • GeneralizedModusPonens • Forwardandbackwardchaining • Logicprogramming • Resolution
A brief history of reasoning Stoics Aristotle Cardano propositionallogic,inference(maybe) “syllogisms”(inferencerules),quantifiers probabilitytheory(propositional logic+ uncertainty) propositionallogic (again) first-order logic proofbytruth tables ∃completealgorithm for FOL completealgorithm for FOL(reduceto propositional) ¬∃completealgorithm for arithmetic “practical” algorithm for propositional logic “practical” algorithm for FOL—resolution 450b.c. 322b.c. 1565 Boole Frege Wittgenstein Gödel Herbrand 1847 1879 1922 1930 1930 Gödel Davis/Putnam 1931 1960 1965 Robinson
Universal instantiation (UI) • Everyinstantiationofauniversallyquantifiedsentence isentailedby it: • ∀vα • SUBST({v/g},α) • forany variablevand groundtermg • E.g.,∀xKing(x)∧Greedy(x)⇒Evil(x)yieldsKing(John)∧Greedy(John)⇒Evil(John) King(Richard)∧Greedy(Richard)⇒Evil(Richard) • King(Father(John))∧Greedy(Father(John))⇒Evil(Father(John)) • …
Existential instantiation (EI) • Foranysentenceα,variablev,andconstant symbol kthat does not appearelsewherein theknowledgebase: • ∃vα • SUBST({v/k},α) • E.g.,∃xCrown(x)∧OnHead(x,John) • Crown(C1)∧OnHead(C1,John) yields providedC1 isa newconstantsymbol,calledaSkolemconstant • Anotherexample:from∃xd(xy)/dy=xy • d(ey)/dy=ey • providedeis anewconstantsymbol weobtain
Existential instantition contd. • UIcanbeappliedseveraltimes toaddnewsentences; thenewKB islogicallyequivalenttotheold • EIcanbe appliedoncetoreplacetheexistentialsentence; thenewKB isnotequivalenttotheold,butissatisfiableiff theold KB wassatisfiable
Reduction to propositional inference SupposetheKB containsjustthefollowing: ∀xKing(x)∧Greedy(x)⇒Evil(x) King(John) Greedy(John) Brother(Richard,John) Instantiatingtheuniversalsentenceinallpossibleways,wehave King(John)∧Greedy(John)⇒Evil(John) King(Richard)∧Greedy(Richard)⇒Evil(Richard) King(John) Greedy(John) Brother(Richard,John) ThenewKB is propositionalized:propositionsymbols are King(John),Greedy(John),Evil(John),King(Richard)etc.
Reduction contd. • Claim: agroundsentenceisentailedby newKBiff entailed by originalKB • Claim:everyFOLKBcan bepropositionalizedsoas to preserveentailment • Idea:propositionalizeKBandquery,applyresolution,returnresult • Problem:withfunctionsymbols,thereareinfinitelymanygroundterms, • e.g.,Father(Father(Father(John)))
Reduction contd. • Theorem: Herbrand(1930).Ifasentence αisentailed by anFOLKB,itisentailedby afinitesubsetofthepropositionalKB • Idea:Forn= 0to ∞do • createapropositionalKBby instantiatingwith depth-ntermsandseeifαisentailed byKB • Problem:worksifαisentailed,loopsifαisnot entailed • Theorem:Turing(1936),Church(1936), entailmentinFOLis semidecidable
Problems with propositionalization • Propositionalizationseemstogeneratelotsofirrelevant sentences. • E.g.,from • ∀x King(x)∧Greedy(x)⇒Evil(x) King(John) • ∀yGreedy(y) Brother(Richard,John) • itseemsobvious thatEvil(John),butpropositionalization produceslotsoffactssuchasGreedy(Richard)thatare irrelevant • Withpk-arypredicatesandnconstants,therearep·nk • instantiations • Withfunctionsymbols,itgetsmuchmuchworse!
Unification • Wecangettheinferenceimmediately ifwecanfind asubstitutionθsuchthatKing(x)andGreedy(x) matchKing(John)andGreedy(y) • θ={x/John,y/John}works • UNIFY(α,β)=θif αθ=βθ p q θ Knows(John,x) Knows(John,x) Knows(John,x) Knows(John,x) Knows(John,Jane) Knows(y,OJ) Knows(y,Mother(y)) Knows(x,OJ) {x/Jane} {x/OJ,y/John} {y/John,x/Mother(John)} fail Standardizing aparteliminates overlapofvariables,e.g.,Knows(z17,OJ)
Generalized Modus Ponens (GMP) p1’,p2’,…,pn’,(p1 ∧p2 ∧…∧pn ⇒q) qθ • wherepi’θ=piθforall i • p1’isKing(John) • p2’isGreedy(y) • θis {x/John,y/John} • q θis Evil(John) p1 isKing(x) p2is Greedy(x) qis Evil(x) GMPusedwithKBofdefiniteclauses(exactlyonepositive literal) Allvariables assumeduniversally quantified
Soundness of GMP Needtoshowthat p1’,p2’,…,pn’,(p1 ∧p2 ∧…∧pn ⇒q)╞qθ providedthatpi’θ=piθforall i Lemma:Forany definiteclausep,wehavep╞pθby UI 1.(p1 ∧p2 ∧…∧pn ⇒q)╞(p1 ∧p2 ∧…∧pn ⇒q)θ= (p1θ∧p2θ ∧…∧pnθ⇒qθ) 2.p1’,p2’,…,pn’╞p1’∧p2’∧…∧pn’╞p1’θ∧p2’θ∧…∧pn’θ 3.From 1and2,qfollowsbyordinaryModusPonens
Example knowledge base • Thelaw saysthatit isacrimeforanAmericantosellweaponstohostilenations. ThecountryNono,anenemy ofAmerica,hassomemissiles,andallofitsmissiles weresoldtoit byColonelWest, whoisAmerican. • ProvethatCol.Westisacriminal
Example knowledge base contd. …it is a crimefor an Americanto sellweaponsto hostilenations: American(x)∧Weapon(y)∧Sells(x,y,z)∧Hostile(z)⇒Criminal(x) • Owns(Nono,M)andMissile(M) • …all of its missiles weresold to itbyColonolWest • ∀x Missile(x)∧Owns(Nono,x)⇒Sells(West,x,Nono) • Missilesareweapons: • Missile(x)⇒Weapon(x) • An enemyofAmericacounts as “hostile”: • Enemy(x,America)⇒Hostile(x) • West,whois American… • American(west) • Thecountry Non,an enemyofAmerica • Enemy(Nono,America) Nono…has somemissiles,i.e., ∃xOwns(Nono,x)∧Missile(x):
Properties of forward chaining • Sound andcompleteforfirst-orderdefiniteclauses (proofsimilartopropositionalproof) • Datalog=first-orderdefiniteclauses+nofunctions(e.g.,crimeKB) • FC terminatesforDataloginpolyiterations:at mostp·nkliterals • May notterminateingeneralif αisnotentailed • Thisisunavoidable:entailmentwithdefiniteclausesissemidecidable
Efficiency of forward chaining • Simple observation:noneedtomatcharuleoniterationkifa premisewasn'tadded oniterationk-1 • ⇒matcheachrulewhosepremisecontainsa newlyaddedliteral • Matchingitselfcanbeexpensive • DatabaseindexingallowsO(1)retrievalofknownfacts e.g.,queryMissile(x)retrievesMissile(M1) • Matchingconjunctivepremisesagainstknownfactsis NP-hard • Forwardchainingis widelyusedin deductivedatabases
Hard matching example • Colorable()isinferrediffthe CSPhasa solution • CSPsinclude3SATasa specialcase, hence matchingisNP-hard
Properties of backward chaining Depth-firstrecursiveproofsearch:spaceis linear insizeof proof Incompletedueto infinite loops ⇒fix bycheckingcurrentgoalagainsteverygoalonstack Inefficientduetorepeatedsubgoals(bothsuccessandfailure) ⇒fixusingcachingof previousresults(extraspace!) Widelyused(withoutimprovements!)forlogicprogramming
Logic programming • Soundbite:computation asinferenceonlogicalKBs OrdinaryprogrammingIdentifyproblem Assembleinformation Figureoutsolution Programsolution Encodeproblemasdata Apply program todata Debugproceduralerrors Logicprogramming Identifyproblem Assemble information Teabreak EncodeinformationinKB Encodeproblemasfacts Askqueries Findfalsefacts ShouldbeeasiertodebugCapital(NewYork,US)thanx:=x+ 2!
Prolog systems • Basis:backwardchainingwithHornclauses+ bells&whistles WidelyusedinEurope,Japan(basisof 5thGenerationproject) Compilationtechniques⇒approachingabillionLIPS • Program=setofclauses=head :- literal1,… literaln. • criminal(X):- american(X), weapon(Y), sells(X,Y,Z), hostile(Z). • Efficientunificationby opencoding • Efficientretrievalof matchingclausesby directlinking • Depth-first,left-to-rightbackwardchaining • Built-in predicatesforarithmetic etc.,e.g.,X isY*Z+3 • Closed-worldassumption(“negationasfailure”) e.g.,givenalive(X) :- not dead(X). alive(joe)succeedsifdead(joe)fails
Prolog examples Depth-firstsearchfromastartstate X: No need toloopoverS:successorsucceedsforeach Appendingtwoliststo produceathird: append([],Y,Y). append([X|L],Y,[X|Z]) :-append(L,Y,Z). query: append(A,B,[1,2]) ?
Resolution: brief summary Fullfirst-orderversion: l1 ∨ …∨ lk,m1 ∨ …∨ mn (l1 ∨ …li-1 ∨ li+1 ∨…∨ lk ∨m1 ∨ …∨ mj-1 ∨mj+1 ∨ …∨ mn)θ whereUNIFY(li,¬mj)=θ. Forexample, ¬Rich(x)∨ Unhappy(x) Rich(Ken) Unhappy(Ken) withθ={x/Ken} Apply resolutionstepstoCNF(KB∧ ¬α);completeforFOL