Top Banner
Explorations in Artificial Intelligence Prof. Carla P. Gomes [email protected] Module 3 Logic Representations (Part 3)
52

Explorations in Artificial Intelligence

Dec 31, 2015

Download

Documents

Sara Craig

Explorations in Artificial Intelligence. Prof. Carla P. Gomes [email protected] Module 3 Logic Representations (Part 3). 3-First-order Logic. Pros and cons of propositional logic.  Propositional logic is declarative - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Explorations in Artificial Intelligence

Explorations in Artificial Intelligence

Prof. Carla P. [email protected]

Module 3 Logic Representations

(Part 3)

Page 2: Explorations in Artificial Intelligence

3-First-order Logic

Page 3: Explorations in Artificial Intelligence

Pros and cons of propositional logic

Propositional logic is declarative Propositional logic allows partial/disjunctive/negated information

– (unlike most data structures and databases)Propositional logic is compositional:

– meaning of B1,1 P1,2 is derived from meaning of B1,1 and of P1,2

Meaning in propositional logic is context-independent– (unlike natural language, where meaning depends on context)

Fast solvers for propositional logic

Propositional logic has very limited expressive power– (unlike natural language)– E.g., cannot say "pits cause breezes in adjacent squares“

• except by writing one sentence for each square– E.g., when we move block B, it is the same block asserted by ON_B_C.

In PL atoms are strings that have no internal structure!

–•

–•

Page 4: Explorations in Artificial Intelligence

First-order logic

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

– Objects: people, houses, numbers, colors, baseball games, wars, …– Relations: red, round, prime, brother of, bigger than, part of, comes

between, …– Functions: father of, best friend, one more than, plus, …–

Page 5: Explorations in Artificial Intelligence

Syntax of FOL: Basic elements

Object Constants infinite set (convention – they start with a capital letter or numeral); Examples: Aa; 125; Q; EiffelTower

Functions Constantsinfinite set of function constants of all arities;convention – start with lower case letter, with arity as superscript (for now…)Examples: fatherOf1; times2; areaOfRectangle2;…

Predicates (relations)infinite set of predicates or relations constants of all arities;convention – start with capital letter, with arity as superscript (for now…)Examples: Large1; Parent2; Clear1;…

Variables --- x, y, a, b,...Connectives --- , , , , Equality --- = Quantifiers --- ,

Page 6: Explorations in Artificial Intelligence

Syntax of FOL: Terms and WFFS

Terms– An object constant is a term– A variable is a term; – A function constant of arity n, followed by n terms in parentheses and separated by

commas (functional expression);–

In a nutshell: Term = function (term1,...,termn) or constant or variable

Examples: fatherOf(John); times(4. plus(3,6)); Sam;…

WFFs

• Atoms: a predicate (or relation) constant of arity n followed by n terms in parentheses and separated by commas is an atom (or atomic formula); an atom is a wff. Note: a predicate or relation of arity 0 omits the parentheses.

Examples: GreaterThan(7,2); Q; • Wff: any expression formed out of predicate-calculus wffs in the same way as

propositional calculus.

Examples: [ GreaterThan(7,2) LessThan(15,4)] Brother(John,Sam) P

Page 7: Explorations in Artificial Intelligence

Syntax of FOL

Sentence AtomicSentence| (Sentence Connective Sentence)| Quantifier Variable, …. Sentence| Sentence

AtomicSentence Predicate(Term) | Term=TermTerm Function(Term)

| Constant| Variable

Connective |||Quantifiers |Constant A | X1 | John | …Variable a | x | s | …Predicte Before |HasColor | Raining |…Function Mother | LeftLeg |…

Page 8: Explorations in Artificial Intelligence

First-Order Logic:Semantics

Sentences are true with respect to a model and an interpretation

Model contains objects (domain elements) and relations among them.

Page 9: Explorations in Artificial Intelligence

First-Order Logic:Semantics

WorldsOur language allows us to refer to objects in the world as well as to propositions.– Objects - correspond to individuals in the world (concrete or fictional, as

long as we give them a name) e.g., BlockA, New-York, 7, ¼, π– Functions on individuals;– Relations or predicates over individuals.

