logical agents & first-order logic

27
Logical agents & First-order logic Tutorial 2 Tutorial 2 1

Upload: others

Post on 04-Nov-2021

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logical agents & First-order logic

Logical agents & First-order logic

Tutorial 2

Tutorial 2 1

Page 2: Logical agents & First-order logic

Outline

ā™¦ Knowledge-based agents

ā™¦ Wumpus world

ā™¦ Logic in generalā€”models and entailment

ā™¦ Propositional (Boolean) logic

ā™¦ Equivalence, validity, satisfiability

ā™¦ Inference rules and theorem provingā€“ forward chainingā€“ backward chainingā€“ resolution

ā™¦ Syntax and semantics of FOL

Tutorial 2 2

Page 3: Logical agents & First-order logic

Knowledge bases

Inference engine

Knowledge base domaināˆ’specific content

domaināˆ’independent algorithms

Knowledge base = set of sentences in a formal language

Declarative approach to building an agent (or other system):Tell it what it needs to know

Then it can Ask itself what to doā€”answers should follow from the KB

Agents can be viewed at the knowledge leveli.e., what they know, regardless of how implemented

Or at the implementation leveli.e., data structures in KB and algorithms that manipulate them

Tutorial 2 3

Page 4: Logical agents & First-order logic

Logic in general

Logics are formal languages for representing informationsuch that conclusions can be drawn

Syntax defines the sentences in the language

Semantics define the ā€œmeaningā€ of sentences;i.e., define truth of a sentence in a world

E.g., the language of arithmetic

x + 2 ā‰„ y is a sentence; x2 + y > is not a sentence

x + 2 ā‰„ y is true iff the number x + 2 is no less than the number y

x + 2 ā‰„ y is true in a world where x = 7, y = 1x + 2 ā‰„ y is false in a world where x = 0, y = 6

Tutorial 2 4

Page 5: Logical agents & First-order logic

Entailment

Entailment means that one thing follows from another:

KB |= Ī±

Knowledge base KB entails sentence Ī±if and only if

Ī± is true in all worlds where KB is true

E.g., the KB containing ā€œthe Giants wonā€ and ā€œthe Reds wonā€entails ā€œEither the Giants won or the Reds wonā€

E.g., x + y = 4 entails 4 = x + y

Entailment is a relationship between sentences (i.e., syntax)that is based on semantics

Note: brains process syntax (of some sort)

Tutorial 2 5

Page 6: Logical agents & First-order logic

Models

Logicians typically think in terms of models, which are formallystructured worlds with respect to which truth can be evaluated

We say m is a model of a sentence Ī± if Ī± is true in m

M(Ī±) is the set of all models of Ī±

Then KB |= Ī± if and only if M(KB) āŠ† M(Ī±)

E.g. KB = Giants won and Reds wonĪ± = Giants won M( )

M(KB)

x

x

x

x

x

x

x x

x

x

xx

xx

xx

xx

x

xxxx

x x

xx

xx x

x

xx

x x x

x

xx

x

x

x

x

x

x

x

x

Tutorial 2 6

Page 7: Logical agents & First-order logic

Propositional logic: Syntax

Propositional logic is the simplest logicā€”illustrates basic ideas

The proposition symbols P1, P2 etc are sentences

If S is a sentence, Ā¬S is a sentence (negation)

If S1 and S2 are sentences, S1 āˆ§ S2 is a sentence (conjunction)

If S1 and S2 are sentences, S1 āˆØ S2 is a sentence (disjunction)

If S1 and S2 are sentences, S1 ā‡’ S2 is a sentence (implication)

If S1 and S2 are sentences, S1 ā‡” S2 is a sentence (biconditional)

Tutorial 2 7

Page 8: Logical agents & First-order logic

Propositional logic: Semantics

Each model specifies true/false for each proposition symbol

E.g. P1,2 P2,2 P3,1

true true false

(With these symbols, 8 possible models, can be enumerated automatically.)

Rules for evaluating truth with respect to a model m:

Ā¬S is true iff S is falseS1 āˆ§ S2 is true iff S1 is true and S2 is trueS1 āˆØ S2 is true iff S1 is true or S2 is true

S1 ā‡’ S2 is true iff S1 is false or S2 is truei.e., is false iff S1 is true and S2 is false

