Deductive Database. Relation Database TitleYearLengthType Harry Porter2001180Color Gone with the wind1938125Black and White Snow White195090Color.

Slides:



Advertisements
Similar presentations
Applications Computational LogicLecture 11 Michael Genesereth Spring 2004.
Advertisements

1 Datalog: Logic Instead of Algebra. 2 Datalog: Logic instead of Algebra Each relational-algebra operator can be mimicked by one or several Database Logic.
First Order Logic Logic is a mathematical attempt to formalize the way we think. First-order predicate calculus was created in an attempt to mechanize.
Relational Calculus and Datalog
Lecture 11: Datalog Tuesday, February 6, Outline Datalog syntax Examples Semantics: –Minimal model –Least fixpoint –They are equivalent Naive evaluation.
1. An Overview of Prolog.
1 Conjunctions of Queries. 2 Conjunctive Queries A conjunctive query is a single Datalog rule with only non-negated atoms in the body. (Note: No negated.
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
1 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke Deductive Databases Chapter 25.
1 Relational Algebra & Calculus. 2 Relational Query Languages  Query languages: Allow manipulation and retrieval of data from a database.  Relational.
Efficient Query Evaluation on Probabilistic Databases
Chapter 12 - Logic Programming
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Winter 2002Arthur Keller – CS 18014–1 Schedule Today: Feb. 26 (T) u Datalog. u Read Sections Assignment 6 due. Feb. 28 (TH) u Datalog and SQL.
CS240A: Databases and Knowledge Bases Fixpoint Semantics of Datalog Carlo Zaniolo Department of Computer Science University of California, Los Angeles.
CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Using Definite Knowledge Notes for Ch.3 of Poole et al. CSCE 580 Marco Valtorta.
Embedded SQL Direct SQL is rarely used: usually, SQL is embedded in some application code. We need some method to reference SQL statements. But: there.
1 Relational Algebra and Calculus Yanlei Diao UMass Amherst Feb 1, 2007 Slides Courtesy of R. Ramakrishnan and J. Gehrke.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
Discussion #24 1/17 Discussion #24 Deductive Databases.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
Deductive Databases Chapter 25
Rutgers University Relational Calculus 198:541 Rutgers University.
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 11 Introduction to Predicate Logic Limitations of Propositional Logic Predicates, quantifiers and propositions.
Database Systems Logical Query Languages assoc. prof., dr. Vladimir Dimitrov web: is.fmi.uni-sofia.bg.
Chapter 1: The Foundations: Logic and Proofs
DEDUCTIVE DATABASE.
The Relational Model: Relational Calculus
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Calculus Chapter 4, Section 4.3.
(CSC 102) Lecture 7 Discrete Structures. Previous Lectures Summary Predicates Set Notation Universal and Existential Statement Translating between formal.
Logical Query Languages Motivation: 1.Logical rules extend more naturally to recursive queries than does relational algebra. u Used in SQL recursion. 2.Logical.
Datalog Inspired by the impedance mismatch in relational databases. Main expressive advantage: recursive queries. More convenient for analysis: papers.
CSE 636 Data Integration Conjunctive Queries Containment Mappings / Canonical Databases Slides by Jeffrey D. Ullman Fall 2006.
1 Relational Algebra and Calculas Chapter 4, Part A.
INFORMATION INTEGRATION Shengyu Li CS-257 ID-211.
Datalog –Another query language –cleaner – closer to a “logic” notation, prolog – more convenient for analysis – can express queries that are not expressible.
Chapter 5 Notes. P. 189: Sets, Bags, and Lists To understand the distinction between sets, bags, and lists, remember that a set has unordered elements,
(CSC 102) Lecture 8 Discrete Structures. Previous Lectures Summary Predicates Set Notation Universal and Existential Statement Translating between formal.
LDK R Logics for Data and Knowledge Representation Propositional Logic: Reasoning First version by Alessandro Agostini and Fausto Giunchiglia Second version.
First-Order Logic and Inductive Logic Programming.
KR A Principled Framework for Modular Web Rule Bases and its Semantics Anastasia Analyti Institute of Computer Science, FORTH-ICS, Greece Grigoris.
Lu Chaojun, SJTU 1 Extended Relational Algebra. Bag Semantics A relation (in SQL, at least) is really a bag (or multiset). –It may contain the same tuple.
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 27 A First Course in Database Systems.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
Datalog Another formalism for expressing queries: - cleaner - closer to a “logic” notation - more convenient for analysis - equivalent in power to relational.
ICS 321 Fall 2011 Algebraic and Logical Query Languages (ii) Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at.
Database Management Systems, R. Ramakrishnan1 Relational Calculus Chapter 4, Part B.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
1 Section 7.1 First-Order Predicate Calculus Predicate calculus studies the internal structure of sentences where subjects are applied to predicates existentially.
Extensions of Datalog Wednesday, February 13, 2001.
1 Datalog with negation Adapted from slides by Jeff Ullman.
CS589 Principles of DB Systems Fall 2008 Lecture 4c: Query Language Equivalence Lois Delcambre
CS589 Principles of DB Systems Spring 2014 Unit 2: Recursive Query Processing Lecture 2-1 – Naïve algorithm for recursive queries Lois Delcambre (slides.
Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman
Recursive stack-based version of Back-chaining using Propositional Logic
Goal for this lecture Demonstrate how we can prove that one query language is more expressive than (i.e., “contained in” as described in the book) another.
First-Order Logic and Inductive Logic Programming
Semantics of Datalog With Negation
Chapter 2: Intro to Relational Model
Logic Based Query Languages
Chapter 2: Intro to Relational Model
Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2: Intro to Relational Model
Datalog Inspired by the impedance mismatch in relational databases.
This Lecture Substitution model
Relational Calculus Chapter 4, Part B 7/1/2019.
Representations & Reasoning Systems (RRS) (2.2)
Presentation transcript:

Deductive Database

Relation Database TitleYearLengthType Harry Porter Color Gone with the wind Black and White Snow White195090Color

A different view: a set of atoms movie(“Harry Porter”, 2001, 180, “Color”) movie(“Gone with the wind”, 1938, 125, “Black and White”) movie(“Snow White”, 1950, 90, “Color”) Predicate name Parameters – order is important

Predicates & Atoms Predicate – relation (associated with a fixed number of arguments) Atoms – predicates followed by a list of arguments (arguments can be variables or constants) –grounded if all arguments are constants, e.g., movie(“Harry Porter”, 2001, 180, “Color”) –non-grounded if some arguments are variables, e.g., movie(X, Y, 180, “Color”)

Atoms & Rows movie(“Harry Porter”, 2001, 180, “Color”) movie(“Gone with the wind”, 1938, 125, “Black and White”) movie(“Snow White”, 1950, 90, “Color”) Each relation instance can be represented by a set of grounded atoms Each row corresponds to an atom. An atom is true if it corresponds to a row in the table; it is false if it does not correspond to any row in the table. Predicate name Parameters – order is important

Why Deductive Database? Declarative: clear understanding of what a database represents Expressiveness: there are queries that cannot be formulated using relational algebra can be easily expressed by datalog rules

Datalog Rule a :- a1, …, an, not b1, …, not bm where a, a1,..,an,b1,…,bm are atoms and not is the negation-as-failure operator (n, m can be 0). A program (or query, knowledge base) is a set of rules

Rule - Meaning Rule a :- a1, …, an, not b1, …, not bm says the following: “If a1,…,an are true and b1,…,bm can be assumed to be false then a must be true.” If n=0 and m=0, then a must be true (fact). If m=0, the rule is a definite rule.

Rule – Examples colorMovie(M) :- movie(M,X,Y,Z), Z = “Color”. longMovie(M):- movie(M,X,Y,Z), Y>120. oldMovie(M):- movie(M,X,Y,Z), X<1940. movieWithSequel(M):- movie(M,X1,Y1,Z1), movie(M,X2,Y2,Z2), X1 <> X2.

Rule – Do-not-care variables colorMovie(M) :- movie(M,_,_,Z), Z = “Color”. longMovie(M):- movie(M,_,Y,_), Y>120. oldMovie(M):- movie(M,X,_,_), X<1940. movieWithSequel(M):- movie(M,X1,_,_), movie(M,X2,_,_), X1 <> X2.

Rule – Negation as failure noColorMovie(M) :- movie(M,_,_,Z), not Z = “Color”. notYetProducedMovie(M) :- not movie(M,X,Y,Z). NOTE: should be careful when using ‘not’; the second rule is not a good one (unsafe). It can say that any movie is not yet produced !

Deductive Database & Relational Algebra Projection colorMovie(M) :- movie(M,_,_,Z), Z = “Color”. Selection oldMovie(M,X,Y,Z):- movie(M,X,Y,Z),X<1940. Join (two relations p(A,B), q(B,C)) r(X,Y,Z):- p(X,Y), q(Y,Z) Union (two relations p(A,B), q(A,B)) r(X,Y):- p(X,Y). r(X,Y):- q(X,Y). Set difference (two relations p(A,B), q(A,B)) r(X,Y):- p(X,Y), not q(X,Y). Cartesian product (two relations p(A,B), q(C,D)) c(X,Y,Z,W):- p(X,Y), q(Z,W).

Programs – Examples Given the following program q(1,2). q(1,3). r(2,3). r(3,1). p(X,Y ):- q(X,Z), r(Z,Y ), not q(X,Y ). q, r are “extensional predicates” p is “intensional predicate” Stored in Tables Computed from the programs Question: what are the atoms of the predicate p which are defined by the program?

Programs – Examples q(1,2). q(1,3). r(2,3). r(3,1). p(X,Y ):- q(X,Z), r(Z,Y ), not q(X,Y ). p(1,3):- q(1,2),r(2,3), not q(1,3). NO p(1,3):- q(1,3),r(3,1), not q(1,1). YES …. X, Y can be 1, 2, or 3

The meaning of a program For a program P, what are the extensional atoms defined by P? It is simple for the case where rules defining the extensional predicate is non- recursive (previous example!)

Recursive Datalog Given: Mother-Child relation mother(Ana, Deborah) mother(Deborah, Nina) mother(Nina, Anita) Define: grand-mother relation? grandma(X,Y):- mother(X,Z),mother(Z,Y).

Recursive Datalog Given: Mother-Child relation mother(Ana, Deborah) mother(Deborah, Nina) mother(Nina, Anita) Define: grand-mother relation? grandma(X,Y):- mother(X,Z),mother(Z,Y). Answer: grandma(Deborah, Anita) and grandma(Ana,Nina) Question: relational algebra expression for grandma? POSSIBLE?

Recursive Datalog Given: Mother-Child relation mother(Ana, Deborah) mother(Deborah, Nina) mother(Nina, Anita) Define: ancestor relation? ancestor(X,Y):- mother(X,Y). ancestor(X,Y):- mother(X,Z), ancestor(Z,Y). Answer: ? (mother, grandma, and great-grandma(Ana, Anita)) Question: relational algebra expression for ancestor? POSSIBLE?

Computing the intensional predicates in recursive Datalog ancestor =  Check if any rule satisfies: three rules – get –ancestor(Ana, Deborah) –ancestor(Deborah, Nina) –ancestor(Nina, Anita) Repeat the second steps until ancestor does not change: –ancestor(Ana, Nina) –ancestor(Deborah, Anita) –ancestor(Ana, Anita)

Program with Negation-as-failure Different situations: –There might be only one solution –There might be several solutions –There might be no solution

Recursive Program – Another Example Given a table of flight schedule of UA and AA AirlineFromToDepartureArrival UASFDEN AASFDEN UADENCHI UADENDAL AADALNY AADALCHI AACHINY UACHINY

reachable(X,Y) – Y can be reached from X flight(Airline,From,To,Departure,Arrival) reachable(X,Y) :- flight(A,X,Y,D,R). reachable(X,Z) :- flight(A,X,Y,D,R), reachable(Y,Z). Computing reachable – similar to ancestor

reachableUA(X,Y) – Y can be reached by UA from X reachableUA(X,Y) :- flight(ua,X,Y,D,R). reachableUA(X,Z) :- flight(ua,X,Y,D,R), reachableUA(Y,Z). Easy: only considers UA flights

reachableUA(X,Y) – Y can be reached by UA’s flight from X reachableUA(X,Y) :- flight(ua,X,Y,D,R). reachableUA(X,Z) :- flight(ua,X,Y,D,R), reachableUA(Y,Z). Easy: only considers UA flights

reachableUA(X,Y) & reachableAA(X,Y) reachableUA(X,Y) :- flight(ua,X,Y,D,R). reachableUA(X,Z) :- flight(ua,X,Y,D,R), reachableUA(Y,Z). reachableAA(X,Y) :- flight(aa,X,Y,D,R). reachableAA(X,Z) :- flight(aa,X,Y,D,R), reachableAA(Y,Z).

reachableOnlyAA(X,Y) reachableUA(X,Y) :- flight(ua,X,Y,D,R). reachableUA(X,Z) :- flight(ua,X,Y,D,R), reachableUA(Y,Z). reachableAA(X,Y) :- flight(aa,X,Y,D,R). reachableAA(X,Z) :- flight(aa,X,Y,D,R), reachableAA(Y,Z). reachableOnlyAA(X,Y):- reachableAA(X,Y), not reachableUA(X,Y). reachableOnlyAA(X,Y) – Unique set of atoms satisfying this properties

A different situation Suppose that the extensional predicate is r and r(0) is the only atom which is true Consider the program p(X) :- r(X), not q(X) q(X) :- r(X), not p(X) {p(0)} or {q(0)} could be used as ‘the answer’ for this program

Yet another situation Suppose that the extensional predicate is r and r(0) is the only atom which is true Consider the program r(X) :- not r(X) Is r(0) true or false? Is r(1) true or false?

Minimal Model of Positive Program Given a program P without negation-as-failure T P (X) = {a | a :- a1,…,an  P, {a1,…,an}  X} If P is a positive program, the sequence T P (  ), T P (T P (  )), … converges again a set of atoms, which is called the minimal model of P

T0 = T P (  ) = {mother(a, d), mother(d, n), mother(n, t)} T1 = T P (T P (  )) = T0  {ancestor(a, d), ancestor(d, n), ancestor(n, t)} T2 = T P (T P (T P (  ))) = T1  {ancestor(a, n), ancestor(d, n)} T3 = T P (T P (T P (T P (  )))) = T2  {ancestor(a, t)} mother(a, d). mother(d, n). mother(n, t) ancestor(X,Y):- mother(X,Y). ancestor(X,Y):- mother(X,Z), ancestor(Z,Y).

Stable Models Given a program P and a set of atoms S P S is a program obtained from S by –Removing all rules in P which contain some not a in the body and a  S –Removing all not a from the remaining rules S is a stable model of P if S is the minimal model of the program P S

Example Given the program P: p :- not q. q :- not p. S = {p} P S consists of a single rule p. The minimal model of P S is {p}. So, {p} is a stable model of P S = {q} P S consists of a single rule q. The minimal model of P S is {q}. So, {q} is a stable model of P

Example Given the program P: p :- not q. q. S = {q, p} P S consists of a single rule q. The minimal model of P S is {q}. So, {q, p} is not a stable model of P S = {q} P S consists of a single rule q. The minimal model of P S is {q}. So, {q} is a stable model of P

Example Given the program P: p :- not p. S = {p} P S is empty. The minimal model of P S is {}. So, {p} is not a stable model of P S = {} P S consists of a single rule p. The minimal model of P S is {p}. So, {} is not a stable model of P

Entailment Given a program P and an atom p. Question: Is p true given P (or: P ╞═ p)? Answer –YES if p appears in every stable model of P – NO if p does not appear in at least on stable model of P There are systems for computing the stable models.