Interpretations specify referents for (these assignments are denotations)constant symbols → objects in the worldpredicate symbols → relations in the worldfunction symbols → functional relations in the world

Domain of interpretation – set of objects to which object constant assignments are made.

Page 10: Explorations in Artificial Intelligence

Truth in first-order logic

Predicate Calculus

World

A

B

C

F1

On

Clear

A

B

C

Floor

On={<B,A>,<A,C>,<C.Floor>}(*)

Clear = {<B>}

(*) we define the relations by the tuples of objects that participate in them

On(A,B) False;Clear(B) True;On(C,F1) On(A,b) True

Page 11: Explorations in Artificial Intelligence

Models for FOL: Example

Model with five objects:•Richard the LionHeart, king of England (1189-1199);•Evil King John, Richard’s brother (1199-1215);•The left legs of Richard and John•A crown

Binary relation

Unary relations (or properties)

functions

LeftLeg(Richard)

x King(x) Greedy(x) Evil(x)King(John)Brother(Richard,John)

Page 12: Explorations in Artificial Intelligence

First-order logic:Models and Related Notions

•Satisfiability– An interpretation satisfies a wff if the wff has the value True under that interpretation.

•Model– An interpretation that satisfies a wff is a model of that wff.

•Validity– Any w wff that has the value True under all the interpretations is valid.

•Inconsistency– Any wff that does not have a model is inconsistent or unsatisfiable.

•Entailment– If a wff ω has a value True under all of those interpretations for which each of the

wffs in a set Δ has the value True, then Δ logically entails ω•Equivalence

– Two wffs are equivalent iff their truth values are identical under all interpretations (i.e., if they logically entail one another).

Page 13: Explorations in Artificial Intelligence

First Order Logic:Variables and Quantification

How would we say that every block in the world has a property – say “clear” We would have to say: Clear(A); Clear(B); … for all the blocks… (it may be long or worse we may have an infinite

number of blocks…)

What do we need:Variable symbols – convention – use lower case letters p, p1, q, …Quantifiers:

Universal quantifier (x) P(x) P(x) is true for all the values x in the

universe of discourseWhen is it true? When is it false?