S1 ā‡” S2 is true iff S1 ā‡’ S2 is true and S2 ā‡’ S1 is true

Simple recursive process evaluates an arbitrary sentence, e.g.,Ā¬P1,2 āˆ§ (P2,2 āˆØ P3,1) = true āˆ§ (false āˆØ true) = true āˆ§ true = true

Tutorial 2 8

Page 9: Logical agents & First-order logic

Logical equivalence

Two sentences are logically equivalent iff true in same models:Ī± ā‰” Ī² if and only if Ī± |= Ī² and Ī² |= Ī±

(Ī± āˆ§ Ī²) ā‰” (Ī² āˆ§ Ī±) commutativity of āˆ§(Ī± āˆØ Ī²) ā‰” (Ī² āˆØ Ī±) commutativity of āˆØ

((Ī± āˆ§ Ī²) āˆ§ Ī³) ā‰” (Ī± āˆ§ (Ī² āˆ§ Ī³)) associativity of āˆ§((Ī± āˆØ Ī²) āˆØ Ī³) ā‰” (Ī± āˆØ (Ī² āˆØ Ī³)) associativity of āˆØ

Ā¬(Ā¬Ī±) ā‰” Ī± double-negation elimination(Ī± ā‡’ Ī²) ā‰” (Ā¬Ī² ā‡’ Ā¬Ī±) contraposition(Ī± ā‡’ Ī²) ā‰” (Ā¬Ī± āˆØ Ī²) implication elimination(Ī± ā‡” Ī²) ā‰” ((Ī± ā‡’ Ī²) āˆ§ (Ī² ā‡’ Ī±)) biconditional eliminationĀ¬(Ī± āˆ§ Ī²) ā‰” (Ā¬Ī± āˆØ Ā¬Ī²) De MorganĀ¬(Ī± āˆØ Ī²) ā‰” (Ā¬Ī± āˆ§ Ā¬Ī²) De Morgan

(Ī± āˆ§ (Ī² āˆØ Ī³)) ā‰” ((Ī± āˆ§ Ī²) āˆØ (Ī± āˆ§ Ī³)) distributivity of āˆ§ over āˆØ(Ī± āˆØ (Ī² āˆ§ Ī³)) ā‰” ((Ī± āˆØ Ī²) āˆ§ (Ī± āˆØ Ī³)) distributivity of āˆØ over āˆ§

Tutorial 2 9

Page 10: Logical agents & First-order logic

Validity and satisfiability

A sentence is valid if it is true in all models,e.g., True, A āˆØ Ā¬A, A ā‡’ A, (A āˆ§ (A ā‡’ B)) ā‡’ B

Validity is connected to inference via the Deduction Theorem:KB |= Ī± if and only if (KB ā‡’ Ī±) is valid

A sentence is satisfiable if it is true in some modele.g., A āˆØB, C

A sentence is unsatisfiable if it is true in no modelse.g., A āˆ§ Ā¬A

Satisfiability is connected to inference via the following:KB |= Ī± if and only if (KB āˆ§ Ā¬Ī±) is unsatisfiable

i.e., prove Ī± by reductio ad absurdum

Tutorial 2 10

Page 11: Logical agents & First-order logic

Forward and backward chaining

Horn Form (restricted)KB = conjunction of Horn clauses

Horn clause =ā™¦ proposition symbol; orā™¦ (conjunction of symbols) ā‡’ symbol

E.g., C āˆ§ (B ā‡’ A) āˆ§ (C āˆ§D ā‡’ B)

Modus Ponens (for Horn Form): complete for Horn KBs

Ī±1, . . . , Ī±n, Ī±1 āˆ§ Ā· Ā· Ā· āˆ§ Ī±n ā‡’ Ī²

Ī²

Can be used with forward chaining or backward chaining.These algorithms are very natural and run in linear time

Tutorial 2 11

Page 12: Logical agents & First-order logic

Forward vs. backward chaining

FC is data-driven, cf. automatic, unconscious processing,e.g., object recognition, routine decisions

May do lots of work that is irrelevant to the goal

BC is goal-driven, appropriate for problem-solving,e.g., Where are my keys? How do I get into a PhD program?

Complexity of BC can be much less than linear in size of KB

