first-order logic.milos/courses/cs2710-fall...– an interpretation gives a semantic to primitives....

27
CS 2710 Foundations of AI CS 2710 Foundations of AI Lecture 11 Milos Hauskrecht [email protected] 5329 Sennott Square First-order logic. CS 2710 Foundations of AI Administration PS-4: Due on Thursday, October 7, 2004 Midterm: October 19, 2004 during the class Closed book Covers: Search and Knowledge Representation

Upload: others

Post on 06-Feb-2021

2 views

Category:

Documents


0 download

TRANSCRIPT

  • 1

    CS 2710 Foundations of AI

    CS 2710 Foundations of AILecture 11

    Milos [email protected] Sennott Square

    First-order logic.

    CS 2710 Foundations of AI

    Administration

    • PS-4:– Due on Thursday, October 7, 2004

    • Midterm: – October 19, 2004 during the class– Closed book– Covers:

    Search and Knowledge Representation

  • 2

    CS 2710 Foundations of AI

    LogicLogic is defined by:• A set of sentences

    – A sentence is constructed from a set of primitives according to syntax rules.

    • A set of interpretations– An interpretation gives a semantic to primitives. It associates

    primitives with objects, values in the real world.• The valuation (meaning) function V

    – Assigns a truth value to a given sentence under some interpretation

    interpretasentence: ×V },{tion FalseTrue→

    CS 2710 Foundations of AI

    First-order logic. Syntax.

    Term - syntactic entity for representing objects

    Terms in FOL:• Constant symbols: represent specific objects

    – E.g. John, France, car89• Variables: represent objects of a certain type (type = domain of

    discourse)– E.g. x,y,z

    • Functions applied to one or more terms– E.g. father-of (John)

    father-of(father-of(John))

  • 3

    CS 2710 Foundations of AI

    First order logic. Syntax.

    Sentences in FOL:• Atomic sentences:

    – A predicate symbol applied to 0 or more termsExamples:Red(car12), Sister(Amy, Jane);Manager(father-of(John));

    – t1 = t2 equivalence of termsExample:John = father-of(Peter)

    CS 2710 Foundations of AI

    First order logic. Syntax.

    Sentences in FOL:• Complex sentences:• Assume are sentences in FOL. Then:

    –and

    –are sentences

    Symbols- stand for the existential and the universal quantifier

    )( ψφ ∧ )( ψφ ∨ ψ¬)( ψφ ⇔)( ψφ ⇒ψφ ,

    φx∀ φy∃

    ∀∃,

  • 4

    CS 2710 Foundations of AI

    Semantics. Interpretation. An interpretation I is defined by a mapping of symbols to the

    domain of discourse D or relations on D• domain of discourse: a set of objects in the world we represent

    and refer to; An interpretation I maps:• Constant symbols to objects in D

    I(John) = • Predicate symbols to relations, properties on D

    • Function symbols to functional relations on D

    ; ; ….

    ; ; ….

    I(brother) =

    I(father-of) =

    CS 2710 Foundations of AI

    Semantics of sentences. Meaning (evaluation) function:

    A predicate predicate(term-1, term-2, term-3, term-n) is true for the interpretation I , iff the objects referred to by term-1, term-2, term-3, term-n are in the relation referred to by predicate

    interpretasentence: ×V },{tion FalseTrue→

    V(brother(John, Paul), I) = True

    ; ; ….I(brother) =

    I(John) = I(Paul) =

    brother(John, Paul) = in I(brother)

  • 5

    CS 2710 Foundations of AI

    Semantics of sentences.

    • Equality

    • Boolean expressions: standard

    • Quantifications

    V(term-1= term-2, I) = TrueIff I(term-1) =I(term-2)

    V(sentence-1 ∨ sentence-2, I) = TrueIff V(sentence-1,I)= True or V(sentence-2,I)= True

    E.g.

    V( , I) = TrueIff for all V( ,I[x/d])= Trueφx∀

    Dd ∈ φ

    V( , I) = TrueIff there is a , s.t. V( ,I[x/d])= Trueφx∃

    Dd ∈ φ

    substitution of x with d

    CS 2710 Foundations of AI

    Order of quantifiers

    • Order of quantifiers of the same type does not matter

    • Order of different quantifiers changes the meaning

    For all x and y, if x is a parent of y then y is a child of x)x,(),(, ychildyxparentyx ⇒∀)x,(),(, ychildyxparentxy ⇒∀

    ),( yxlovesyx∃∀

  • 6

    CS 2710 Foundations of AI

    Order of quantifiers

    • Order of quantifiers of the same type does not matter

    • Order of different quantifiers changes the meaning

    Everybody loves somebody

    For all x and y, if x is a parent of y then y is a child of x)x,(),(, ychildyxparentyx ⇒∀)x,(),(, ychildyxparentxy ⇒∀

    ),( yxlovesyx∃∀

    ),( yxlovesxy∀∃

    CS 2710 Foundations of AI

    Order of quantifiers

    • Order of quantifiers of the same type does not matter

    • Order of different quantifiers changes the meaning

    Everybody loves somebody

    There is someone who is loved by everyone

    For all x and y, if x is a parent of y then y is a child of x)x,(),(, ychildyxparentyx ⇒∀)x,(),(, ychildyxparentxy ⇒∀

    ),( yxlovesyx∃∀

    ),( yxlovesxy∀∃

  • 7

    CS 2710 Foundations of AI

    Connections between quantifiers

    Everyone likes ice cream

    Is it possible to convey the same meaning using an existential quantifier ?

    A universal quantifier in the sentence can be expressed using anexistential quantifier !!!

    ),( IceCreamxlikesx∀

    ),( IceCreamxlikesx ¬¬∃There is no one who does not like ice cream

    CS 2710 Foundations of AI

    Connections between quantifiers

    Is it possible to convey the same meaning using a universal quantifier ?

    An existential quantifier in the sentence can be expressed using a universal quantifier !!!

    Someone likes ice cream

    ),( IceCreamxlikesx∃

    Not everybody does not like ice cream

    ),( IceCreamxlikesx ¬¬∀

  • 8

    CS 2710 Foundations of AI

    Representing knowledge in FOLExample:

    Kinship domain

    • Objects: people

    • Properties: gender

    • Relations: parenthood, brotherhood, marriage

    • Functions: mother-of (one for each person x)

    )(),( xFemalexMale

    ),(),,(),,( yxSpouseyxBrotheryxParent

    )( xMotherOf

    K,,, JaneMaryJohn

    CS 2710 Foundations of AI

    Kinship domain in FOL

    Relations between predicates and functions: write down what we know about them; how relate to each other.

    • Male and female are disjoint categories

    • Parent and child relations are inverse

    • A grandparent is a parent of parent

    • A sibling is another child of one’s parents

    • And so on ….

    ),(),(),(, cpParentpgParentpcgtGrandparencg ∧∃⇔∀

    ),(),()(),(, ypParentxpParentpyxyxSiblingyx ∧∃∧≠⇔∀

    ),(),(, xyChildyxParentyx ⇔∀

    )()( xFemalexMalex ¬⇔∀

  • 9

    CS 2710 Foundations of AI

    Inference in First order logic

    CS 2710 Foundations of AI

    Logical inference in FOL

    Logical inference problem:• Given a knowledge base KB (a set of sentences) and a

    sentence , does the KB semantically entail ?

    In other words: In all interpretations in which sentences in the KB are true, is also true?

    Logical inference problem in the first-order logic is undecidable !!!. No procedure that can decide the entailment for all possible input sentences in a finite number of steps.

    α=|KB ?

    α

    αα

  • 10

    CS 2710 Foundations of AI

    Logical inference problem in the Propositional logic

    Computational procedures that answer:

    Three approaches:• Truth-table approach• Inference rules• Conversion to the inverse SAT problem

    – Resolution-refutation

    α=|KB ?

    CS 2710 Foundations of AI

    Inference in FOL: Truth table approach

    • Is the Truth-table approach a viable approach for the FOL?

    • NO! • Why? • It would require us to enumerate and list all possible

    interpretations I • I = (assignments of symbols to objects, predicates to

    relations and functions to relational mappings)• Simply there are too many interpretations

    ?

  • 11

    CS 2710 Foundations of AI

    Inference in FOL: Inference rules

    • Is the Inference rule approach a viable approach for the FOL?

    • Yes. • The inference rules represent sound inference patterns one

    can apply to sentences in the KB• What is derived follows from the KB• Caveat: we need to add rules for handling quantifiers

    ?

    CS 2710 Foundations of AI

    Inference rules

    • Inference rules from the propositional logic:– Modus ponens

    – Resolution

    – and others: And-introduction, And-elimination, Or-introduction, Negation elimination

    • Additional inference rules are needed for sentences with quantifiers and variables– Must involve variable substitutions

    BABA ,⇒

    CACBBA

    ∨∨¬∨ ,

  • 12

    CS 2710 Foundations of AI

    Sentences with variablesFirst-order logic sentences can include variables.• Variable is:

    – Bound – if it is in the scope of some quantifier

    – Free – if it is not bound.

    • Sentence (formula) is:– Closed – if it has no free variables

    – Open – if it is not closed– Ground – if it does not have any variables

    )(xPx∀

    ),( JaneJohnLikes

    )()( xQyPx ∧∃ y is free

    )()( xQyPxy ⇒∃∀

    CS 2710 Foundations of AI

    Variable substitutions

    • Variables in the sentences can be substituted with terms.(terms = constants, variables, functions)

    • Substitution:– Is represented by a mapping from variables to terms

    – Application of the substitution to sentences

    },/,/{ 2211 Ktxtx

    ),()),(},/,/({ PamSamLikesyxLikesPamySamxSUBST =

    ))(,()),()},(/,/({

    JohnfatherofzLikesyxLikesJohnfatherofyzxSUBST =

  • 13

    CS 2710 Foundations of AI

    Inference rules for quantifiers

    • Universal elimination

    – substitutes a variable with a constant symbol

    • Existential elimination.

    – Substitutes a variable with a constant symbol that does not appear elsewhere in the KB

    )()(

    axx

    φφ∃

    )()(

    axx

    φφ∀

    a - is a constant symbol

    ),( IceCreamxLikesx∀ ),( IceCreamBenLikes

    ),( VictimxKillx∃ ),( VictimMurdererKill

    CS 2710 Foundations of AI

    Inference rules for quantifiers

    • Universal instantiation (introduction)

    – Introduces a universal variable which does not affect or its assumptions

    • Existential instantiation (introduction)

    – Substitutes a ground term in the sentence with a variable and an existential statement

    )()(xx

    aφφ

    φφx∀

    x – is not free in φ

    a – is a ground term inx – is not free in

    φφ

    φ

    ),( IceCreamxLikesx∃),( IceCreamBenLikes

    ),( JaneAmySister ),( JaneAmySisterx∀

  • 14

    CS 2710 Foundations of AI

    Unification

    • Problem in inference: Universal elimination gives many opportunities for substituting variables with ground terms

    • Solution: Try substitutions that may help– Use substitutions of “similar” sentences in KB

    • Unification – takes two similar sentences and computes the substitution that makes them look the same, if it exists

    ),(), s.t. ),( qSUBSTpSUBST( σqpUNIFY σσ ==

    )()(

    axx

    φφ∀

    a - is a constant symbol

    CS 2710 Foundations of AI

    Unification. Examples.

    • Unification:

    • Examples:

    }/{)),(),,(( JanexJaneJohnKnowsxJohnKnowsUNIFY =

    }/,/{)),(),,(( JohnyAnnxAnnyKnowsxJohnKnowsUNIFY =

    failElizabethxKnowsxJohnKnowsUNIFY =)),(),,((

    }/),(/{ )))(,(),,((

    JohnyJohnMotherOfxyMotherOfyKnowsxJohnKnowsUNIFY

    =

    ),(), s.t. ),( qSUBSTpSUBST( σqpUNIFY σσ ==

  • 15

    CS 2710 Foundations of AI

    Generalized inference rules.

    • Use substitutions that let us make inferencesExample: Modus Ponens• If there exists a substitution such that

    • Substitution that satisfies the generalized inference rule can be build via unification process

    • Advantage of the generalized rules: they are focused– only substitutions that allow the inferences to proceed

    ),(',',', 2121

    BSUBSTAAABAAA nn

    σKK ⇒∧∧

    )',(),( ii ASUBSTASUBST σσ =

    σ

    for all i=1,2, n

    CS 2710 Foundations of AI

    Resolution inference rule• Recall: Resolution inference rule is sound and complete

    (refutation-complete) for the propositional logic and CNF

    • Generalized resolution rule is sound and refutation completefor the first-order logic and CNF w/o equalities (if unsatisfiablethe resolution will find the contradiction)

    CBCABA

    ∨∨¬∨ ,

    ),(,

    111111

    2121

    njjkii

    nk

    SUBST ψψψψφφφφσψψψφφφ

    KKKK

    KK

    +−+− ∨∨∨∨∨∨∨∨∨∨∨∨

    failUNIFY ji ≠¬= ),( ψφσ

    Example:)()(

    )()(),()(ySJohnP

    ySJohnQxQxP∨

    ∨¬∨

  • 16

    CS 2710 Foundations of AI

    Inference with resolution rule

    • Proof by refutation:– Prove that is unsatisfiable– resolution is refutation-complete

    • Main procedure (steps):1. Convert to CNF with ground terms and

    universal variables only2. Apply repeatedly the resolution rule while keeping track

    and consistency of substitutions3. Stop when empty set (contradiction) is derived or no more

    new resolvents (conclusions) follow

    α¬,KB

    α¬,KB

    CS 2710 Foundations of AI

    Conversion to CNF

    1. Eliminate implications, equivalences

    2. Move negations inside (DeMorgan’s Laws, double negation)

    3. Standardize variables (rename duplicate variables)

    )()( qpqp ∨¬→⇒

    qpqp ¬∨¬→∧¬ )(qpqp ¬∧¬→∨¬ )(

    pxpx ¬∃→¬∀pxpx ¬∀→¬∃

    pp →¬¬

    ))(())(())(())(( yQyxPxxQxxPx ∃∨∀→∃∨∀

  • 17

    CS 2710 Foundations of AI

    Conversion to CNF

    4. Move all quantifiers left (no invalid capture possible )

    5. Skolemization (removal of existential quantifiers through elimination)

    • If no universal quantifier occurs before the existential quantifier, replace the variable with a new constant symbol

    • If a universal quantifier precede the existential quantifier replace the variable with a function of the “universal” variable

    )()())(())(( yQxPyxyQyxPx ∨∃∀→∃∨∀

    ))(()()()( xFQxPxyQxPyx ∨∀→∨∃∀

    )()()()( BQAPyQAPy ∨→∨∃

    )( xF - a Skolem function

    CS 2710 Foundations of AI

    Conversion to CNF

    6. Drop universal quantifiers (all variables are universally quantified)

    7. Convert to CNF using the distributive laws

    The result is a CNF with variables, constants, functions

    )()()( rpqprqp ∨∧∨→∧∨

    ))(()())(()( xFQxPxFQxPx ∨→∨∀

  • 18

    CS 2710 Foundations of AI

    Resolution example

    )()( wQwP ∨¬ )()( ySyQ ∨¬ )()( zSzR ∨¬)()( xRxP ∨

    KB

    )(AS¬

    α¬, , , ,

    CS 2710 Foundations of AI

    Resolution example

    )()( wQwP ∨¬ )()( ySyQ ∨¬ )()( zSzR ∨¬)()( xRxP ∨

    KB

    )(AS¬

    α¬

    )()( wSwP ∨¬

    , , , ,

    }/{ wy

  • 19

    CS 2710 Foundations of AI

    Resolution example

    )()( wQwP ∨¬ )()( ySyQ ∨¬ )()( zSzR ∨¬)()( xRxP ∨

    KB

    )(AS¬

    α¬

    )()( wSwP ∨¬

    , , , ,

    }/{ wy

    )()( wRwS ∨

    }/{ wx

    CS 2710 Foundations of AI

    Resolution example

    )()( wQwP ∨¬ )()( ySyQ ∨¬ )()( zSzR ∨¬)()( xRxP ∨

    KB

    )(AS¬

    α¬

    )()( wSwP ∨¬

    , , , ,

    }/{ wy

    )()( wRwS ∨

    }/{ wx

    )(wS

    }/{ wz

  • 20

    CS 2710 Foundations of AI

    Resolution example

    )()( wQwP ∨¬ )()( ySyQ ∨¬ )()( zSzR ∨¬)()( xRxP ∨

    KB

    )(AS¬

    α¬

    )()( wSwP ∨¬

    , , , ,

    }/{ wy

    )()( wRwS ∨

    }/{ wx

    )(wS

    }/{ wz

    }/{ Aw

    Contradictionα=|KB

    CS 2710 Foundations of AI

    Dealing with equality

    • Resolution works for first-order logic without equalities• To incorporate equalities we need an additional inference rule• Demodulation rule

    • Example:

    • Paramodulation rule: more powerful• Resolution+paramodulation give a refutation-complete

    proof theory for FOL

    kii

    k

    tSUBSTtSUBSTSUBSTtt

    φφφφσσφφφ

    ∨∨∨∨=∨∨

    +− KK

    K

    11121

    2121

    )},,(/),(({,

    failtUNIFY i ≠= ),( 1φσ

    )()()),((

    aPxxfafP =

  • 21

    CS 2710 Foundations of AI

    Sentences in Horn normal form• Horn normal form (HNF) in the propositional logic

    – a special type of clause with at most one positive literal

    • A clause with one literal, e.g. A, is also called a fact• A clause representing an implication (with a conjunction of

    positive literals in antecedent and one positive literal in consequent), is also called a rule

    • Generalized Modus ponens:

    – is the complete inference rule for KBs in the Horn normal form. Not all KBs are convertible to HNF !!!

    )()( DCABA ∨¬∨¬∧¬∨

    ))(()( DCAAB ⇒∧∧⇒Typically written as:

    CS 2710 Foundations of AI

    Horn normal form in FOL

    First-order logic (FOL)– adds variables and quantifiers, works with terms

    Generalized modus ponens rule:

    Generalized modus ponens:• is complete for the KBs with sentences in Horn form;• Not all first-order logic sentences can be expressed in this

    form

    ),(,',',' 2121

    τστφφφφφφ

    SUBSTnn ⇒∧∧ KK

    ),()',( s.t.on substituti a ii SUBSTSUBSTi φσφσσ =∀=

  • 22

    CS 2710 Foundations of AI

    Forward and backward chaining

    Two inference procedures based on modus ponens for Horn KBs:• Forward chaining

    Idea: Whenever the premises of a rule are satisfied, infer the conclusion. Continue with rules that became satisfied.Typical usage: If we want to infer all sentences entailed by the existing KB.

    • Backward chaining (goal reduction)Idea: To prove the fact that appears in the conclusion of a rule prove the premises of the rule. Continue recursively.Typical usage: If we want to prove that the target (goal) sentence is entailed by the existing KB.

    Both procedures are complete for KBs in Horn form !!!

    α

    CS 2710 Foundations of AI

    Forward chaining example• Forward chaining

    Idea: Whenever the premises of a rule are satisfied, infer the conclusion. Continue with rules that became satisfied

    ),(),(),( zxFasterzyFasteryxFaster ⇒∧

    KB: R1:

    R2:

    R3:

    Assume the KB with the following rules:),()()( yxFasterySailboatxSteamboat ⇒∧

    ),()()( zyFasterzRowBoatySailboat ⇒∧

    )(TitanicSteamboat

    )(MistralSailboat

    )(PondArrowRowBoat

    Theorem: ),( PondArrowTitanicFaster

    F1:

    F2:

    F3:

    ?

  • 23

    CS 2710 Foundations of AI

    Forward chaining example

    )(TitanicSteamboat)(MistralSailboat

    KB: R1:R2:R3:

    F1:F2:F3: )(PondArrowRowBoat

    ),(),(),( zxFasterzyFasteryxFaster ⇒∧

    ),()()( yxFasterySailboatxSteamboat ⇒∧),()()( zyFasterzRowBoatySailboat ⇒∧

    ?

    CS 2710 Foundations of AI

    Forward chaining example

    )(TitanicSteamboat)(MistralSailboat

    KB: R1:R2:R3:

    F1:F2:

    ),( MistralTitanicFaster

    F3: )(PondArrowRowBoat

    F4:

    ),(),(),( zxFasterzyFasteryxFaster ⇒∧

    ),()()( yxFasterySailboatxSteamboat ⇒∧),()()( zyFasterzRowBoatySailboat ⇒∧

    Rule R1 is satisfied:

  • 24

    CS 2710 Foundations of AI

    Forward chaining example

    )(TitanicSteamboat)(MistralSailboat

    KB: R1:R2:R3:

    F1:F2:

    ),( MistralTitanicFaster

    F3: )(PondArrowRowBoat

    F4:

    ),(),(),( zxFasterzyFasteryxFaster ⇒∧

    ),()()( yxFasterySailboatxSteamboat ⇒∧),()()( zyFasterzRowBoatySailboat ⇒∧

    ),( PondArrowMistralFasterRule R2 is satisfied:F5:

    Rule R1 is satisfied:

    CS 2710 Foundations of AI

    Forward chaining example

    )(TitanicSteamboat)(MistralSailboat

    KB: R1:R2:R3:

    F1:F2:

    ),( MistralTitanicFaster

    F3: )(PondArrowRowBoat

    F4:

    ),(),(),( zxFasterzyFasteryxFaster ⇒∧

    ),()()( yxFasterySailboatxSteamboat ⇒∧),()()( zyFasterzRowBoatySailboat ⇒∧

    ),( PondArrowMistralFasterRule R2 is satisfied:F5:Rule R3 is satisfied:

    ),( PondArrowTitanicFasterF6:

    Rule R1 is satisfied:

  • 25

    CS 2710 Foundations of AI

    Backward chaining example

    • Backward chaining (goal reduction)Idea: To prove the fact that appears in the conclusion of a rule prove the antecedents (if part) of the rule & repeat recursively.

    ),()()( yxFasterySailboatxSteamboat ⇒∧

    ),()()( zyFasterzRowBoatySailboat ⇒∧

    ),(),(),( zxFasterzyFasteryxFaster ⇒∧

    )(TitanicSteamboat

    )(MistralSailboat

    )(PondArrowRowBoat

    KB:

    Theorem: ),( PondArrowTitanicFaster

    R1:

    R2:

    R3:

    F1:

    F2:

    F3:

    CS 2710 Foundations of AI

    Backward chaining example

    ),( PondArrowTitanicFaster

    )(TitanicSteamboat

    R1

    )(PondArrowSailboat

    ),()()( yxFasterySailboatxSteamboat ⇒∧

    ),( PondArrowTitanicFaster}/,/{ PondArrowyTitanicx

    )(TitanicSteamboat

    )(MistralSailboat

    )(PondArrowRowBoat

    F1:

    F2:

    F3:

  • 26

    CS 2710 Foundations of AI

    Backward chaining example

    )(TitanicSteamboatR1

    ),( PondArrowTitanicFaster

    R2)(TitanicSailboat

    )(PondArrowRowBoat)(PondArrowSailboat

    ),( PondArrowTitanicFaster}/,/{ PondArrowzTitanicy

    ),()()( zyFasterzRowBoatySailboat ⇒∧

    )(TitanicSteamboat

    )(MistralSailboat

    )(PondArrowRowBoat

    F1:

    F2:

    F3:

    CS 2710 Foundations of AI

    Backward chaining example

    ),( PondArrowyFaster)(TitanicSteamboat

    R1

    ),( PondArrowTitanicFaster

    R2

    )(PondArrowRowBoat),( yTitanicFaster

    R3

    )(TitanicSteamboatR1

    R2

    )(PondArrowRowBoat

    )(PondArrowSailboat

    )(MistralSailboat

    )(MistralSailboat

    )(TitanicSailboat

    )(TitanicSteamboat

    )(MistralSailboat

    )(PondArrowRowBoat

    F1:

    F2:

    F3:

  • 27

    CS 2710 Foundations of AI

    Backward chaining

    ),( PondArrowyFaster)(TitanicSteamboat

    R1

    ),( PondArrowTitanicFaster

    R2

    )(PondArrowRowBoat),( yTitanicFaster

    R3

    )(TitanicSteamboatR1

    )(MistralSailboat

    R2

    )(PondArrowRowBoat

    )(PondArrowSailboat

    )(MistralSailboat

    )(TitanicSailboat

    y must be bound tothe same term

    CS 2710 Foundations of AI

    Backward chaining• The search tree: AND/OR tree• Special search algorithms exits (including heuristics): AO, AO*

    ),( PondArrowyFaster)(TitanicSteamboat

    R1

    )(PondArrowSailboat

    ),( PondArrowTitanicFaster

    R2)(TitanicSailboat

    )(PondArrowRowBoat),( yTitanicFaster

    R3

    )(TitanicSteamboat R1

    )(MistralSailboat

    R2)(MistralSailboat

    )(PondArrowRowBoat