logic: datalog syntax and semantics

Upload: jeff-pratt

Post on 31-May-2018

242 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 Logic: Datalog Syntax and Semantics

    1/26

    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

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    2/26

    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

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    3/26

    Recap Datalog Syntax Datalog Semantics

    Top-down definite clause interpreter

    To solve the query ?q1 . . . qk:

    ac := yes q1 . . . qkrepeat

    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 Cuntil ac is an answer.

    Dont-care nondeterminism If one selection doesnt lead to asolution, there is no point trying other alternatives. select

    Dont-know nondeterminism If one choice doesnt lead to asolution, other choices may. choose

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

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    4/26

    Recap Datalog Syntax Datalog Semantics

    Representational Assumptions of Datalog

    An agents knowledge can be usefully described in terms ofindividuals and relations among individuals.

    An agents knowledge base consists ofdefinite 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

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    5/26

    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).

    alan

    r123

    r023

    cs_building

    in( , )part_of( , )

    person( )

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

    R D l S D l S i

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    6/26

    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

    R D t l S t D t l S ti

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    7/26

    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

    Recap Datalog S ntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    8/26

    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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    9/26

    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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    10/26

    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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    11/26

    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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    12/26

    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 a

    relation: a function from Dn into {TRUE, FALSE}.

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    13/26

    p g y g

    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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    14/26

    Important points to note

    The domain D can contain real objects. (e.g., a person, aroom, a course). D cant 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 the

    same 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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    15/26

    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)(t1

    , . . . , tn

    ) = TRUE, where tidenotes t

    iin interpretation I and

    false in interpretation I if (p)(t1, . . . , tn) = 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 only

    if 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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    16/26

    Example Truths

    In the interpretation given before:

    noisy(phone)

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    17/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone)

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    18/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

    noisy(pencil)

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    19/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

    noisy(pencil) falseleft of(phone, pencil)

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    20/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

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

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    21/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

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

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    22/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

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

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    23/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

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

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

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    24/26

    Example Truths

    In the interpretation given before:

    noisy(phone) truenoisy(telephone) true

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

    noisy(phone) noisy(telephone) noisy(pencil) true

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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    25/26

    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 is

    true 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

    Recap Datalog Syntax Datalog Semantics

    http://find/http://goback/
  • 8/14/2019 Logic: Datalog Syntax and Semantics

    26/26

    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

    http://find/http://goback/