Existential quantifier (x)[P(x) there exists an element x in the universe of

discourse such that P(x) is true.When is it true? When is it false?

Page 14: Explorations in Artificial Intelligence

Quantified formulas

If ω is a wff and x is a variable symbol, then both (x) ω and (x) ω are

wffs.

x is the variable quantified over;

ω is said to be within the scope of the quantifier

if all the variables in ω are quantified over in ω, we say that we have a closed wff or closed sentence.

Example:

(x) [P(x) R(x)]; (x)[P(x)(( y) [R(x,y) S(f(x))]]

Page 15: Explorations in Artificial Intelligence

Quantified formulas

Note 1: as we will see (x)[(y)ω] is equivalent to (y)[(x)ω];

We can also put all the quantified variables together, i.e., (x,y)ω.

When all the quantified variables are together, before ω, we call ω the matrix

Note 2: The order of quantifiers is important!

Note 3: the variables of quantifiers are “dummy” variables – we can rename them without changing the value of the wff.

Note 4: quantifying over variables makes the first-order logic very powerful – why not quantify over predicate symbols or functions symbols? Not in the version of predicate calculus we are using – that is why we called it first-order logic; second- and higher-order predicate calculi allow quantification over relation and function symbols. Problem – much more complex inference mechanisms

Page 16: Explorations in Artificial Intelligence

Binding Variables

Binding variables:

When a quantifier is used on a variable x or when we assign a value to this variable, we say that this occurrence of the variable is bound.

An occurrence of a variable that is not bound by a quantifier or set equal to a particular variable is free.

All the variables that occur in a propositional function must be bound to turn it into a proposition (done by combination of universal and existentialquantifiers and value assignments).

The part of a logical expression to which a quantifier is applied is called the scope of the quantifier; A variable is free if it is outside the scope of all the quantifiers in the formula that specifies this variable.

Page 17: Explorations in Artificial Intelligence

Scope of

All variables are bound(x) (P(x) Q(x)) x R(x)

Page 18: Explorations in Artificial Intelligence

Semantics:Universal quantification

<variables> <sentence>

x P is true in a model m iff P is true with x being each possible object in the model

Everyone at Cornell is smart:x At(x,Cornell) Smart(x)

Roughly speaking, equivalent to the conjunction of instantiations of PAt(Mary,Cornell) Smart(Mary)

At(Richard,Cornell) Smart(Richard) At(John,Cornell) Smart(John) ...

• --- we refer to the domain of x as the universe of discourse.

Page 19: Explorations in Artificial Intelligence

A common mistake to avoid

Typically, is the main connective with Common mistake: using as the main connective with :

x At(x,Cornell) Smart(x)

means “Everyone is at Cornell and everyone is smart”

Page 20: Explorations in Artificial Intelligence

Existential quantification

<variables> <sentence>

Someone at Cornell is smart:x At(x,Cornell) Smart(x)

x P is true in a model m iff P is true with x being some possible object in the model

Roughly speaking, equivalent to the disjunction of instantiations of PAt(John,Cornell) Smart(John)

At(Mary,Cornell) Smart(Mary) At(Richard,Cornell) Smart(Richard) ...

••

Page 21: Explorations in Artificial Intelligence

Another common mistake to avoid

Typically, is the main connective with

Common mistake: using as the main connective with :

x At(x,Cornell) Smart(x)

is true if there is anyone who is not at Cornell!•

Page 22: Explorations in Artificial Intelligence

Properties of quantifiers

x y is the same as y xx y is the same as y x

x y is not the same as y xx 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 otherx Likes(x,IceCream) x Likes(x,IceCream)x Likes(x,Broccoli) x Likes(x,Broccoli)

Page 23: Explorations in Artificial Intelligence

Love Affairs Loves(x,y) x loves y

Everybody loves Jerry

x Loves (x, Jerry)

Everybody loves somebody

x y Loves (x, y)

There is somebody whom somebody loves

y x Loves (x, y)

Nobody loves everybody

x y Loves (x, y) = x y Loves (x, y)

There is somebody whom Lydia doesn’t love

y Loves (Lydia, y)

Page 24: Explorations in Artificial Intelligence

Love AffairsLoves(x,y) x loves y

There is somebody whom no one loves

y x Loves (x, y)

There is exactly one person whom everybody loves

y(x Loves(x,y) z((w Loves (w ,z) z=y))

There are exactly two people whom Lynn Loves

x y ((xy) Loves(Lynn,x) Loves(Lynn,y) z( Loves (Lynn ,z) (z=x z=y)))

Everybody loves himself or herself

x Loves(x,x)

There is someone who loves no one besides herself or himself

x y Loves(x,y) (x=y) (note biconditional – why?)

Page 25: Explorations in Artificial Intelligence

Let Q(x,y) denote “xy =0”; consider the domain of discourse the real

numbers

What is the truth value of

a) y x Q(x,y)?

b) x y Q(x,y)?

False

True

Page 26: Explorations in Artificial Intelligence

Statement When True When False

x y P(x,y)

y x P(x,y)

P(x,y) is true for every pair

There is a pair for which P(x.y) is false

x y P(x,y) For every x there is a y for which P(x,y) is true

There is an x such that P(x,y) is false for every y.

x y P(x,y) There is an x such that P(x,y) is true for every y.

For every x there is a y for which P(x,y) is false

x y P(x,y)

y x P(x,y)

There is a pair x, y for which P(x,y) is true

P(x,y) is flase fo every pair x,y.

Page 27: Explorations in Artificial Intelligence

Negation

Negation Equivalent

Statement

When is the negation True

When is False

x P(x) x P(x) For every x, P(x) is false

There is an x for which P(x) is true.

x P(x) x P(x) There is an x for which P(x) is false.

For every x, P(x) is true.

Page 28: Explorations in Artificial Intelligence

There is an honest politician x H(x)

Where H(x) denotes: x is honest.

(universe of discourse consists of all the politicians)

Negation x H(x) x H(x) (Every politician is dishonest)

All Americans eat cheeseburgers x C(x)

C(x) denotes: x eats cheeseburgers

Negation x C(x) x C(x)

(Some American does not eat cheeseburgers)

Page 29: Explorations in Artificial Intelligence

Equality

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

E.g., definition of 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)]•

