80
Introduction to Logic Relational Logic Michael Genesereth Computer Science Department Stanford University

Introduction to Logic Relational Logic

  • Upload
    others

  • View
    9

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Logic Relational Logic

Introduction to LogicRelational Logic

Michael GeneserethComputer Science Department

Stanford University

Page 2: Introduction to Logic Relational Logic

Premises: If Abby likes Bess, then Bess likes Abby. Abby likes Bess.

Conclusion: Bess likes Abby.

Propositional Logic

Page 3: Introduction to Logic Relational Logic

Symmetry of Affection: If Abby likes Bess, then Bess likes Abby. If Abby likes Cody, then Cody likes Abby. If Abby likes Dana, then Dana likes Abby. ... If Bess likes Abby, then Abby likes Bess. If Cody likes Abby, then Abby likes Cody. If Dana likes Abby, then Abby likes Dana. Doing things this way is annoyingly verbose.

Problem

Page 4: Introduction to Logic Relational Logic

New Linguistic Features: Variables Quantifiers

Informal Sentence: For every X and for every Y, if X likes Y, then Y likes X.

Formal Sentence:∀x.∀y.(likes(x,y) ⇒ likes(y,x))

Relational Logic

Page 5: Introduction to Logic Relational Logic

Syntax

Page 6: Introduction to Logic Relational Logic

Wordsa b c p q r x y z

Sentences∀x.(p(x,a) ∧ q(x,b) ⇒ r(a,b))

Components of Language

Page 7: Introduction to Logic Relational Logic

Words are strings of letters, digits, and occurrences of the underscore character.

Variables begin with characters from the end of the alphabet (from u through z).

u, v, w, x, y, z

Constants begin with digits or letters from the beginning of the alphabet (from a through t).

a, b, c, 123, cs157, barackobama

Note that, in the online tools, we use lower case and capital letters to distinguish constants and variables.

Words

Page 8: Introduction to Logic Relational Logic

Object constants represent objects.

joe stanford usa 2345

Relation constants represent properties or relationships.

isaperson isacountry knows likes between

Constants

Page 9: Introduction to Logic Relational Logic

The arity of a relation constant is the number of arguments it takes.

Unary relation constant - 1 argumente.g. isaperson, isacountry

Binary relation constant - 2 argumentse.g. knows, likes

Ternary relation constant - 3 argumentse.g. between

n-ary relation constant - n arguments

Arity

Page 10: Introduction to Logic Relational Logic

A vocabulary / signature consists of a finite, non-empty set of object constants and a finite, non-empty set of relation constants together with a specification of arity for the relation constants.

Object Constants: a, bUnary Relation Constant: pBinary Relation Constant: q

Vocabularies

Page 11: Introduction to Logic Relational Logic

A term is either (1) a variable or (2) an object constant.

Terms represent objects.

Terms are analogous to pronouns and nouns in English.

Terms

Page 12: Introduction to Logic Relational Logic

Three types of sentences in Relational Logic:

Relational sentences - analogous to the proposition constants in Propositional Logic

Logical sentences - analogous to logical sentences in Propositional Logic

Quantified sentences - sentences that express the significance of variables

Sentences

Page 13: Introduction to Logic Relational Logic

A relational sentence is an expression formed from an n-ary relation constant and n terms enclosed in parentheses and separated by commas.

q(a,y)

Relational sentences are not terms and cannot be nested in relational sentences.

No! q(a,q(a,y)) No!

Relational sentences are also called atoms or atomic sentences.

Relational Sentences

Page 14: Introduction to Logic Relational Logic

Logical sentences in Relational Logic are analogous to those in Propositional Logic (except with relational sentences in place of propositional constants)

(¬q(a,b))(p(a) ∧ p(b))(p(a) ∨ p(b))(q(x,y) ⇒ q(y,x))(q(x,y) ⇔ q(y,x))

Logical Sentences

Page 15: Introduction to Logic Relational Logic

Universal sentences assert facts about all objects.

(∀x.(p(x) ⇒ q(x,x)))

Existential sentences assert the existence of objects with given properties.

(∃x.(p(x) ∧ q(x,x)))

The sentence contained within a quantified sentence is called the scope of that sentence.

Quantified Sentences

Page 16: Introduction to Logic Relational Logic

Quantified sentences can be nested within other sentences.

