32
First-order logic Chapter 8 Chapter 8 1

1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

First-orderlogic

Chapter8

Chapter81

Page 2: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Outline

♦WhyFOL?

♦SyntaxandsemanticsofFOL

♦Funwithsentences

♦WumpusworldinFOL

Chapter82

Page 3: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Prosandconsofpropositionallogic

Propositionallogicisdeclarative:piecesofsyntaxcorrespondtofacts

Propositionallogicallowspartial/disjunctive/negatedinformation(unlikemostdatastructuresanddatabases)

Propositionallogiciscompositional:meaningofB1,1∧P1,2isderivedfrommeaningofB1,1andofP1,2

Meaninginpropositionallogiciscontext-independent

(unlikenaturallanguage,wheremeaningdependsoncontext)

Propositionallogichasverylimitedexpressivepower(unlikenaturallanguage)E.g.,cannotsay“pitscausebreezesinadjacentsquares”

exceptbywritingonesentenceforeachsquare

Chapter83

Page 4: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

First-orderlogic

Whereaspropositionallogicassumesworldcontainsfacts,first-orderlogic(likenaturallanguage)assumestheworldcontains

•Objects:people,houses,numbers,theories,RonaldMcDonald,colors,baseballgames,wars,centuries...

•Relations:red,round,bogus,prime,multistoried...,brotherof,biggerthan,inside,partof,hascolor,occurredafter,owns,comesbetween,...

•Functions:fatherof,bestfriend,thirdinningof,onemorethan,endof...

Chapter84

Page 5: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Logicsingeneral

LanguageOntologicalEpistemologicalCommitmentCommitment

Propositionallogicfactstrue/false/unknownFirst-orderlogicfacts,objects,relationstrue/false/unknownTemporallogicfacts,objects,relations,timestrue/false/unknownProbabilitytheoryfactsdegreeofbeliefFuzzylogicfacts+degreeoftruthknownintervalvalue

Chapter85

Page 6: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

SyntaxofFOL:Basicelements

ConstantsKingJohn,2,UCB,...PredicatesBrother,>,...FunctionsSqrt,LeftLegOf,...Variablesx,y,a,b,...Connectives∧∨¬⇒⇔Equality=Quantifiers∀∃

Chapter86

Page 7: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Atomicsentences

Atomicsentence=predicate(term1,...,termn)orterm1=term2

Term=function(term1,...,termn)orconstantorvariable

E.g.,Brother(KingJohn,RichardTheLionheart)>(Length(LeftLegOf(Richard)),Length(LeftLegOf(KingJohn)))

Chapter87

Page 8: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Complexsentences

Complexsentencesaremadefromatomicsentencesusingconnectives

¬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)

Chapter88

Page 9: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Truthinfirst-orderlogic

Sentencesaretruewithrespecttoamodelandaninterpretation

Modelcontains≥1objects(domainelements)andrelationsamongthem

Interpretationspecifiesreferentsforconstantsymbols→objectspredicatesymbols→relationsfunctionsymbols→functionalrelations

Anatomicsentencepredicate(term1,...,termn)istrueifftheobjectsreferredtobyterm1,...,termn

areintherelationreferredtobypredicate

Chapter89

Page 10: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

ModelsforFOL:Example

RJ $

left legleft leg

on headbrother

brother

personpersonking

crown

Chapter810

Page 11: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Truthexample

ConsidertheinterpretationinwhichRichard→RichardtheLionheartJohn→theevilKingJohnBrother→thebrotherhoodrelation

Underthisinterpretation,Brother(Richard,John)istruejustincaseRichardtheLionheartandtheevilKingJohnareinthebrotherhoodrelationinthemodel

Chapter811

Page 12: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

ModelsforFOL:Lots!

Entailmentinpropositionallogiccanbecomputedbyenumeratingmodels

WecanenumeratetheFOLmodelsforagivenKBvocabulary:

Foreachnumberofdomainelementsnfrom1to∞Foreachk-arypredicatePkinthevocabulary

Foreachpossiblek-aryrelationonnobjectsForeachconstantsymbolCinthevocabulary

ForeachchoiceofreferentforCfromnobjects...

ComputingentailmentbyenumeratingFOLmodelsisnoteasy!

Chapter812

Page 13: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Universalquantification

∀〈variables〉〈sentence〉

EveryoneatBerkeleyissmart:∀xAt(x,Berkeley)⇒Smart(x)

∀xPistrueinamodelmiffPistruewithxbeingeachpossibleobjectinthemodel

Roughlyspeaking,equivalenttotheconjunctionofinstantiationsofP

(At(KingJohn,Berkeley)⇒Smart(KingJohn))∧(At(Richard,Berkeley)⇒Smart(Richard))∧(At(Berkeley,Berkeley)⇒Smart(Berkeley))∧...

