CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order...

64
CS 416 Artificial Intelligence Lecture 11 Lecture 11 First-Order Logic First-Order Logic Chapters 8 and 9 Chapters 8 and 9

Transcript of CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order...

Page 1: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

CS 416Artificial Intelligence

Lecture 11Lecture 11

First-Order LogicFirst-Order Logic

Chapters 8 and 9Chapters 8 and 9

Lecture 11Lecture 11

First-Order LogicFirst-Order Logic

Chapters 8 and 9Chapters 8 and 9

Page 2: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Midterm

October 25October 25thth

Up through chapter 9 (excluding chapter 5)Up through chapter 9 (excluding chapter 5)

October 25October 25thth

Up through chapter 9 (excluding chapter 5)Up through chapter 9 (excluding chapter 5)

Page 3: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Review

We were talking about a replacement of We were talking about a replacement of propositional logic: first-order logicpropositional logic: first-order logic

We’re just getting started with the definition of the We’re just getting started with the definition of the languagelanguage

We were talking about a replacement of We were talking about a replacement of propositional logic: first-order logicpropositional logic: first-order logic

We’re just getting started with the definition of the We’re just getting started with the definition of the languagelanguage

Page 4: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Formal structure of first-order logicModels of first-order logic contain:Models of first-order logic contain:

• DomainDomain: a set of objects : a set of objects

– Alice, Alice’s left arm, Bob, Bob’s hat Alice, Alice’s left arm, Bob, Bob’s hat

• RelationshipsRelationships between objects between objects

– Represented as Represented as tuplestuples

Sibling (Alice, Bob), Sibling (Bob, Alice)Sibling (Alice, Bob), Sibling (Bob, Alice)

On head (Bob, hat)On head (Bob, hat)

Person (Bob), Person (Alice)Person (Bob), Person (Alice)

– Some relationships are Some relationships are functionsfunctions if a given object is related to exactly if a given object is related to exactly one object in a certain wayone object in a certain way

leftArm(Alice) leftArm(Alice) Alice’s left arm Alice’s left arm

Models of first-order logic contain:Models of first-order logic contain:

• DomainDomain: a set of objects : a set of objects

– Alice, Alice’s left arm, Bob, Bob’s hat Alice, Alice’s left arm, Bob, Bob’s hat

• RelationshipsRelationships between objects between objects

– Represented as Represented as tuplestuples

Sibling (Alice, Bob), Sibling (Bob, Alice)Sibling (Alice, Bob), Sibling (Bob, Alice)

On head (Bob, hat)On head (Bob, hat)

Person (Bob), Person (Alice)Person (Bob), Person (Alice)

– Some relationships are Some relationships are functionsfunctions if a given object is related to exactly if a given object is related to exactly one object in a certain wayone object in a certain way

leftArm(Alice) leftArm(Alice) Alice’s left arm Alice’s left arm

Page 5: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Models of first-order logic

– Unlike in propositional logic, models in FOL are more than Unlike in propositional logic, models in FOL are more than just truth assignments to the objects… they are just truth assignments to the objects… they are relationships among the objectsrelationships among the objects

– Unlike in propositional logic, models in FOL are more than Unlike in propositional logic, models in FOL are more than just truth assignments to the objects… they are just truth assignments to the objects… they are relationships among the objectsrelationships among the objects

Page 6: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

First-order logic syntax

Constant SymbolsConstant Symbols

• A, B, Bob, Alice, HatA, B, Bob, Alice, Hat

Predicate SymbolsPredicate Symbols

• is, onHead, hasColor, personis, onHead, hasColor, person

Function SymbolsFunction Symbols

• Mother, leftLegMother, leftLeg

Each predicate and function symbol has an arityEach predicate and function symbol has an arity

• A constant the fixes the number of argumentsA constant the fixes the number of arguments

Constant SymbolsConstant Symbols

• A, B, Bob, Alice, HatA, B, Bob, Alice, Hat

Predicate SymbolsPredicate Symbols

• is, onHead, hasColor, personis, onHead, hasColor, person

Function SymbolsFunction Symbols

• Mother, leftLegMother, leftLeg

Each predicate and function symbol has an arityEach predicate and function symbol has an arity

• A constant the fixes the number of argumentsA constant the fixes the number of arguments

Page 7: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

First-order logic semantics

Semantics relates sentences to models in order to Semantics relates sentences to models in order to determine truthdetermine truth

• InterpretationInterpretation accomplishes semantics: accomplishes semantics:it maps symbols to modelsit maps symbols to models

– constant symbols constant symbols objects objects

– predicate symbols predicate symbols relations relations

– function symbols function symbols functions functions

Semantics relates sentences to models in order to Semantics relates sentences to models in order to determine truthdetermine truth

• InterpretationInterpretation accomplishes semantics: accomplishes semantics:it maps symbols to modelsit maps symbols to models

– constant symbols constant symbols objects objects

– predicate symbols predicate symbols relations relations

– function symbols function symbols functions functions

Page 8: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Syntax and semantics

Names of things are abitraryNames of things are abitrary

• Knowledge base adds meaningKnowledge base adds meaning

Number of possible domain elements (objects) is Number of possible domain elements (objects) is unbounded… integers for exampleunbounded… integers for example

• Number of Number of modelsmodels is unbounded and many is unbounded and many interpretationsinterpretations for for each modeleach model

– Checking entailment by enumeration is usually impossibleChecking entailment by enumeration is usually impossible

Names of things are abitraryNames of things are abitrary

• Knowledge base adds meaningKnowledge base adds meaning

Number of possible domain elements (objects) is Number of possible domain elements (objects) is unbounded… integers for exampleunbounded… integers for example

• Number of Number of modelsmodels is unbounded and many is unbounded and many interpretationsinterpretations for for each modeleach model

– Checking entailment by enumeration is usually impossibleChecking entailment by enumeration is usually impossible

Page 9: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Term