(∀x.p(x)) ∨ (∃x.q(x,x))(∀x.(∃y.(q(x,y) ∧ q(y,x))))

The sentence contained inside a quantified sentence is called the scope of that sentence.

Nesting

Page 17: Introduction to Logic Relational Logic

Parentheses can be removed when precedence allows us to reconstruct sentences correctly.

Precedence relations same as in Propositional Logic with quantifiers being of higher precedence than logical operators.

∀x.p(x) ⇒ q(x,x) → (∀x.p(x)) ⇒ q(x,x)∃x.p(x) ∧ q(x,x) → (∃x.p(x)) ∧ q(x,x)

Parentheses

Page 18: Introduction to Logic Relational Logic

An expression is ground if and only if it contains no variables.

Ground sentence:p(a)

Non-Ground Sentences:q(a,x)∀x.p(x)

Ground and Non-Ground Expressions

Page 19: Introduction to Logic Relational Logic

An occurrence of a variable is bound if and only if it lies in the scope of a quantifier of that variable. Otherwise, it is free.

∃y.q(x,y)

In this example, x is free and y is bound.

Bound and Free Variables

Page 20: Introduction to Logic Relational Logic

A sentence is open if and only if it has free variables. Otherwise, it is closed.

Open sentence:∃y.q(x,y)

Closed Sentence:∀x.∃y.q(x,y)

Open and Closed Sentences

Page 21: Introduction to Logic Relational Logic

Semantics

Page 22: Introduction to Logic Relational Logic

The Herbrand base for a Relational language is the set of all ground relational sentences that can be formed from the vocabulary of the language.

Herbrand Base

Page 23: Introduction to Logic Relational Logic

Object Constants: a, bUnary Relation Constant: pBinary Relation Constant: q

Herbrand Base:{p(a), p(b), q(a,a), q(a,b), q(b,a), q(b,b)}

Questions: How large is the Herbrand base for a vocabulary with 2 unary relation constants and n object constants?

How large is the Herbrand base for a vocabulary with 1 binary relation constant and n object constants?

Example

Page 24: Introduction to Logic Relational Logic

A truth assignment / interpretation is an association between ground atomic sentences and the truth values true or false. As with Propositional Logic, we use 1 as a synonym for true and 0 as a synonym for false.

p(a)i = 1 p(b)i = 0 q(a,a)i = 1 q(a,b)i = 0 q(b,a)i = 1 q(b,b)i = 0

How many truth assignments are there for a language with 2 object constants and a single binary relation constant?

Truth Assignment

Page 25: Introduction to Logic Relational Logic

A sentential truth assignment is an association between arbitrary sentences in a Relational language and the truth values 1 and 0.

Truth Assignment Sentential Truth Assignmentp(a)i = 1 (p(a) ∨ p(b))i = 1p(b)i = 0 (p(a) ∧ ¬p(b))i = 1

Each truth assignment leads to a sentential truth assignment based on the type of sentence.

Sentential Truth Assignment

Page 26: Introduction to Logic Relational Logic

(¬ϕ)i = 1 if and only if ϕi = 0

(ϕ ∧ ψ)i = 1 if and only if ϕi = 1 and ψi = 1

(ϕ ∨ ψ)i = 1 if and only if ϕ i = 1 or ψi = 1

(ϕ ⇒ ψ)i = 1 if and only if ϕi = 0 or ψi = 1

(ϕ ⇔ ψ)i = 1 if and only if ϕi = ψi

Logical Sentences

Page 27: Introduction to Logic Relational Logic

An instance of an expression is an expression in which all free variables have been consistently replaced by ground terms.

Examples: p(x) ⇒ q(x,x) p(x) ⇒ ∃y.q(x,y)

p(a) ⇒ q(a,a) p(a) ⇒ ∃y.q(a,y) p(b) ⇒ q(b,b) p(b) ⇒ ∃y.q(b,y)

Consistent replacement here means that, if one occurrence of a variable is replaced by a ground term, then all occurrences of that variable are replaced by the same ground term.

Instances

Page 28: Introduction to Logic Relational Logic

A universally quantified sentence is true for a truth assignment if and only if every instance of the scope of the quantified sentence is true for that assignment.

An existentially quantified sentence is true for a truth assignment if and only if some instance of the scope of the quantified sentence is true for that assignment.

Quantified Sentences

Page 29: Introduction to Logic Relational Logic

