logic: datalog syntax and semantics - ubc computer sciencekevinlb/teaching/cs322 - 2006-7... ·...

26
Recap Datalog Syntax Datalog Semantics Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22 March 9, 2007 Textbook §5 Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 1

Upload: others

Post on 20-Mar-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Logic: Datalog Syntax and Semantics

CPSC 322 Lecture 22

March 9, 2007Textbook §5

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 1

Page 2: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Lecture Overview

1 Recap

2 Datalog Syntax

3 Datalog Semantics

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 2

Page 3: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Top-down definite clause interpreter

To solve the query ?q1 ∧ . . . ∧ qk:

ac := “yes← q1 ∧ . . . ∧ qk”repeat

select atom ai from the body of ac;choose clause C from KB with ai as head;replace ai in the body of ac by the body of C

until ac is an answer.

Don’t-care nondeterminism If one selection doesn’t lead to asolution, there is no point trying other alternatives. select

Don’t-know nondeterminism If one choice doesn’t lead to asolution, other choices may. choose

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 3

Page 4: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Representational Assumptions of Datalog

An agent’s knowledge can be usefully described in terms ofindividuals and relations among individuals.

An agent’s knowledge base consists of definite and positivestatements.

The environment is static.

There are only a finite number of individuals of interest in thedomain. Each individual can be given a unique name.

=⇒ Datalog

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 4

Page 5: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Domain for an RRS

in(alan,cs_building)

in(alan,r123).part_of(r123,cs_building).in(X,Y) ← part_of(Z,Y) ∧ in(X,Z).

alanr123r023

cs_buildingin( , )

part_of( , )person( )

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 5

Page 6: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Lecture Overview

1 Recap

2 Datalog Syntax

3 Datalog Semantics

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 6

Page 7: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Syntax of Datalog

Definition (variable)

A variable starts with upper-case letter.

Definition (constant)

A constant starts with lower-case letter or is a sequence of digits.

Definition (term)

A term is either a variable or a constant.

Definition (predicate symbol)

A predicate symbol starts with lower-case letter.

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 7

Page 8: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Syntax of Datalog (cont)

Definition (atom)

An atomic symbol (atom) is of the form p or p(t1, . . . , tn) where pis a predicate symbol and ti are terms.

Definition (definite clause)

A definite clause is either an atomic symbol (a fact) or of the form:

a︸︷︷︸ ← b1 ∧ · · · ∧ bm︸ ︷︷ ︸head body

where a and bi are atomic symbols.

Definition (knowledge base)

A knowledge base is a set of definite clauses.

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 8

Page 9: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Knowledge Base

in(alan, R)←teaches(alan, cs322) ∧in(cs322, R).

grandfather(william,X)←father(william, Y ) ∧parent(Y, X).

slithy(toves)←mimsy ∧ borogroves ∧outgrabe(mome, Raths).

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 9

Page 10: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Lecture Overview

1 Recap

2 Datalog Syntax

3 Datalog Semantics

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 10

Page 11: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Semantics: General Idea

Recall: a semantics specifies the meaning of sentences in thelanguage.

ultimately, we want to be able to talk about which sentencesare true and which are false

In propositional logic, all we needed to do in order to come upwith an interpretation was to assign truth values to atoms

For Datalog, an interpretation specifies:

what objects (individuals) are in the worldthe correspondence between symbols in the computer andobjects & relations in world

which constants denote which individualswhich predicate symbols denote which relations (and thus,along with the above, which sentences will be true and whichwill be false)

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 11

Page 12: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Formal Semantics

Definition (interpretation)

An interpretation is a triple I = 〈D,φ, π〉, where

D, the domain, is a nonempty set. Elements of D areindividuals.

φ is a mapping that assigns to each constant an element ofD. Constant c denotes individual φ(c).π is a mapping that assigns to each n-ary predicate symbol arelation: a function from Dn into {TRUE, FALSE}.

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 12

Page 13: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Interpretation

Constants: phone, pencil, telephone.Predicate Symbol: noisy (unary), left of (binary).

D = {",%,.}.These are actually objects in the world, not symbols

φ(phone) = %, φ(pencil) = ., φ(telephone) = %.

π(noisy): 〈"〉 FALSE 〈%〉 TRUE 〈.〉 FALSE

π(left of):〈","〉 FALSE 〈",%〉 TRUE 〈",.〉 TRUE

〈%,"〉 FALSE 〈%,%〉 FALSE 〈%,.〉 TRUE

〈.,"〉 FALSE 〈.,%〉 FALSE 〈.,.〉 FALSE

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 13

Page 14: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Important points to note

The domain D can contain real objects. (e.g., a person, aroom, a course). D can’t necessarily be stored in a computer.

The constants do not have to match up one-to-one withmembers of the domain. Multiple constants can refer to thesame object, and some objects can have no constants thatrefer to them.

π(p) specifies whether the relation denoted by the n-arypredicate symbol p is true or false for each n-tuple ofindividuals.

If predicate symbol p has no arguments, then π(p) is eitherTRUE or FALSE.

this was the situation in propositional logic

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 14

Page 15: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Truth in an interpretation

Definition (truth in an interpretation)

A constant c denotes in I the individual φ(c).Ground (variable-free) atom p(t1, . . . , tn) is

true in interpretation I if π(p)(t′1, . . . , t′n) = TRUE, where ti

denotes t′i in interpretation I andfalse in interpretation I if π(p)(t′1, . . . , t

′n) = FALSE.

Ground clause h← b1 ∧ . . . ∧ bm is

false in interpretation I if h is false in I and each bi is true inI, and item true in interpretation I otherwise.A knowledge base, KB, is true in interpretation I if and onlyif every clause in KB is true in I.

Notice that truth values are only associated with predicates(atomic symbols; clauses), not variables and constants!

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 15

Page 16: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone)

truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 17: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone)

truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 18: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil)

falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 19: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil)

trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 20: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone)

falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 21: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone)

truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 22: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil)

falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 23: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil)

true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 24: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Example Truths

In the interpretation given before:

noisy(phone) truenoisy(telephone) truenoisy(pencil) falseleft of(phone, pencil) trueleft of(phone, telephone) falsenoisy(pencil)← left of(phone, telephone) truenoisy(pencil)← left of(phone, pencil) falsenoisy(phone)← noisy(telephone) ∧ noisy(pencil) true

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 16

Page 25: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Variables

How do we determine the truth value of a clause that includesvariables?

Definition (variable assignment)

A variable assignment is a function from variables into the domain.

Given an interpretation and a variable assignment, each termdenotes an individual and each clause is either true or false.

A clause containing variables is true in an interpretation if it istrue for all variable assignments.

Variables are universally quantified in the scope of a clause.

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17

Page 26: Logic: Datalog Syntax and Semantics - UBC Computer Sciencekevinlb/teaching/cs322 - 2006-7... · 2018-09-26 · Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 17. Recap

Recap Datalog Syntax Datalog Semantics

Models and logical consequences

Definition (model)

A model of a set of clauses is an interpretation in which all theclauses are true.

Definition (logical consequence)

If KB is a set of clauses and g is a conjunction of atoms, g is alogical consequence of KB, written KB |= g, if g is true in everymodel of KB.

That is, KB |= g if there is no interpretation in which KB istrue and g is false.

Logic: Datalog Syntax and Semantics CPSC 322 Lecture 22, Slide 18