Chapter813

Page 14: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Acommonmistaketoavoid

Typically,⇒isthemainconnectivewith∀

Commonmistake:using∧asthemainconnectivewith∀:

∀xAt(x,Berkeley)∧Smart(x)

means“EveryoneisatBerkeleyandeveryoneissmart”

Chapter814

Page 15: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Existentialquantification

∃〈variables〉〈sentence〉

SomeoneatStanfordissmart:∃xAt(x,Stanford)∧Smart(x)

∃xPistrueinamodelmiffPistruewithxbeingsomepossibleobjectinthemodel

Roughlyspeaking,equivalenttothedisjunctionofinstantiationsofP

(At(KingJohn,Stanford)∧Smart(KingJohn))∨(At(Richard,Stanford)∧Smart(Richard))∨(At(Stanford,Stanford)∧Smart(Stanford))∨...

Chapter815

Page 16: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Anothercommonmistaketoavoid

Typically,∧isthemainconnectivewith∃

Commonmistake:using⇒asthemainconnectivewith∃:

∃xAt(x,Stanford)⇒Smart(x)

istrueifthereisanyonewhoisnotatStanford!

Chapter816

Page 17: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Propertiesofquantifiers

∀x∀yisthesameas∀y∀x(why??)

∃x∃yisthesameas∃y∃x(why??)

∃x∀yisnotthesameas∀y∃x

∃x∀yLoves(x,y)“Thereisapersonwholoveseveryoneintheworld”

∀y∃xLoves(x,y)“Everyoneintheworldislovedbyatleastoneperson”

Quantifierduality:eachcanbeexpressedusingtheother

∀xLikes(x,IceCream)¬∃x¬Likes(x,IceCream)

∃xLikes(x,Broccoli)¬∀x¬Likes(x,Broccoli)

Chapter817

Page 18: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Funwithsentences

Brothersaresiblings

Chapter818

Page 19: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Funwithsentences

Brothersaresiblings

∀x,yBrother(x,y)⇒Sibling(x,y).

“Sibling”issymmetric

Chapter819

Page 20: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Funwithsentences

Brothersaresiblings

∀x,yBrother(x,y)⇒Sibling(x,y).

“Sibling”issymmetric

∀x,ySibling(x,y)⇔Sibling(y,x).

One’smotherisone’sfemaleparent

Chapter820

Page 21: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Funwithsentences

Brothersaresiblings

∀x,yBrother(x,y)⇒Sibling(x,y).

“Sibling”issymmetric

∀x,ySibling(x,y)⇔Sibling(y,x).

One’smotherisone’sfemaleparent

∀x,yMother(x,y)⇔(Female(x)∧Parent(x,y)).

Afirstcousinisachildofaparent’ssibling

Chapter821

Page 22: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Funwithsentences

Brothersaresiblings

∀x,yBrother(x,y)⇒Sibling(x,y).

“Sibling”issymmetric

∀x,ySibling(x,y)⇔Sibling(y,x).

One’smotherisone’sfemaleparent

∀x,yMother(x,y)⇔(Female(x)∧Parent(x,y)).

Afirstcousinisachildofaparent’ssibling

∀x,yFirstCousin(x,y)⇔∃p,psParent(p,x)∧Sibling(ps,p)∧Parent(ps,y)

Chapter822

Page 23: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Equality

term1=term2istrueunderagiveninterpretationifandonlyifterm1andterm2refertothesameobject

E.g.,1=2and∀x×(Sqrt(x),Sqrt(x))=xaresatisfiable2=2isvalid

E.g.,definitionof(full)SiblingintermsofParent:∀x,ySibling(x,y)⇔[¬(x=y)∧∃m,f¬(m=f)∧

Parent(m,x)∧Parent(f,x)∧Parent(m,y)∧Parent(f,y)]

Chapter823

Page 24: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

InteractingwithFOLKBs

Supposeawumpus-worldagentisusinganFOLKBandperceivesasmellandabreeze(butnoglitter)att=5:

Tell(KB,Percept([Smell,Breeze,None],5))Ask(KB,∃aAction(a,5))

I.e.,doesKBentailanyparticularactionsatt=5?

Answer:Yes,{a/Shoot}←substitution(bindinglist)

GivenasentenceSandasubstitutionσ,SσdenotestheresultofpluggingσintoS;e.g.,S=Smarter(x,y)σ={x/Hillary,y/Bill}Sσ=Smarter(Hillary,Bill)

Ask(KB,S)returnssome/allσsuchthatKB|=Sσ

Chapter824

Page 25: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Knowledgebaseforthewumpusworld

“Perception”∀b,g,tPercept([Smell,b,g],t)⇒Smelt(t)∀s,b,tPercept([s,b,Glitter],t)⇒AtGold(t)