Truth Assignment:p(a)i = 1 q(a,a)i = 1p(b)i = 0 q(a,b)i = 0

q(b,a)i = 1 q(b,b)i = 0

Sentence:∀x.(p(x) ⇒ q(x,x))

Instances:p(a) ⇒ q(a,a)p(b) ⇒ q(b,b)

Example

Page 30: Introduction to Logic Relational Logic

Truth Assignment:p(a)i = 1 q(a,a)i = 1p(b)i = 0 q(a,b)i = 0

q(b,a)i = 1 q(b,b)i = 0

Sentence:∀x.(p(x) ⇒ q(x,x))

Instances:p(a) ⇒ q(a,a) √p(b) ⇒ q(b,b)

Example

Page 31: Introduction to Logic Relational Logic

Truth Assignment:p(a)i = 1 q(a,a)i = 1p(b)i = 0 q(a,b)i = 0

q(b,a)i = 1 q(b,b)i = 0

Sentence:∀x.(p(x) ⇒ q(x,x))

Instances:p(a) ⇒ q(a,a) √p(b) ⇒ q(b,b) √

Example

Page 32: Introduction to Logic Relational Logic

Truth Assignment:p(a)i = 1 q(a,a)i = 1p(b)i = 0 q(a,b)i = 0

q(b,a)i = 1 q(b,b)i = 0

Sentence:∀x.(p(x) ⇒ q(x,x)) √

Instances:p(a) ⇒ q(a,a) √p(b) ⇒ q(b,b) √

Example

Page 33: Introduction to Logic Relational Logic

Truth Assignment:p(a)i = 1 q(a,a)i = 1p(b)i = 0 q(a,b)i = 0

q(b,a)i = 1 q(b,b)i = 0

Sentence:∀x.∃y.q(x,y)

Instances: ∃y.q(a,y) ∃y.q(b,y) q(a,a) q(b,a) q(a,b) q(b,b)

Example

Page 34: Introduction to Logic Relational Logic

A truth assignment satisfies a sentence with free variables if and only if it satisfies every instance of that sentence. (In other words, we can think of all free variables as being universally quantified.)

(∃y.q(x,y))i = (∀x.∃y.q(x,y))i

A truth assignment satisfies a set of sentences if and only if it satisfies every sentence in the set.

Open Sentences

Page 35: Introduction to Logic Relational Logic

Example - Friends

Page 36: Introduction to Logic Relational Logic

Friends

Page 37: Introduction to Logic Relational Logic

One Possible State

Page 38: Introduction to Logic Relational Logic

Another Possible State

Page 39: Introduction to Logic Relational Logic

Possible States

2^16 (65,536) possible worlds.

Page 40: Introduction to Logic Relational Logic

Actual State

Page 41: Introduction to Logic Relational Logic

Object Constants: abby, bess, cody, dana

Binary Relation Constant: likes

Herbrand base has 16 ground relational sentences.

Signature

Page 42: Introduction to Logic Relational Logic