Tutorial 2 12

Page 13: Logical agents & First-order logic

Resolution

Conjunctive Normal Form (CNFā€”universal)conjunction of disjunctions of literalsļøø ļø·ļø· ļøø

clausesE.g., (A āˆØ Ā¬B) āˆ§ (B āˆØ Ā¬C āˆØ Ā¬D)

Resolution inference rule (for CNF): complete for propositional logic

`1 āˆØ Ā· Ā· Ā· āˆØ `k, m1 āˆØ Ā· Ā· Ā· āˆØmn

`1 āˆØ Ā· Ā· Ā· āˆØ `iāˆ’1 āˆØ `i+1 āˆØ Ā· Ā· Ā· āˆØ `k āˆØm1 āˆØ Ā· Ā· Ā· āˆØmjāˆ’1 āˆØmj+1 āˆØ Ā· Ā· Ā· āˆØmn

where `i and mj are complementary literals. E.g.,

OK

OK OK

A

A

B

P?

P?

A

S

OK

P

W

A

P1,3 āˆØ P2,2, Ā¬P2,2

P1,3

Resolution is sound and complete for propositional logic

Tutorial 2 13

Page 14: Logical agents & First-order logic

First-order logic

Whereas propositional logic assumes world contains facts,first-order logic (like natural language) assumes the world contains

ā€¢ Objects: people, houses, numbers, theories, Ronald McDonald, colors,baseball games, wars, centuries . . .

ā€¢ Relations: red, round, bogus, prime, multistoried . . .,brother of, bigger than, inside, part of, has color, occurred after, owns,comes between, . . .

ā€¢ Functions: father of, best friend, third inning of, one more than, end of. . .

Tutorial 2 14

Page 15: Logical agents & First-order logic

Logics in general

Language Ontological EpistemologicalCommitment Commitment

Propositional logic facts true/false/unknownFirst-order logic facts, objects, relations true/false/unknownTemporal logic facts, objects, relations, times true/false/unknownProbability theory facts degree of beliefFuzzy logic facts + degree of truth known interval value

Tutorial 2 15

Page 16: Logical agents & First-order logic

Syntax of FOL: Basic elements

Constants KingJohn, 2, UCB, . . .Predicates Brother, >, . . .Functions Sqrt, LeftLegOf, . . .Variables x, y, a, b, . . .Connectives āˆ§ āˆØ Ā¬ ā‡’ ā‡”Equality =Quantifiers āˆ€ āˆƒ

Tutorial 2 16

Page 17: Logical agents & First-order logic

Atomic sentences

Atomic sentence = predicate(term1, . . . , termn)or term1 = term2

Term = function(term1, . . . , termn)or constant or variable

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

Tutorial 2 17

Page 18: Logical agents & First-order logic

Complex sentences

Complex sentences are made from atomic sentences using connectives

Ā¬S, S1 āˆ§ S2, S1 āˆØ S2, S1 ā‡’ S2, S1 ā‡” S2

E.g. Sibling(KingJohn,Richard) ā‡’ Sibling(Richard, KingJohn)>(1, 2) āˆØ ā‰¤(1, 2)>(1, 2) āˆ§ Ā¬>(1, 2)

Tutorial 2 18

Page 19: Logical agents & First-order logic

Universal quantification

āˆ€ 怈variables怉 怈sentence怉Everyone at Berkeley is smart:āˆ€x At(x,Berkeley) ā‡’ Smart(x)

āˆ€x P is true in a model m iff P is true with x beingeach possible object in the model

Roughly speaking, equivalent to the conjunction of instantiations of P

(At(KingJohn,Berkeley) ā‡’ Smart(KingJohn))āˆ§ (At(Richard, Berkeley) ā‡’ Smart(Richard))āˆ§ (At(Berkeley, Berkeley) ā‡’ Smart(Berkeley))āˆ§ . . .

Tutorial 2 19

Page 20: Logical agents & First-order logic

Existential quantification

āˆƒ 怈variables怉 怈sentence怉Someone at Stanford is smart:āˆƒx At(x, Stanford) āˆ§ Smart(x)

āˆƒx P is true in a model m iff P is true with x beingsome possible object in the model

Roughly speaking, equivalent to the disjunction of instantiations of P

(At(KingJohn, Stanford) āˆ§ Smart(KingJohn))āˆØ (At(Richard, Stanford) āˆ§ Smart(Richard))āˆØ (At(Stanford, Stanford) āˆ§ Smart(Stanford))āˆØ . . .

Tutorial 2 20

Page 21: Logical agents & First-order logic

Properties of quantifiers

āˆ€x āˆ€ y is the same as āˆ€ y āˆ€x (why??)

āˆƒx āˆƒ y is the same as āˆƒ y āˆƒx (why??)

āˆƒx āˆ€ y is not the same as āˆ€ y āˆƒx

āˆƒx āˆ€ y Loves(x, y)ā€œThere is a person who loves everyone in the worldā€

āˆ€ y āˆƒx Loves(x, y)ā€œEveryone in the world is loved by at least one personā€

Quantifier duality: each can be expressed using the other

āˆ€x Likes(x, IceCream) Ā¬āˆƒx Ā¬Likes(x, IceCream)

āˆƒx Likes(x,Broccoli) Ā¬āˆ€x Ā¬Likes(x,Broccoli)

Tutorial 2 21

Page 22: Logical agents & First-order logic

Equality

term1 = term2 is true under a given interpretationif and only if term1 and term2 refer to the same object

E.g., 1 = 2 and āˆ€x Ɨ(Sqrt(x), Sqrt(x)) = x are satisfiable2 = 2 is valid

E.g., definition of (full) Sibling in terms of Parent:āˆ€x, y Sibling(x, y) ā‡” [Ā¬(x = y) āˆ§ āˆƒm, f Ā¬(m = f ) āˆ§

Parent(m,x) āˆ§ Parent(f, x) āˆ§ Parent(m, y) āˆ§ Parent(f, y)]

Tutorial 2 22

Page 23: Logical agents & First-order logic

Summary

Logical agents apply inference to a knowledge baseto derive new information and make decisions

Basic concepts of logic:ā€“ syntax: formal structure of sentencesā€“ semantics: truth of sentences wrt modelsā€“ entailment: necessary truth of one sentence given anotherā€“ inference: deriving sentences from other sentencesā€“ soundess: derivations produce only entailed sentencesā€“ completeness: derivations can produce all entailed sentences

Wumpus world requires the ability to represent partial and negated informa-tion, reason by cases, etc.

Forward, backward chaining are linear-time, complete for Horn clausesResolution is complete for propositional logic

Propositional logic lacks expressive power

Tutorial 2 23

Page 24: Logical agents & First-order logic

First-order logic:ā€“ objects and relations are semantic primitivesā€“ syntax: constants, functions, predicates, equality, quantifiers

Increased expressive power: sufficient to define wumpus world

Situation calculus:ā€“ conventions for describing actions and change in FOLā€“ can formulate planning as inference on a situation calculus KB

Tutorial 2 24

Page 25: Logical agents & First-order logic

Exercises

ā™¦ Decide whether each of the following sentences is valid, unsatisfiable, orneither. Verify your decisions using truth tables or the equivalence rules ofFigure 7.11.

a. Smoke ā‡’ Smoke

b. (Smoke ā‡’ Fire) ā‡’ (Ā¬Smoke ā‡’ Ā¬Fire)

ā™¦ Represent the following sentences in first-order logic, using a consistentvocabulary (which you must define):

a. Only one student took Greek in spring 2001

b. The best score in Greek is always higher than the best score in French

Tutorial 2 25

Page 26: Logical agents & First-order logic

Answers

1.

a. V alid

b. Satisfiable

2.

Let the basic vocabulary be as follows:

Takes(x, c, s): student x takes course c in semester s;

Score(x, c, s): the score obtained by student x in course c in semester s;

x > y: x is greater than y;

F and G: specific French and Greek courses (one could also interpret thesesentences as referring to any such course.

a. āˆƒx, Student(x)āˆ§Takes(x,G, Spring2001)āˆ§āˆ€y, y 6= x ā‡’ Ā¬Takes(y, G, Spring2001)

Tutorial 2 26

Page 27: Logical agents & First-order logic

b. āˆ€s, āˆƒx, āˆ€y, Score(x,G, s) > Score(y, F, s)

Tutorial 2 27