Page 30: Explorations in Artificial Intelligence

Using FOL

The kinship domain:Brothers are siblings

x,y Brother(x,y) Sibling(x,y)

One's mother is one's female parentm,c Mother(c) = m (Female(m) Parent(m,c))

“Sibling” is symmetricx,y Sibling(x,y) Sibling(y,x)

Page 31: Explorations in Artificial Intelligence

Using FOLThe set domain: Only sets are empty sets or those made by adjoining something to a set

s Set(s) (s = {} ) (x,s2 Set(s2) s = {x|s2})The empty set has no element adjoined to itx,s {x|s} = {}Adjoining an element already in the set has no effectx,s x s s = {x|s}Only elements have been adjoined to it

x,s x s [ y,s2} (s = {y|s2} (x = y x s2))]Subset

s1,s2 s1 s2 (x x s1 x s2)Equality of sets

s1,s2 (s1 = s2) (s1 s2 s2 s1)Intersection

x,s1,s2 x (s1 s2) (x s1 x s2)Uniion

x,s1,s2 x (s1 s2) (x s1 x s2)

Page 32: Explorations in Artificial Intelligence

Interacting with FOL KBs

Substitution:

Given a sentence S and a substitution σ,Sσ denotes the result of plugging σ into S; e.g.,

S = Smarter(x,y)σ = {x/Hillary,y/Bill}Sσ = Smarter(Hillary,Bill)

Page 33: Explorations in Artificial Intelligence

Knowledge engineering in FOL

Identify the taskAssemble the relevant knowledgeDecide on a vocabulary of predicates, functions, and constantsEncode general knowledge about the domainEncode a description of the specific problem instancePose queries to the inference procedure and get answersDebug the knowledge base

“The big problem of AI is what to say not how to say it but ”

Page 34: Explorations in Artificial Intelligence

First-Order Logic:Rules of Inference

Propositional Logic rules of inference generalize to first-order logic.

+

Other inference rules

Page 35: Explorations in Artificial Intelligence

Universal instantiation (UI)

Every instantiation of a universally quantified wff is entailed by it:(x) P(x)

P(c) for any variable v and ground term g

E.g., (x) (King(x) Greedy(x) Evil(x) )yields:King(John) Greedy(John) Evil(John)King(Richard) Greedy(Richard) Evil(Richard)King(Father(John)) Greedy(Father(John)) Evil(Father(John))..

.We conclude that P(c) is true, where c is a particular member of the universe of discourse, given the premise (x) P(x). Example – All women are wise – Mary is wise;

x can be John or Richard or Father of John

Page 36: Explorations in Artificial Intelligence

Universal Generalization (UG)

Every instantiation of a universally quantified wff is entailed by it:P(c) for an arbitrary c

(x) P(x)

E.g., King(x) ..

x can be John or Richard or Father of John, they are all Kings

Page 37: Explorations in Artificial Intelligence

Existential instantiation (EI)

For any wff α, variable v, and constant symbol k that does not appear elsewhere in the knowledge base:

v αSubst({v/k}, α)

E.g., x Crown(x) OnHead(x,John) yields:

Crown(C1) OnHead(C1,John)

provided C1 is a new constant symbol, called a Skolem constant••

This rule allows us to conclude that there is an element c in the universe of discoursefor which P(c) is true if we know x P(x) is true; We cannot select it arbitrarily though…we may give it a name that does and continue our argument…

Page 38: Explorations in Artificial Intelligence

Existential instantiation (EI)

(x) P(x)

P(k) for some element k (we use a symbol k that does not appear elsewhere in the knowledge base)

E.g., x Crown(x) OnHead(x,John) yields:

Crown(C1) OnHead(C1,John)

provided C1 is a new constant symbol, called a Skolem constant••

This rule allows us to conclude that there is an element c in the universe of discoursefor which P(c) is true if we know x P(x) is true; We cannot select it arbitrarily though…we may give it a name that does and continue our argument…

Page 39: Explorations in Artificial Intelligence

Existential Generalization (EG)

P(c) for some element c (x) P(x)

We can conclude (x) P(x), since a particular element c satisfies

Page 40: Explorations in Artificial Intelligence

(x) P(x)

P(c) Universal Instantiation

