39
ITCS 3153 Artificial Intelligence Lecture 13 Lecture 13 First-Order Logic First-Order Logic Chapter 8 Chapter 8

ITCS 3153 Artificial Intelligence Lecture 13 First-Order Logic Chapter 8 Lecture 13 First-Order Logic Chapter 8

  • View
    220

  • Download
    1

Embed Size (px)

Citation preview

ITCS 3153Artificial Intelligence

Lecture 13Lecture 13

First-Order LogicFirst-Order Logic

Chapter 8Chapter 8

Lecture 13Lecture 13

First-Order LogicFirst-Order Logic

Chapter 8Chapter 8

First-order logic

We saw how propositional logic can create We saw how propositional logic can create intelligent behaviorintelligent behavior

But propositional logic is a poor representation But propositional logic is a poor representation for complex environmentsfor complex environments

First-order logicFirst-order logic is a more expressive and is a more expressive and powerful representationpowerful representation

We saw how propositional logic can create We saw how propositional logic can create intelligent behaviorintelligent behavior

But propositional logic is a poor representation But propositional logic is a poor representation for complex environmentsfor complex environments

First-order logicFirst-order logic is a more expressive and is a more expressive and powerful representationpowerful representation

Diagnostic Rules

Rules leading from observed effects to hidden causesRules leading from observed effects to hidden causes

• After you’ve observed something, this rule offers an explanationAfter you’ve observed something, this rule offers an explanation

• These rules explain what happened in the pastThese rules explain what happened in the past

– Breezy implies pitsBreezy implies pits

– Not breezy implies no pitsNot breezy implies no pits

– CombiningCombining

Rules leading from observed effects to hidden causesRules leading from observed effects to hidden causes

• After you’ve observed something, this rule offers an explanationAfter you’ve observed something, this rule offers an explanation

• These rules explain what happened in the pastThese rules explain what happened in the past

– Breezy implies pitsBreezy implies pits

– Not breezy implies no pitsNot breezy implies no pits

– CombiningCombining

Causal Rules

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

• These are predictions of perceptions you expect to have in These are predictions of perceptions you expect to have in the future given current conditionsthe future given current conditions

– 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

• These are predictions of perceptions you expect to have in These are predictions of perceptions you expect to have in the future given current conditionsthe future given current conditions

– 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

Causal Rules

The causal rules formulate a The causal rules formulate a modelmodel

• 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

The causal rules formulate a The causal rules formulate a modelmodel

• 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

Conclusion

If the axioms correctly and completely describe the way If 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

If the axioms correctly and completely describe the way If 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

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

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 (features)Learn what concepts are important in the domain (features)

– 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 (features)Learn what concepts are important in the domain (features)

– 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

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 agent store daily temperatures or can it use Must the agent 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 agent store daily temperatures or can it use Must the agent store daily temperatures or can it use another agent?another agent?

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

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

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

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

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

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

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

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

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

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)

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

Existential Instantiation

Only perform substitution onceOnly perform substitution once

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

– Someone killed the victimSomeone killed the victim

– Maybe more than once person killed the victimMaybe more than once person killed the victim

– Existential quantifier says at least one person was killerExistential quantifier says at least one person was killer

• Replacement isReplacement is

– Kill (Murderer, Victim)Kill (Murderer, Victim)

Only perform substitution onceOnly perform substitution once

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

– Someone killed the victimSomeone killed the victim

– Maybe more than once person killed the victimMaybe more than once person killed the victim

– Existential quantifier says at least one person was killerExistential quantifier says at least one person was killer

• Replacement isReplacement is

– Kill (Murderer, Victim)Kill (Murderer, Victim)

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

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?

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

• ……

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!

The Halting Problem

Alan Turing and Alonzo Church provedAlan Turing and Alonzo Church proved

• You can write an algorithm that says yes to every entailed sentence butYou can write an algorithm that says yes to every entailed sentence but

• You no algorithm exists that says no to every nonentailed sentenceYou no algorithm exists that says no 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.sentence is not entailed.

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

Alan Turing and Alonzo Church provedAlan Turing and Alonzo Church proved

• You can write an algorithm that says yes to every entailed sentence butYou can write an algorithm that says yes to every entailed sentence but

• You no algorithm exists that says no to every nonentailed sentenceYou no algorithm exists that says no 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.sentence is not entailed.

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

Adapting Modus Ponens

Did you notice how inefficient previous method Did you notice how inefficient previous method was?was?• 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, John is the right substitution for x.Clearly, John is the right substitution for x.

Did you notice how inefficient previous method Did you notice how inefficient previous method was?was?• 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, John is the right substitution for x.Clearly, John is the right substitution for x.

Modus Ponens for propositional logic

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}: }:

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

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

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?

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

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

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

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

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

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)

Subsumption Lattice

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