likes(abby,abby) likes(bess,abby) likes(abby,bess likes(bess,bess) likes(abby,cody) likes(bess,cody) likes(abby,dana) likes(bess,dana)

likes(cody,abby) likes(dana,abby) likes(cody,bess) likes(dana,bess) likes(cody,cody) likes(dana,cody) likes(cody,dana) likes(dana,dana)

Herbrand Base

Page 43: Introduction to Logic Relational Logic

Sorority World

Page 44: Introduction to Logic Relational Logic

likes(abby,abby) = 0 likes(bess,abby) = 0 likes(abby,bess) = 0 likes(bess,bess) = 0 likes(abby,cody) = 1 likes(bess,cody) = 1 likes(abby,dana) = 0 likes(bess,dana) = 0

likes(cody,abby) = 1 likes(dana,abby) = 0 likes(cody,bess) = 1 likes(dana,bess) = 0 likes(cody,cody) = 0 likes(dana,cody) = 1 likes(cody,dana) = 1 likes(dana,dana) = 0

Herbrand Base

Page 45: Introduction to Logic Relational Logic

Abby likes everyone Bess likes.

Sentences

Page 46: Introduction to Logic Relational Logic

Abby likes everyone Bess likes.If Bess likes someone, then Abby also likes her.

∀y.(likes(bess,y) ⇒ likes(abby,y))

Sentences

Page 47: Introduction to Logic Relational Logic

Abby likes everyone Bess likes.If Bess likes someone, then Abby also likes her.

∀y.(likes(bess,y) ⇒ likes(abby,y))

Cody likes everyone who likes her.

Sentences

Page 48: Introduction to Logic Relational Logic

Abby likes everyone Bess likes.If Bess likes someone, then Abby also likes her.

∀y.(likes(bess,y) ⇒ likes(abby,y))

Cody likes everyone who likes her.If someone likes Cody, then Cody likes that person.

∀x.(likes(x,cody) ⇒ likes(cody,x))

Sentences

Page 49: Introduction to Logic Relational Logic

Cody likes somebody who likes her.

Sentences

Page 50: Introduction to Logic Relational Logic

Cody likes somebody who likes her.There is someone who likes cody and is liked by Cody.

∃y.(likes(cody,y) ∧ likes(y,cody))

Sentences

Page 51: Introduction to Logic Relational Logic

Cody likes somebody who likes her.There is someone who likes cody and is liked by Cody.

∃y.(likes(cody,y) ∧ likes(y,cody))

Nobody likes herself.

Sentences

Page 52: Introduction to Logic Relational Logic

Cody likes somebody who likes her.There is someone who likes cody and is liked by Cody.

∃y.(likes(cody,y) ∧ likes(y,cody))

Nobody likes herself.It is not the case that there is someone who likes herself.

¬∃x.likes(x,x)

Sentences

Page 53: Introduction to Logic Relational Logic

Everybody likes somebody.

∀x.∃y.likes(x,y)

There is somebody whom everybody likes.

∃y.∀x.likes(x,y)

Sentences

Page 54: Introduction to Logic Relational Logic

Abby Bess

Cody Dana

Example

∀x.∃y.likes(x,y)

Page 55: Introduction to Logic Relational Logic

∀x.∃y.likes(x,y)

Abby Bess

Cody Dana

Everybody Likes Somebody

Page 56: Introduction to Logic Relational Logic

∀x.∃y.likes(x,y)

Abby Bess

Cody Dana

Everybody Likes Somebody

Page 57: Introduction to Logic Relational Logic

∀x.∃y.likes(x,y)

Abby Bess

Cody Dana

Everybody Likes Somebody

Page 58: Introduction to Logic Relational Logic

∀x.∃y.likes(x,y)

Abby Bess

Cody Dana

Everybody Likes Somebody

Page 59: Introduction to Logic Relational Logic

∀x.∃y.likes(x,y)

Abby Bess

Cody Dana

Everybody Likes Somebody

Page 60: Introduction to Logic Relational Logic

Abby Bess

Cody Dana

∃y.∀x.likes(x,y)

There is Somebody Whom Everyone Likes

Page 61: Introduction to Logic Relational Logic

Example - Blocks World

Page 62: Introduction to Logic Relational Logic

Blocks World

Page 63: Introduction to Logic Relational Logic

Object Constants: a, b, c, d, e

Unary Relation Constants: clear - blocks with no blocks on top. table - blocks on the table.

Binary Relation Constants: on - pairs of blocks in which first is on the second. above - pairs in which first block is above the second.

Ternary Relation Constant: stack - triples of blocks arranged in a stack.

Signature

Page 64: Introduction to Logic Relational Logic

¬on(a,a) ¬on(b,a) ¬on(c,a) on(a,b) ¬on(b,b) ¬on(c,b)¬on(a,c) on(b,c) ¬on(c,c)¬on(a,d) ¬on(b,d) ¬on(c,d)¬on(a,e) ¬on(b,e) ¬on(c,e)

¬on(d,a) ¬on(e,a) ¬on(d,b) ¬on(e,b) ¬on(d,c) ¬on(e,c) ¬on(d,d) ¬on(e,d) on(d,e) ¬on(e,e)

Data

Page 65: Introduction to Logic Relational Logic

Definition of clear:

∀y.(clear(y) ⇔ ¬∃x.on(x,y))

Definition of table:

∀x.(table(x) ⇔ ¬∃y.on(x,y))

Definitions

Page 66: Introduction to Logic Relational Logic

Definition of stack:

∀x.∀y.∀z.(stack(x,y,z) ⇔ on(x,y) ∧ on(y,z))

Definition of above:

∀x.∀z.(above(x,z) ⇔ on(x,z) ∨ ∃y.(on(x,y) ∧ above(y,z)))

∀x.¬above(x,x)

Definitions

Page 67: Introduction to Logic Relational Logic

Example - Modular Arithmetic

Page 68: Introduction to Logic Relational Logic

In Modular Arithmetic of modulus 4 there are just 4 numbers (0,1, 2, 3).

0+0=0 1+0=1 2+0=2 3+0=30+1=1 1+1=2 2+1=3 3+1=00+2=2 1+2=3 2+2=0 3+2=10+3=3 1+3=0 2+3=1 3+3=2

Modular Arithmetic

Page 69: Introduction to Logic Relational Logic

Object Constants: 0, 1, 2, 3

Binary Relation Constants: same - the first and second arguments are identical next - the second argument is number after the first

Ternary Relation Constant: plus - the third argument is the sum of the first two

plus(1,2,3)

Signature

Page 70: Introduction to Logic Relational Logic

Ground Relational Data:

same(0,0) ¬same(1,0) ¬same(2,0) ¬same(3,0)¬same(0,1) same(1,1) ¬same(2,1) ¬same(3,1)¬same(0,2) ¬same(1,2) same(2,2) ¬same(3,2)¬same(0,3) ¬same(1,3) ¬same(2,3) same(3,3)

Same

Page 71: Introduction to Logic Relational Logic

Ground Relational Data:

¬next(0,0) ¬next(1,0) ¬next(2,0) next(3,0) next(0,1) ¬next(1,1) ¬next(2,1) ¬next(3,1)¬next(0,2) next(1,2) ¬next(2,2) ¬next(3,2)¬next(0,3) ¬next(1,3) next(2,3) ¬next(3,3)

Next

Page 72: Introduction to Logic Relational Logic

Ground Relational Data:

next(0,1)next(1,2)next(2,3)next(3,0)

Deal with negative literals by saying that all other cases are false. How do we do this?

Next

Page 73: Introduction to Logic Relational Logic

For every x, there is just one y such that next(x,y):

∀x.∀y.∀z.(next(x,y) ∧ next(x,z) ⇒ same(y,z))

Logically equivalent version:

∀x.∀y.∀z.(next(x,y) ∧ ¬same(y,z) ⇒ ¬next(x,z))

Functionality Axiom

Page 74: Introduction to Logic Relational Logic

Ground Relational Data:

plus(0,0,0) plus(1,0,1) plus(2,0,2) plus(3,0,3)plus(0,1,1) plus(1,1,2) plus(2,1,3) plus(3,1,0)plus(0,2,2) plus(1,2,3) plus(2,2,0) plus(3,2,1)plus(0,3,3) plus(1,3,0) plus(2,3,1) plus(3,3,2)

Functionality Axiom:

∀x.∀y.∀z.∀w.(plus(x,y,z) ∧ plus(x,y,w) ⇒ same(z,w))∀x.∀y.∀z.∀w.(plus(x,y,z) ∧ ¬same(z,w) ⇒ ¬plus(x,y,w))

Addition

Page 75: Introduction to Logic Relational Logic

Identity:

∀y.plus(0,y,y)

Successor:

∀x.∀y.∀z.(plus(x,y,z) ∧ next(x,x2) ∧ next(z,z2) ⇒ plus(x2,y,z2))

Functionality:

∀x.∀y.∀z.∀w.(plus(x,y,z) ∧ ¬same(z,w) ⇒ ¬plus(x,y,w))

Alternative Definition of Addition

Page 76: Introduction to Logic Relational Logic

Identity:

∀y.plus(0,y,y)y+0=y

Successor:

∀x.∀y.∀z.(plus(x,y,z) ∧ next(x,x2) ∧ next(z,z2) ⇒ plus(x2,y,z2)) x+y=z ⇒ (x+1)+y=z+1

Functionality:

∀x.∀y.∀z.∀w.(plus(x,y,z) ∧ plus(x,y,w) ⇒ same(z,w))x+y=z ∧ x+y=w ⇒ z=w

Alternative Definition of Addition

Page 77: Introduction to Logic Relational Logic

Example - Minefinder

Page 78: Introduction to Logic Relational Logic

http://intrologic.stanford.edu

Course Website

Page 79: Introduction to Logic Relational Logic
Page 80: Introduction to Logic Relational Logic