Reflex:∀tAtGold(t)⇒Action(Grab,t)

Reflexwithinternalstate:dowehavethegoldalready?∀tAtGold(t)∧¬Holding(Gold,t)⇒Action(Grab,t)

Holding(Gold,t)cannotbeobserved⇒keepingtrackofchangeisessential

Chapter825

Page 26: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Deducinghiddenproperties

Propertiesoflocations:∀x,tAt(Agent,x,t)∧Smelt(t)⇒Smelly(x)∀x,tAt(Agent,x,t)∧Breeze(t)⇒Breezy(x)

Squaresarebreezynearapit:

Diagnosticrule—infercausefromeffect∀yBreezy(y)⇒∃xPit(x)∧Adjacent(x,y)

Causalrule—infereffectfromcause∀x,yPit(x)∧Adjacent(x,y)⇒Breezy(y)

Neitheroftheseiscomplete—e.g.,thecausalruledoesn’tsaywhethersquaresfarawayfrompitscanbebreezy

DefinitionfortheBreezypredicate:∀yBreezy(y)⇔[∃xPit(x)∧Adjacent(x,y)]

Chapter826

Page 27: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Keepingtrackofchange

Factsholdinsituations,ratherthaneternallyE.g.,Holding(Gold,Now)ratherthanjustHolding(Gold)

SituationcalculusisonewaytorepresentchangeinFOL:Addsasituationargumenttoeachnon-eternalpredicateE.g.,NowinHolding(Gold,Now)denotesasituation

SituationsareconnectedbytheResultfunctionResult(a,s)isthesituationthatresultsfromdoingains

PIT

PIT

PIT

Gold

PIT

PIT

PIT

Gold

S0

Forward

S1

Chapter827

Page 28: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

DescribingactionsI

“Effect”axiom—describechangesduetoaction∀sAtGold(s)⇒Holding(Gold,Result(Grab,s))

“Frame”axiom—describenon-changesduetoaction∀sHaveArrow(s)⇒HaveArrow(Result(Grab,s))

Frameproblem:findanelegantwaytohandlenon-change(a)representation—avoidframeaxioms(b)inference—avoidrepeated“copy-overs”tokeeptrackofstate

Qualificationproblem:truedescriptionsofrealactionsrequireendlesscaveats—whatifgoldisslipperyornaileddownor...

Ramificationproblem:realactionshavemanysecondaryconsequences—whataboutthedustonthegold,wearandtearongloves,...

Chapter828

Page 29: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

DescribingactionsII

Successor-stateaxiomssolvetherepresentationalframeproblem

Eachaxiomis“about”apredicate(notanactionperse):

Ptrueafterwards⇔[anactionmadePtrue

∨PtruealreadyandnoactionmadePfalse]

Forholdingthegold:∀a,sHolding(Gold,Result(a,s))⇔

[(a=Grab∧AtGold(s))∨(Holding(Gold,s)∧a6=Release)]

Chapter829

Page 30: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Makingplans

InitialconditioninKB:At(Agent,[1,1],S0)At(Gold,[1,2],S0)

Query:Ask(KB,∃sHolding(Gold,s))i.e.,inwhatsituationwillIbeholdingthegold?

Answer:{s/Result(Grab,Result(Forward,S0))}i.e.,goforwardandthengrabthegold

ThisassumesthattheagentisinterestedinplansstartingatS0andthatS0

istheonlysituationdescribedintheKB

Chapter830

Page 31: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Makingplans:Abetterway

Representplansasactionsequences[a1,a2,...,an]

PlanResult(p,s)istheresultofexecutingpins

ThenthequeryAsk(KB,∃pHolding(Gold,PlanResult(p,S0)))hasthesolution{p/[Forward,Grab]}

DefinitionofPlanResultintermsofResult:∀sPlanResult([],s)=s∀a,p,sPlanResult([a|p],s)=PlanResult(p,Result(a,s))

Planningsystemsarespecial-purposereasonersdesignedtodothistypeofinferencemoreefficientlythanageneral-purposereasoner

Chapter831

Page 32: 1 8 Chapteraima.eecs.berkeley.edu/2nd-ed/slides-pdf/chapter08.pdf · 2004. 2. 27. · Chapter 8 Chapter 8 1. Outline} Why F OL?} Syntax and semantics of F OL} F un with sentences}

Summary

First-orderlogic:–objectsandrelationsaresemanticprimitives–syntax:constants,functions,predicates,equality,quantifiers

Increasedexpressivepower:sufficienttodefinewumpusworld

Situationcalculus:–conventionsfordescribingactionsandchangeinFOL–canformulateplanningasinferenceonasituationcalculusKB

Chapter832