P(c) for an arbitrary c (x) P(x)

Universal Generalization

(x) P(x) P(c) for some element c

Existential Instantiation

P(c) for some element c (x) P(x)

Existential Generalization

Page 41: Explorations in Artificial Intelligence

Example:

Let Info372(x) denote: x is taking Info 372 class

Let AI(x) denote: x has taken a course in AI

Consider the premises x (Info372(x) AI(x))

Info372(Ron)

We can conclude AI(Ron)

Page 42: Explorations in Artificial Intelligence

Arguments

Argument:

Step Reason

1x (Info372(x) AI(x)) premise

2 Info372(Ron) AI(Ron) Universal Instantiation

3 Infor372(Ron) Premise

4 AI(Ron) Modus Ponens (2 and 3)

Page 43: Explorations in Artificial Intelligence

Example

Show that the premises:

1- A student in this class has not read the textbook;

2- Everyone in this class passed the first homework

Imply

Someone who has passed the first homework has not read the textbook

Page 44: Explorations in Artificial Intelligence

Example

Solution:

Let C(x) x is in this class;

T(x) x has read the textbook;

P(x) x passed the first homework

Premises:

x (Cx T(x))

x (C(x)P(x))

Conclusion: we want to show x (P(x) T(x))

Page 45: Explorations in Artificial Intelligence

Step Reason

1 x (Cx T(x)) premise

2 C(a) T(a) Existential Instantiation from 1

3 C(a) Simplification 2

4 x (C(x)P(x)) Premise

5 C(a)P(a) Universal Instanstiation from 4

6 P(a) Modus ponens from 3 and 5

7 T(a) Simplification from 2

8 P(a) T(a) Conjunction from 6 and 7

9 x P(x) T(x) Existential generalization from 8

Page 46: Explorations in Artificial Intelligence

Argument:

Step Reason

1x (Info372(x) AI(x)) premise

2 Info372(Ron) AI(Ron) Universal Instantiation

3 Infor372(Ron) Premise

4 AI(Ron) Modus Ponens (2 and 3)

Page 47: Explorations in Artificial Intelligence

Reduction to propositional inference

Suppose the KB contains just the following:x King(x) Greedy(x) Evil(x)King(John)Greedy(John)Brother(Richard,John)

Instantiating the universal sentence in all possible ways, we have:King(John) Greedy(John) Evil(John)King(Richard) Greedy(Richard) Evil(Richard)King(John)Greedy(John)Brother(Richard,John)

The new KB is propositionalized: proposition symbols are

King(John), Greedy(John), Evil(John), King(Richard), etc.

•–

»•

Page 48: Explorations in Artificial Intelligence

Reduction contd.

Every FOL KB can be propositionalized so as to preserve entailment

(A ground sentence is entailed by new KB iff entailed by original KB)

Idea: propositionalize KB and query, apply resolution, return result

Problem: with function symbols, there are infinitely many ground terms,– e.g., Father(Father(Father(John)))

–•

Page 49: Explorations in Artificial Intelligence

Problems with propositionalization

Propositionalization seems to generate lots of irrelevant sentences.

E.g., from the KB:x King(x) Greedy(x) Evil(x)King(John)y Greedy(y)Brother(Richard,John)

it seems obvious that Evil(John), but propositionalization produces lots of facts such as Greedy(Richard), that are irrelevant

With p k-ary predicates and n constants, there are p·nk instantiations.

Page 50: Explorations in Artificial Intelligence

We can get the inference immediately if we can find a substitution θ such that King(x) and Greedy(x) match King(John) and Greedy(y)

θ = {x/John,y/John} works

Unify(α,β) = θ if αθ = βθ

Page 51: Explorations in Artificial Intelligence

Inference in First-Order Logic

Unification

Generalized Modus Ponens

Forward chaining

Backward chaining

Resolution

More advanced… CS 472

How to perform substitution of variables, e.g., toperform resolution?

Page 52: Explorations in Artificial Intelligence

Summary

First-order logic:– objects and relations are semantic primitives

– syntax: constants, functions, predicates, equality, quantifiers

Increased expressive power: sufficient to define wumpus world

… but it’s much harder the Propositional Logic – in theory and in practice…