A logical expression that refers to an objectA logical expression that refers to an object• ConstantsConstants

– We could assign names to all objects, like providing a We could assign names to all objects, like providing a name for every shoe in your closetname for every shoe in your closet

• Function symbolsFunction symbols

– Replaces the need to name all the shoesReplaces the need to name all the shoes

– OnLeftFoot(John))OnLeftFoot(John))

Refers to a shoe, some shoeRefers to a shoe, some shoe

A logical expression that refers to an objectA logical expression that refers to an object• ConstantsConstants

– We could assign names to all objects, like providing a We could assign names to all objects, like providing a name for every shoe in your closetname for every shoe in your closet

• Function symbolsFunction symbols

– Replaces the need to name all the shoesReplaces the need to name all the shoes

– OnLeftFoot(John))OnLeftFoot(John))

Refers to a shoe, some shoeRefers to a shoe, some shoe

Page 10: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Atomic Sentences

Formed by a Formed by a predicatepredicate symbolsymbol followed by parenthesized followed by parenthesized list of list of termsterms

• Sibling (Alice, Bob)Sibling (Alice, Bob)

• Married (Father(Alice), Mother(Bob))Married (Father(Alice), Mother(Bob))

An atomic sentence is true in a given model, under a An atomic sentence is true in a given model, under a given interpretation, if the relation referred to by the given interpretation, if the relation referred to by the predicate symbol holds among the objects referred to by predicate symbol holds among the objects referred to by the argumentsthe arguments

Formed by a Formed by a predicatepredicate symbolsymbol followed by parenthesized followed by parenthesized list of list of termsterms

• Sibling (Alice, Bob)Sibling (Alice, Bob)

• Married (Father(Alice), Mother(Bob))Married (Father(Alice), Mother(Bob))

An atomic sentence is true in a given model, under a An atomic sentence is true in a given model, under a given interpretation, if the relation referred to by the given interpretation, if the relation referred to by the predicate symbol holds among the objects referred to by predicate symbol holds among the objects referred to by the argumentsthe arguments

Page 11: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Complex sentences

We can use logical connectivesWe can use logical connectives

• ~Sibling(LeftLeg(Alice), Bob)~Sibling(LeftLeg(Alice), Bob)

• Sibling(Alice, Bob) ^ Sibling (Bob, Alice)Sibling(Alice, Bob) ^ Sibling (Bob, Alice)

We can use logical connectivesWe can use logical connectives

• ~Sibling(LeftLeg(Alice), Bob)~Sibling(LeftLeg(Alice), Bob)

• Sibling(Alice, Bob) ^ Sibling (Bob, Alice)Sibling(Alice, Bob) ^ Sibling (Bob, Alice)

Page 12: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Quantifiers

A way to express properties of entire collections A way to express properties of entire collections of objectsof objects

• Universal quantificationUniversal quantification (forall, ) (forall, )

– The power of first-order logicThe power of first-order logic

– ForallForallxx King(x) => Person(x) King(x) => Person(x)

– xx is a variable is a variable

A way to express properties of entire collections A way to express properties of entire collections of objectsof objects

• Universal quantificationUniversal quantification (forall, ) (forall, )

– The power of first-order logicThe power of first-order logic

– ForallForallxx King(x) => Person(x) King(x) => Person(x)

– xx is a variable is a variable

)()(: xPersonxKingx

Page 13: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Universal Quantification

Forall x, PForall x, P

• P is true for every object xP is true for every object x

• Forall x, King(x) => Person(x)Forall x, King(x) => Person(x)

• x = x =

– Richard the LionheartRichard the Lionheart

– King JohnKing John

– Richard’s left legRichard’s left leg

– John’s left legJohn’s left leg

– The crownThe crown

Forall x, PForall x, P

• P is true for every object xP is true for every object x

• Forall x, King(x) => Person(x)Forall x, King(x) => Person(x)

• x = x =

– Richard the LionheartRichard the Lionheart

– King JohnKing John

– Richard’s left legRichard’s left leg

– John’s left legJohn’s left leg

– The crownThe crown

Page 14: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Universal Quantification

Note that all of these are trueNote that all of these are true• Implication is true even if the premise is falseImplication is true even if the premise is false

• is the right connective to use for is the right connective to use for

By asserting a universally quantified sentence, By asserting a universally quantified sentence, you assert a whole list of individual implicationsyou assert a whole list of individual implications

Note that all of these are trueNote that all of these are true• Implication is true even if the premise is falseImplication is true even if the premise is false

• is the right connective to use for is the right connective to use for

By asserting a universally quantified sentence, By asserting a universally quantified sentence, you assert a whole list of individual implicationsyou assert a whole list of individual implications

Page 15: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

There exists,There exists,• There exists an x such that Crown(x) ^ OnHead(x, John)There exists an x such that Crown(x) ^ OnHead(x, John)

• It is true for It is true for at leastat least one object one object

• ^ is the right connective for ^ is the right connective for

There exists,There exists,• There exists an x such that Crown(x) ^ OnHead(x, John)There exists an x such that Crown(x) ^ OnHead(x, John)

• It is true for It is true for at leastat least one object one object

• ^ is the right connective for ^ is the right connective for

Existential Quantification

Page 16: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Nested Quantifiers

Building more complex sentencesBuilding more complex sentences

– Everybody loves somebodyEverybody loves somebody

– There is someone who is loved by everyoneThere is someone who is loved by everyone

Use unique variable names and parentheses when Use unique variable names and parentheses when appropriateappropriate

Building more complex sentencesBuilding more complex sentences

– Everybody loves somebodyEverybody loves somebody

– There is someone who is loved by everyoneThere is someone who is loved by everyone

Use unique variable names and parentheses when Use unique variable names and parentheses when appropriateappropriate

Page 17: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Combining

• Everyone dislikes parsnips ==Everyone dislikes parsnips ==there does not exist someone who likes parsnipsthere does not exist someone who likes parsnips

• Everyone likes ice cream ==Everyone likes ice cream ==there is no one who does not like ice creamthere is no one who does not like ice cream

• Everyone dislikes parsnips ==Everyone dislikes parsnips ==there does not exist someone who likes parsnipsthere does not exist someone who likes parsnips

• Everyone likes ice cream ==Everyone likes ice cream ==there is no one who does not like ice creamthere is no one who does not like ice cream

Page 18: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Combining

De Morgan’s rules applyDe Morgan’s rules applyDe Morgan’s rules applyDe Morgan’s rules apply

Page 19: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Equality

Two terms that refer to the same objectTwo terms that refer to the same object

• Father (John) = HenryFather (John) = Henry

• Richard has at least two brothersRichard has at least two brothers

• Notice this sentence is not the sameNotice this sentence is not the same

Two terms that refer to the same objectTwo terms that refer to the same object

• Father (John) = HenryFather (John) = Henry

• Richard has at least two brothersRichard has at least two brothers

• Notice this sentence is not the sameNotice this sentence is not the same

Page 20: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

An Example

A Tell/Ask interface for a first-order knowledge baseA Tell/Ask interface for a first-order knowledge base

• Sentences are added with “Tell”Sentences are added with “Tell”

– These are called assertionsThese are called assertions

– Tell (KB, King(John))Tell (KB, King(John))

– Tell (KB, Forall x: King(x) => Person(x))Tell (KB, Forall x: King(x) => Person(x))

• Queries are made with “Ask”Queries are made with “Ask”

– Ask (KB, King(John))Ask (KB, King(John))

– Ask (KB, Person(John))Ask (KB, Person(John))

A Tell/Ask interface for a first-order knowledge baseA Tell/Ask interface for a first-order knowledge base

• Sentences are added with “Tell”Sentences are added with “Tell”

– These are called assertionsThese are called assertions

– Tell (KB, King(John))Tell (KB, King(John))

– Tell (KB, Forall x: King(x) => Person(x))Tell (KB, Forall x: King(x) => Person(x))

• Queries are made with “Ask”Queries are made with “Ask”

– Ask (KB, King(John))Ask (KB, King(John))

– Ask (KB, Person(John))Ask (KB, Person(John))

Page 21: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

An Example

• Quantified queriesQuantified queries

– Ask (KB, exist x: Person(x))Ask (KB, exist x: Person(x))

• KB should return a list of variable/term pairs that satisfy the KB should return a list of variable/term pairs that satisfy the queryquery

• Quantified queriesQuantified queries

– Ask (KB, exist x: Person(x))Ask (KB, exist x: Person(x))

• KB should return a list of variable/term pairs that satisfy the KB should return a list of variable/term pairs that satisfy the queryquery

Page 22: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Axioms

The basic facts from which conclusions can be The basic facts from which conclusions can be derivedderived

• Male (Jim) Spouse (Jim, Laura)Male (Jim) Spouse (Jim, Laura)

The basic facts from which conclusions can be The basic facts from which conclusions can be derivedderived

• Male (Jim) Spouse (Jim, Laura)Male (Jim) Spouse (Jim, Laura)

A theorem derived from axioms

Page 23: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

The Wumpus World

More precise axioms than with propositional logicMore precise axioms than with propositional logic

• Percept has five valuesPercept has five values

• Time is importantTime is important

• A typical sentenceA typical sentence

– Percept ([Stench, Breeze, Glitter, None, None], 5)Percept ([Stench, Breeze, Glitter, None, None], 5)

• The actions are termsThe actions are terms

– Turn(right), Turn(left), Forward, Shoot, Grab, ReleaseTurn(right), Turn(left), Forward, Shoot, Grab, Release

• Computing best action with a queryComputing best action with a query

– Exist a: BestAction(a, 5)Exist a: BestAction(a, 5)

More precise axioms than with propositional logicMore precise axioms than with propositional logic

• Percept has five valuesPercept has five values

• Time is importantTime is important

• A typical sentenceA typical sentence

– Percept ([Stench, Breeze, Glitter, None, None], 5)Percept ([Stench, Breeze, Glitter, None, None], 5)

• The actions are termsThe actions are terms

– Turn(right), Turn(left), Forward, Shoot, Grab, ReleaseTurn(right), Turn(left), Forward, Shoot, Grab, Release

• Computing best action with a queryComputing best action with a query

– Exist a: BestAction(a, 5)Exist a: BestAction(a, 5)

Page 24: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

The Wumpus World

• After executing query, KB responds with variable/term list: After executing query, KB responds with variable/term list: {a/Grab}{a/Grab}

• Then tell the KB the action takenThen tell the KB the action taken

• Raw percept data is easily encodedRaw percept data is easily encoded

• Reflexes are easily encodedReflexes are easily encoded

• After executing query, KB responds with variable/term list: After executing query, KB responds with variable/term list: {a/Grab}{a/Grab}

• Then tell the KB the action takenThen tell the KB the action taken

• Raw percept data is easily encodedRaw percept data is easily encoded

• Reflexes are easily encodedReflexes are easily encoded

Page 25: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Wumpus World

• Defining the environment with[x,y] reference instead of Defining the environment with[x,y] reference instead of alternative atomic namealternative atomic name

• Adjacency between two squaresAdjacency between two squares

• Location of Wumpus is constant: Home (Wumpus)Location of Wumpus is constant: Home (Wumpus)

• Location of agent changes: At (Agent, [ ], t)Location of agent changes: At (Agent, [ ], t)

• Defining the environment with[x,y] reference instead of Defining the environment with[x,y] reference instead of alternative atomic namealternative atomic name

• Adjacency between two squaresAdjacency between two squares

• Location of Wumpus is constant: Home (Wumpus)Location of Wumpus is constant: Home (Wumpus)

• Location of agent changes: At (Agent, [ ], t)Location of agent changes: At (Agent, [ ], t)

Page 26: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Diagnostic Rules

Rules leading from observed effects to hidden Rules leading from observed effects to hidden causescauses

• Breezy implies pitsBreezy implies pits

• Not breezy implies no pitsNot breezy implies no pits

• CombiningCombining

Rules leading from observed effects to hidden Rules leading from observed effects to hidden causescauses

• Breezy implies pitsBreezy implies pits

• Not breezy implies no pitsNot breezy implies no pits

• CombiningCombining

Page 27: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Causal Rules

Some hidden property causes percepts to be Some hidden property causes percepts to be generatedgenerated

• A pit causes adjacent squares to be breezyA pit causes adjacent squares to be breezy

• If all squares adjacent to a square a pitless, it will not be If all squares adjacent to a square a pitless, it will not be breezybreezy

Some hidden property causes percepts to be Some hidden property causes percepts to be generatedgenerated

• A pit causes adjacent squares to be breezyA pit causes adjacent squares to be breezy

• If all squares adjacent to a square a pitless, it will not be If all squares adjacent to a square a pitless, it will not be breezybreezy

Page 28: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Causal Rules

The causal rules formulate a The causal rules formulate a model of the worldmodel of the world

• Knowledge of how the environment operatesKnowledge of how the environment operates

• Model can be very useful and important and replace Model can be very useful and important and replace straightforward diagnostic approachesstraightforward diagnostic approaches

– Note how much the term model is overloadedNote how much the term model is overloaded

The causal rules formulate a The causal rules formulate a model of the worldmodel of the world

• Knowledge of how the environment operatesKnowledge of how the environment operates

• Model can be very useful and important and replace Model can be very useful and important and replace straightforward diagnostic approachesstraightforward diagnostic approaches

– Note how much the term model is overloadedNote how much the term model is overloaded

Page 29: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Conclusion

IfIf the axioms correctly and completely describe the way the axioms correctly and completely describe the way the world works and the way percepts are produced,the world works and the way percepts are produced,

then any complete logical inference procedure will infer then any complete logical inference procedure will infer the strongest possible description of the world state the strongest possible description of the world state given the available perceptsgiven the available percepts

The agent designer can focus on getting the knowledge The agent designer can focus on getting the knowledge right without worrying about the processes of deductionright without worrying about the processes of deduction

IfIf the axioms correctly and completely describe the way the axioms correctly and completely describe the way the world works and the way percepts are produced,the world works and the way percepts are produced,

then any complete logical inference procedure will infer then any complete logical inference procedure will infer the strongest possible description of the world state the strongest possible description of the world state given the available perceptsgiven the available percepts

The agent designer can focus on getting the knowledge The agent designer can focus on getting the knowledge right without worrying about the processes of deductionright without worrying about the processes of deduction

Page 30: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Discussion of models

Let’s think about how we use models every dayLet’s think about how we use models every day

• Daily stock pricesDaily stock prices

• Seasonal stock pricesSeasonal stock prices

• Seasonal temperaturesSeasonal temperatures

• Annual temperaturesAnnual temperatures

Let’s think about how we use models every dayLet’s think about how we use models every day

• Daily stock pricesDaily stock prices

• Seasonal stock pricesSeasonal stock prices

• Seasonal temperaturesSeasonal temperatures

• Annual temperaturesAnnual temperatures

Page 31: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Knowledge Engineering

• Understand a particular domainUnderstand a particular domain

– How does stock trading workHow does stock trading work

• Learn what concepts are important in the domain (Learn what concepts are important in the domain (featuresfeatures))

– Buyer confidence, strength of the dollar, company Buyer confidence, strength of the dollar, company earnings, interest rateearnings, interest rate

• Create a formal representation of the objects and relations in Create a formal representation of the objects and relations in the domainthe domain

– Forall stocks (price = low ^ confidence = high) => Forall stocks (price = low ^ confidence = high) => profitability = highprofitability = high

• Understand a particular domainUnderstand a particular domain

– How does stock trading workHow does stock trading work

• Learn what concepts are important in the domain (Learn what concepts are important in the domain (featuresfeatures))

– Buyer confidence, strength of the dollar, company Buyer confidence, strength of the dollar, company earnings, interest rateearnings, interest rate

• Create a formal representation of the objects and relations in Create a formal representation of the objects and relations in the domainthe domain

– Forall stocks (price = low ^ confidence = high) => Forall stocks (price = low ^ confidence = high) => profitability = highprofitability = high

Page 32: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Identify the task

What is the range of inputs and outputsWhat is the range of inputs and outputs

• Will the stock trading system have to answer questions about Will the stock trading system have to answer questions about the weather?the weather?

– Perhaps if you’re buying wheat futuresPerhaps if you’re buying wheat futures

– Must the system store daily temperatures or can it use Must the system store daily temperatures or can it use another agent?another agent?

What is the range of inputs and outputsWhat is the range of inputs and outputs

• Will the stock trading system have to answer questions about Will the stock trading system have to answer questions about the weather?the weather?

– Perhaps if you’re buying wheat futuresPerhaps if you’re buying wheat futures

– Must the system store daily temperatures or can it use Must the system store daily temperatures or can it use another agent?another agent?

Page 33: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Assemble the relevant knowledge

• You know what information is relevantYou know what information is relevant

• How can you accumulate the information?How can you accumulate the information?

– Not formal description of knowledge at this pointNot formal description of knowledge at this point

– Just principled understanding of where information residesJust principled understanding of where information resides

• You know what information is relevantYou know what information is relevant

• How can you accumulate the information?How can you accumulate the information?

– Not formal description of knowledge at this pointNot formal description of knowledge at this point

– Just principled understanding of where information residesJust principled understanding of where information resides

Page 34: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Formalize the knowledge

Decide on vocabulary of predicates, functions, Decide on vocabulary of predicates, functions, and constantsand constants• Beginning to map domain into a programmatic structureBeginning to map domain into a programmatic structure

• You’re selecting an ontologyYou’re selecting an ontology

– A particular theory of how the domain can be simplified A particular theory of how the domain can be simplified and represented at its basic elementsand represented at its basic elements

– Mistakes here cause big problemsMistakes here cause big problems

Decide on vocabulary of predicates, functions, Decide on vocabulary of predicates, functions, and constantsand constants• Beginning to map domain into a programmatic structureBeginning to map domain into a programmatic structure

• You’re selecting an ontologyYou’re selecting an ontology

– A particular theory of how the domain can be simplified A particular theory of how the domain can be simplified and represented at its basic elementsand represented at its basic elements

– Mistakes here cause big problemsMistakes here cause big problems

Page 35: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Encode general knowledge

• Write down axioms for all vocabulary termsWrite down axioms for all vocabulary terms

– Define the meaning of termsDefine the meaning of terms

• Errors will be discovered and knowledge assembly and Errors will be discovered and knowledge assembly and formalization steps repeatedformalization steps repeated

• Write down axioms for all vocabulary termsWrite down axioms for all vocabulary terms

– Define the meaning of termsDefine the meaning of terms

• Errors will be discovered and knowledge assembly and Errors will be discovered and knowledge assembly and formalization steps repeatedformalization steps repeated

Page 36: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Map to this particular instance

Encode a description of the specific problem Encode a description of the specific problem instanceinstance

• Should be an easy stepShould be an easy step

• Write simple atomic sentencesWrite simple atomic sentences

– Derived from sensors/perceptsDerived from sensors/percepts

– Derived from external dataDerived from external data

Encode a description of the specific problem Encode a description of the specific problem instanceinstance

• Should be an easy stepShould be an easy step

• Write simple atomic sentencesWrite simple atomic sentences

– Derived from sensors/perceptsDerived from sensors/percepts

– Derived from external dataDerived from external data

Page 37: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Use the knowledge base

Pose queries and get answersPose queries and get answers

• Use inference procedureUse inference procedure

• Derive new factsDerive new facts

Pose queries and get answersPose queries and get answers

• Use inference procedureUse inference procedure

• Derive new factsDerive new facts

Page 38: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Debug the knowledge base

There will most likely be bugsThere will most likely be bugs

• If inference engine works bugs will be in knowledge baseIf inference engine works bugs will be in knowledge base

– Missing axiomsMissing axioms

– Axioms that are too weakAxioms that are too weak

– Conflicting axiomsConflicting axioms

There will most likely be bugsThere will most likely be bugs

• If inference engine works bugs will be in knowledge baseIf inference engine works bugs will be in knowledge base

– Missing axiomsMissing axioms

– Axioms that are too weakAxioms that are too weak

– Conflicting axiomsConflicting axioms

Page 39: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Enough talk, let’s get to the meat

Chapter 9Chapter 9

Inference in First-Order LogicInference in First-Order Logic

• We want to use inference to answer any answerable We want to use inference to answer any answerable question stated in first-order logicquestion stated in first-order logic

Chapter 9Chapter 9

Inference in First-Order LogicInference in First-Order Logic

• We want to use inference to answer any answerable We want to use inference to answer any answerable question stated in first-order logicquestion stated in first-order logic

Page 40: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Propositional Inference

We already know how to perform inference in We already know how to perform inference in propositional logicpropositional logic• Transform first-order logic to propositional logicTransform first-order logic to propositional logic

• First-order logic makes powerful use of variablesFirst-order logic makes powerful use of variables

– Universal quantification (for all Universal quantification (for all xx))

– Existential quantification (there exists an Existential quantification (there exists an xx))

Transform quantifiers to logical connectivesTransform quantifiers to logical connectives

We already know how to perform inference in We already know how to perform inference in propositional logicpropositional logic• Transform first-order logic to propositional logicTransform first-order logic to propositional logic

• First-order logic makes powerful use of variablesFirst-order logic makes powerful use of variables

– Universal quantification (for all Universal quantification (for all xx))

– Existential quantification (there exists an Existential quantification (there exists an xx))

Transform quantifiers to logical connectivesTransform quantifiers to logical connectives

Page 41: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Converting universal quantifiers

Universal InstantiationUniversal Instantiation

Example:Example:

after substitution {x/John}, {x/Richard}, {x/Father(John)} after substitution {x/John}, {x/Richard}, {x/Father(John)} becomesbecomes

We’ve replaced the variable with all possible ground terms We’ve replaced the variable with all possible ground terms (terms without variables)(terms without variables)

Universal InstantiationUniversal Instantiation

Example:Example:

after substitution {x/John}, {x/Richard}, {x/Father(John)} after substitution {x/John}, {x/Richard}, {x/Father(John)} becomesbecomes

We’ve replaced the variable with all possible ground terms We’ve replaced the variable with all possible ground terms (terms without variables)(terms without variables)

Page 42: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Converting existential quantifiers

Existential InstantiationExistential Instantiation

Example:Example:

• There is some thing that is a crown and is on John’s head…There is some thing that is a crown and is on John’s head…

• Let’s call it CLet’s call it C11

becomes: becomes:

You can replace the variable with a constant symbol that You can replace the variable with a constant symbol that does not appear elsewhere in the knowledge basedoes not appear elsewhere in the knowledge base

The constant symbol is a The constant symbol is a Skolem Skolem constantconstant

Existential InstantiationExistential Instantiation

Example:Example:

• There is some thing that is a crown and is on John’s head…There is some thing that is a crown and is on John’s head…

• Let’s call it CLet’s call it C11

becomes: becomes:

You can replace the variable with a constant symbol that You can replace the variable with a constant symbol that does not appear elsewhere in the knowledge basedoes not appear elsewhere in the knowledge base

The constant symbol is a The constant symbol is a Skolem Skolem constantconstant

Page 43: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Existential Instantiation

Only perform substitution onceOnly perform substitution once

• There exists an There exists an xx s.t. s.t. Punched (x, Victim)Punched (x, Victim)

– Someone punched the victimSomeone punched the victim

– Maybe more than one person punched the victimMaybe more than one person punched the victim

– Existential quantifier says Existential quantifier says at least at least one person punchedone person punched

• Replacement isReplacement is

– Punched (Criminal, Victim)Punched (Criminal, Victim)

Only perform substitution onceOnly perform substitution once

• There exists an There exists an xx s.t. s.t. Punched (x, Victim)Punched (x, Victim)

– Someone punched the victimSomeone punched the victim

– Maybe more than one person punched the victimMaybe more than one person punched the victim

– Existential quantifier says Existential quantifier says at least at least one person punchedone person punched

• Replacement isReplacement is

– Punched (Criminal, Victim)Punched (Criminal, Victim)

Page 44: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Complete reduction

• Convert existentially quantified sentencesConvert existentially quantified sentences

– Creates one instantiationCreates one instantiation

• Convert universally quantified sentencesConvert universally quantified sentences

– Creates all possible instantiationsCreates all possible instantiations

• Use propositional logic to resolveUse propositional logic to resolve

Every first-order knowledge base and query can Every first-order knowledge base and query can be propositionalized in such a way that entailment be propositionalized in such a way that entailment is preservedis preserved

• Convert existentially quantified sentencesConvert existentially quantified sentences

– Creates one instantiationCreates one instantiation

• Convert universally quantified sentencesConvert universally quantified sentences

– Creates all possible instantiationsCreates all possible instantiations

• Use propositional logic to resolveUse propositional logic to resolve

Every first-order knowledge base and query can Every first-order knowledge base and query can be propositionalized in such a way that entailment be propositionalized in such a way that entailment is preservedis preserved

Page 45: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Trouble ahead!

Universal quantification with functions:Universal quantification with functions:

What about (Father(Father(Father(John))))?What about (Father(Father(Father(John))))?

• Isn’t it possible to have infinite number of substitutions?Isn’t it possible to have infinite number of substitutions?

• How well will the propositional algorithms work with infinite number of How well will the propositional algorithms work with infinite number of sentences?sentences?

Universal quantification with functions:Universal quantification with functions:

What about (Father(Father(Father(John))))?What about (Father(Father(Father(John))))?

• Isn’t it possible to have infinite number of substitutions?Isn’t it possible to have infinite number of substitutions?

• How well will the propositional algorithms work with infinite number of How well will the propositional algorithms work with infinite number of sentences?sentences?

Page 46: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

A theorem of completeness

if if

• a sentence is entailed by the original, first-order knowledge basea sentence is entailed by the original, first-order knowledge base

then then

• there is a proof involving just a finite subset of the propositional knowledge there is a proof involving just a finite subset of the propositional knowledge basebase

We want to find that finite subsetWe want to find that finite subset

• First try proving the sentence with constant symbolsFirst try proving the sentence with constant symbols

• Then add all terms of depth 1: Father (Richard)Then add all terms of depth 1: Father (Richard)

• Then add all terms of depth 2: Father (Father (Richard))Then add all terms of depth 2: Father (Father (Richard))

• ……

if if

• a sentence is entailed by the original, first-order knowledge basea sentence is entailed by the original, first-order knowledge base

then then

• there is a proof involving just a finite subset of the propositional knowledge there is a proof involving just a finite subset of the propositional knowledge basebase

We want to find that finite subsetWe want to find that finite subset

• First try proving the sentence with constant symbolsFirst try proving the sentence with constant symbols

• Then add all terms of depth 1: Father (Richard)Then add all terms of depth 1: Father (Richard)

• Then add all terms of depth 2: Father (Father (Richard))Then add all terms of depth 2: Father (Father (Richard))

• ……

Page 47: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Still more trouble

Completeness says that if statement is true in Completeness says that if statement is true in first-order logic, it will also be true in propositionsfirst-order logic, it will also be true in propositions

• But what happens if you’ve been waiting for your proposition-But what happens if you’ve been waiting for your proposition-based algorithm to return an answer and it has been a while?based algorithm to return an answer and it has been a while?

– Is the statement not true?Is the statement not true?

– Is the statement just requiring lots of substitutions?Is the statement just requiring lots of substitutions?

You don’t know!You don’t know!

Completeness says that if statement is true in Completeness says that if statement is true in first-order logic, it will also be true in propositionsfirst-order logic, it will also be true in propositions

• But what happens if you’ve been waiting for your proposition-But what happens if you’ve been waiting for your proposition-based algorithm to return an answer and it has been a while?based algorithm to return an answer and it has been a while?

– Is the statement not true?Is the statement not true?

– Is the statement just requiring lots of substitutions?Is the statement just requiring lots of substitutions?

You don’t know!You don’t know!

Page 48: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

The Halting Problem

Alan Turing and Alonzo Church proved (1936)Alan Turing and Alonzo Church proved (1936)

• You can write an algorithm that returns You can write an algorithm that returns yesyes to every entailed sentence but to every entailed sentence but

• No algorithm exists that returns No algorithm exists that returns nono to every nonentailed sentence to every nonentailed sentence

So if your entailment-checking algorithm hasn’t returned So if your entailment-checking algorithm hasn’t returned “yes” yet, you cannot know if that’s because the “yes” yet, you cannot know if that’s because the sentence is not entailed…. Halting Problemsentence is not entailed…. Halting Problem

Entailment for first-order logic is Entailment for first-order logic is semi-decidablesemi-decidable

Alan Turing and Alonzo Church proved (1936)Alan Turing and Alonzo Church proved (1936)

• You can write an algorithm that returns You can write an algorithm that returns yesyes to every entailed sentence but to every entailed sentence but

• No algorithm exists that returns No algorithm exists that returns nono to every nonentailed sentence to every nonentailed sentence

So if your entailment-checking algorithm hasn’t returned So if your entailment-checking algorithm hasn’t returned “yes” yet, you cannot know if that’s because the “yes” yet, you cannot know if that’s because the sentence is not entailed…. Halting Problemsentence is not entailed…. Halting Problem

Entailment for first-order logic is Entailment for first-order logic is semi-decidablesemi-decidable

Page 49: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Adapting Modus Ponens

Did you notice inefficiency of propositionalization?Did you notice inefficiency of propositionalization?• Instantiate universal quantifiers by performing lots of Instantiate universal quantifiers by performing lots of

substitutions until (hopefully quickly) a proof was foundsubstitutions until (hopefully quickly) a proof was found

• Why bother substitutingWhy bother substitutingRichard for x when you andRichard for x when you andI know it won’t lead to aI know it won’t lead to aproof?proof?

• Clearly, a human sees John is the right substitution for x.Clearly, a human sees John is the right substitution for x.

Did you notice inefficiency of propositionalization?Did you notice inefficiency of propositionalization?• Instantiate universal quantifiers by performing lots of Instantiate universal quantifiers by performing lots of

substitutions until (hopefully quickly) a proof was foundsubstitutions until (hopefully quickly) a proof was found

• Why bother substitutingWhy bother substitutingRichard for x when you andRichard for x when you andI know it won’t lead to aI know it won’t lead to aproof?proof?

• Clearly, a human sees John is the right substitution for x.Clearly, a human sees John is the right substitution for x.

Page 50: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Modus Ponens for propositional logic

Page 51: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

How would we use modus ponens?

• Want to avoid creating Want to avoid creating all instances ofall instances of

• If there were a substitution we could perform on the premise If there were a substitution we could perform on the premise of such that the premise of such that the premise became identical to sentences already in the knowledge became identical to sentences already in the knowledge base, then we could assert the implication after performing base, then we could assert the implication after performing the subtitution the subtitution

• Replace x with JohnReplace x with John

– Assert Evil (John)Assert Evil (John)

• Want to avoid creating Want to avoid creating all instances ofall instances of

• If there were a substitution we could perform on the premise If there were a substitution we could perform on the premise of such that the premise of such that the premise became identical to sentences already in the knowledge became identical to sentences already in the knowledge base, then we could assert the implication after performing base, then we could assert the implication after performing the subtitution the subtitution

• Replace x with JohnReplace x with John

– Assert Evil (John)Assert Evil (John)

Page 52: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

How would we use modus ponens?

• Change example slightlyChange example slightly

• Now we want to performNow we want to performtwo substitutionstwo substitutions

• {x / John} {y / John}{x / John} {y / John}

• Change example slightlyChange example slightly

• Now we want to performNow we want to performtwo substitutionstwo substitutions

• {x / John} {y / John}{x / John} {y / John}

Page 53: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Generalized Modus Ponens

• For atomic sentences pFor atomic sentences p ii, p, pii’, ’, where there is a substitution where there is a substitution

such that Subst{q, psuch that Subst{q, p ii’} = Subst{q, p’} = Subst{q, pii}: }:

• For atomic sentences pFor atomic sentences p ii, p, pii’, ’, where there is a substitution where there is a substitution

such that Subst{q, psuch that Subst{q, p ii’} = Subst{q, p’} = Subst{q, pii}: }:

Page 54: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Generalized Modus Ponens

This is a This is a liftedlifted versionversion

• It raises Modus Ponens to first-order logicIt raises Modus Ponens to first-order logic

• We want to find lifted versions of forward chaining, backward We want to find lifted versions of forward chaining, backward chaining, and resolution algorithmschaining, and resolution algorithms

– Lifted versions make only those substitutions that are Lifted versions make only those substitutions that are required to allow particular inferences to proceedrequired to allow particular inferences to proceed

This is a This is a liftedlifted versionversion

• It raises Modus Ponens to first-order logicIt raises Modus Ponens to first-order logic

• We want to find lifted versions of forward chaining, backward We want to find lifted versions of forward chaining, backward chaining, and resolution algorithmschaining, and resolution algorithms

– Lifted versions make only those substitutions that are Lifted versions make only those substitutions that are required to allow particular inferences to proceedrequired to allow particular inferences to proceed

Page 55: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Unification

Generalized Modus Ponens requires finding good Generalized Modus Ponens requires finding good substitutionssubstitutions

• Logical expressions must look identicalLogical expressions must look identical

• Other lifted inference rules require this as wellOther lifted inference rules require this as well

Unification is the process of finding substitutionsUnification is the process of finding substitutions

Generalized Modus Ponens requires finding good Generalized Modus Ponens requires finding good substitutionssubstitutions

• Logical expressions must look identicalLogical expressions must look identical

• Other lifted inference rules require this as wellOther lifted inference rules require this as well

Unification is the process of finding substitutionsUnification is the process of finding substitutions

Page 56: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Unification

Unify takes two sentences and returns a unifier if Unify takes two sentences and returns a unifier if one existsone exists

Examples to answer the query, Knows (John, x):Examples to answer the query, Knows (John, x):

• Whom does John know?Whom does John know?

Unify takes two sentences and returns a unifier if Unify takes two sentences and returns a unifier if one existsone exists

Examples to answer the query, Knows (John, x):Examples to answer the query, Knows (John, x):

• Whom does John know?Whom does John know?

Page 57: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Unification

Consider the last sentence:Consider the last sentence:

• This fails because This fails because xx cannot take on two values cannot take on two values

• But “Everyone knows Elizabeth” and it should not failBut “Everyone knows Elizabeth” and it should not fail

• Must Must standardize apart standardize apart one of the two sentences to eliminate one of the two sentences to eliminate reuse of variablereuse of variable

Consider the last sentence:Consider the last sentence:

• This fails because This fails because xx cannot take on two values cannot take on two values

• But “Everyone knows Elizabeth” and it should not failBut “Everyone knows Elizabeth” and it should not fail

• Must Must standardize apart standardize apart one of the two sentences to eliminate one of the two sentences to eliminate reuse of variablereuse of variable

Page 58: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Unification

Multiple unifiers are possible:Multiple unifiers are possible:

or or Which is better, Knows (John, z) or Knows (John, John)?Which is better, Knows (John, z) or Knows (John, John)?

• Second could be obtained from first with extra subsSecond could be obtained from first with extra subs

• First unifier is more general than second because it places fewer First unifier is more general than second because it places fewer restrictions on the values of the variablesrestrictions on the values of the variables

There is a single There is a single most general unifiermost general unifier for every unifiable for every unifiable pair of expressionspair of expressions

Multiple unifiers are possible:Multiple unifiers are possible:

or or Which is better, Knows (John, z) or Knows (John, John)?Which is better, Knows (John, z) or Knows (John, John)?

• Second could be obtained from first with extra subsSecond could be obtained from first with extra subs

• First unifier is more general than second because it places fewer First unifier is more general than second because it places fewer restrictions on the values of the variablesrestrictions on the values of the variables

There is a single There is a single most general unifiermost general unifier for every unifiable for every unifiable pair of expressionspair of expressions

Page 59: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Storage and Retrieval

Remember Ask() and Tell() from propositions?Remember Ask() and Tell() from propositions?

• Replace with Store(s) and Fetch(q)Replace with Store(s) and Fetch(q)

– Store puts a sentence, s, into the KBStore puts a sentence, s, into the KB

– Fetch returns all unifiers such that query q unifies with Fetch returns all unifiers such that query q unifies with some sentence in the KBsome sentence in the KB

– An example is when we ask Knows (John, x) and returnsAn example is when we ask Knows (John, x) and returns

Remember Ask() and Tell() from propositions?Remember Ask() and Tell() from propositions?

• Replace with Store(s) and Fetch(q)Replace with Store(s) and Fetch(q)

– Store puts a sentence, s, into the KBStore puts a sentence, s, into the KB

– Fetch returns all unifiers such that query q unifies with Fetch returns all unifiers such that query q unifies with some sentence in the KBsome sentence in the KB

– An example is when we ask Knows (John, x) and returnsAn example is when we ask Knows (John, x) and returns

Page 60: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Fetch()

SimpleSimple

• Store all facts in KB as one long listStore all facts in KB as one long list

• For each fetch(q), call Unify (q, s) for every sentence s in listFor each fetch(q), call Unify (q, s) for every sentence s in list

– Inefficient because we’re performing so many unifies…Inefficient because we’re performing so many unifies…

ComplexComplex

• Only attempt unfications that have some chance of Only attempt unfications that have some chance of succeedingsucceeding

SimpleSimple

• Store all facts in KB as one long listStore all facts in KB as one long list

• For each fetch(q), call Unify (q, s) for every sentence s in listFor each fetch(q), call Unify (q, s) for every sentence s in list

– Inefficient because we’re performing so many unifies…Inefficient because we’re performing so many unifies…

ComplexComplex

• Only attempt unfications that have some chance of Only attempt unfications that have some chance of succeedingsucceeding

Page 61: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Predicate Indexing

Index the facts in the KBIndex the facts in the KB

• Example: unify Knows (John, x) with Brother (Richard, John)Example: unify Knows (John, x) with Brother (Richard, John)

• Predicate indexing puts all the Predicate indexing puts all the KnowsKnows facts in one bucket and all the facts in one bucket and all the Brother Brother facts in anotherfacts in another

– Might not be a win if there are lots of clauses for a particular Might not be a win if there are lots of clauses for a particular predicate symbolpredicate symbol

Consider how many people Consider how many people Know Know one anotherone another

– Instead index by predicate and first argumentInstead index by predicate and first argument

Clauses may be stored in multiple bucketsClauses may be stored in multiple buckets

Index the facts in the KBIndex the facts in the KB

• Example: unify Knows (John, x) with Brother (Richard, John)Example: unify Knows (John, x) with Brother (Richard, John)

• Predicate indexing puts all the Predicate indexing puts all the KnowsKnows facts in one bucket and all the facts in one bucket and all the Brother Brother facts in anotherfacts in another

– Might not be a win if there are lots of clauses for a particular Might not be a win if there are lots of clauses for a particular predicate symbolpredicate symbol

Consider how many people Consider how many people Know Know one anotherone another

– Instead index by predicate and first argumentInstead index by predicate and first argument

Clauses may be stored in multiple bucketsClauses may be stored in multiple buckets

Page 62: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Subsumption lattice

How to construct indices for all possible queries How to construct indices for all possible queries that unify with itthat unify with it

• Example: Employs (AIMA.org, Richard)Example: Employs (AIMA.org, Richard)

How to construct indices for all possible queries How to construct indices for all possible queries that unify with itthat unify with it

• Example: Employs (AIMA.org, Richard)Example: Employs (AIMA.org, Richard)

Page 63: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Subsumption Lattice

Page 64: CS 416 Artificial Intelligence Lecture 11 First-Order Logic Chapters 8 and 9 Lecture 11 First-Order Logic Chapters 8 and 9.

Subsumption lattice

• Each node reflects making one substitutionEach node reflects making one substitution

• The “highest” common descendent of any two nodes is the The “highest” common descendent of any two nodes is the result of applying the most general unifierresult of applying the most general unifier

• Predicate with Predicate with n n arguments will create a lattice with O(2arguments will create a lattice with O(2nn) ) nodesnodes

• Benefits of indexing may be outweighed by cost of storing Benefits of indexing may be outweighed by cost of storing and maintaining indicesand maintaining indices

• Each node reflects making one substitutionEach node reflects making one substitution

• The “highest” common descendent of any two nodes is the The “highest” common descendent of any two nodes is the result of applying the most general unifierresult of applying the most general unifier

• Predicate with Predicate with n n arguments will create a lattice with O(2arguments will create a lattice with O(2nn) ) nodesnodes

• Benefits of indexing may be outweighed by cost of storing Benefits of indexing may be outweighed by cost of storing and maintaining indicesand maintaining indices