1 Using Views to Implement Datalog Programs Inverse Rules Duschka’s Algorithm.

Slides:



Advertisements
Similar presentations
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.
Advertisements

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.
Inference Rules Universal Instantiation Existential Generalization
CSE 636 Data Integration Conjunctive Queries Containment Mappings / Canonical Databases Slides by Jeffrey D. Ullman.
1 Extended Conjunctive Queries Unions Arithmetic Negation.
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Standard Logical Equivalences
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.
First Order Logic Resolution
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
For Friday No reading Homework: –Chapter 9, exercise 4 (This is VERY short – do it while you’re running your tests) Make sure you keep variables and constants.
F22H1 Logic and Proof Week 7 Clausal Form and Resolution.
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
Prolog IV Logic, condensed. 2 Propositional logic Propositional logic consists of: The logical values true and false ( T and F ) Propositions: “Sentences,”
1 A Scalable Algorithm for Answering Queries Using Views Rachel Pottinger Qualifying Exam October 29, 1999 Advisor: Alon Levy.
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.
Normal Forms for CFG’s Eliminating Useless Variables Removing Epsilon
Inference and Resolution for Problem Solving
2005certain1 Views as Incomplete Databases – Certain & Possible Answers  Views – an incomplete representation  Certain and possible answers  Complexity.
CSE 636 Data Integration Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman.
Local-as-View Mediators Priya Gangaraju(Class Id:203)
1 Datalog Logical Rules Recursion SQL-99 Recursion.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
1 Datalog Rules Programs Negation. 2 Review of Logical If-Then Rules h(X,…) :- a(Y,…) & b(Z,…) & … head body subgoals “The head is true if all the subgoals.
1 Semantics of Datalog With Negation Local Stratification Stable Models Well-Founded Models.
2005lav-iii1 The Infomaster system & the inverse rules algorithm  The InfoMaster system  The inverse rules algorithm  A side trip – equivalence & containment.
CSE (c) S. Tanimoto, 2005 Logic Programming 1 Logic Programming Outline: Motivation Examples: The Grandmother relation Formulation in Prolog Logic,
Copyright © Cengage Learning. All rights reserved.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
Introduction Even though the syntax of Scheme is simple, it can be very difficult to determine the semantics of an expression. Hacker’s approach: Run it.
1 Searching for Solutions Careful Analysis of Expansions The Bucket Algorithm.
Logical Rules Recursion
1 Datalog Logical Rules Recursion. 2 Logic As a Query Language uIf-then logical rules have been used in many systems. wMost important today: EII (Enterprise.
Credit: Slides are an adaptation of slides from Jeffrey D. Ullman 1.
Properties of Context-Free Languages
Introduction to Logic for Artificial Intelligence Lecture 2 Erik Sandewall 2010.
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Inference in First-Order logic Department of Computer Science & Engineering Indian Institute of Technology Kharagpur.
Conjunctive normal form: any formula of the predicate calculus can be transformed into a conjunctive normal form. Def. A formula is said to be in conjunctive.
1 Chapter 8 Inference and Resolution for Problem Solving.
First Order Predicate Logic
CSE S. Tanimoto Horn Clauses and Unification 1 Horn Clauses and Unification Propositional Logic Clauses Resolution Predicate Logic Horn Clauses.
Datalog Inspired by the impedance mismatch in relational databases. Main expressive advantage: recursive queries. More convenient for analysis: papers.
Chapter 1, Part II: Predicate Logic With Question/Answer Animations.
CSE 636 Data Integration Conjunctive Queries Containment Mappings / Canonical Databases Slides by Jeffrey D. Ullman Fall 2006.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
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,
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Automated Reasoning Early AI explored how to automate several reasoning tasks – these were solved by what we might call weak problem solving methods as.
CSE (c) S. Tanimoto, 2008 Predicate Calculus II 1 Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability.
1 Reasoning with Infinite stable models Piero A. Bonatti presented by Axel Polleres (IJCAI 2001,
1 Datalog with negation Adapted from slides by Jeff Ullman.
Introduction to Logic for Artificial Intelligence Lecture 2
Datalog Rules / Programs / Negation Slides by Jeffrey D. Ullman
CSE 341, S. Tanimoto Logic Programming -
Answering Queries using Templates with Binding Patterns
Horn Clauses and Unification
Containment Mappings Canonical Databases Sariaya’s Algorithm
Semantics of Datalog With Negation
Horn Clauses and Unification
Prolog IV Logic, condensed.
Horn Clauses and Unification
Horn Clauses and Unification
Local-as-View Mediators
Logic Based Query Languages
Horn Clauses and Unification
Datalog Inspired by the impedance mismatch in relational databases.
Copyright © Cengage Learning. All rights reserved.
CS589 Principles of DB Systems Fall 2008 Lecture 4b: Domain Independence and Safety Lois Delcambre
Presentation transcript:

1 Using Views to Implement Datalog Programs Inverse Rules Duschka’s Algorithm

2 Inverting Rules uIdea: “invert” the view definitions to give the global predicates definitions in terms of views and function symbols. uPlug the globals’ definitions into the body of the query to get a direct expansion of the query into views. uEven works when the query is a program.

3 Inverting Rules --- (2) uBut the query may have function symbols in its solution, and these symbols actually have no meaning. uWe therefore need to get rid of them. uTrick comes from Huyn -> Qian -> Duschka.

4 Skolem Functions uLogical trick for getting rid of existentially quantified variables. uIn terms of safe Datalog rules: wFor each local (nondistinguished) variable X, pick a new function symbol f (the Skolem constant). wReplace X by f (head variables).

5 Example v(X,Y) :- p(X,Z) & p(Z,Y)  Replace Z by f(X,Y) to get: v(X,Y) :- p(X,f(X,Y)) & p(f(X,Y),Y) uIntuition: for v(X,Y) to be true, there must be some value, depending on X and Y, that makes the above body true.

6 HQD Rule Inversion uReplace a Skolemized view definition by rules with: 1.A subgoal as the head, and 2.The view itself as the only subgoal of the body.

7 Example v(X,Y) :- p(X,f(X,Y)) & p(f(X,Y),Y) becomes: p(X,f(X,Y)) :- v(X,Y) p(f(X,Y),Y) :- v(X,Y)

8 Running Example: Maternal Ancestors uGlobal predicates: wm(X,Y) = “Y is the mother of X.” wf(X,Y) = “Y is the father of X.” umanc rules: r1: manc(X,Y) :- m(X,Y) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y)

9 Example --- Continued uThe views: v1(X,Y) :- f(X,Z) & m(Z,Y) v2(X,Y) :- m(X,Y) uInverse rules: r4: f(X,g(X,Y)) :- v1(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y)

10 Evaluating the Rules uTreat views as EDB. uApply seminaïve evaluation to query (Datalog program). uIn general, function symbols -> no convergence.

11 Evaluating the Rules uBut here, all function symbols are in the heads of global predicates. uThese are like EDB as far as the query is concerned, so no nested function symbols occur. uOne level of function symbols assures convergence.

12 Example r1: manc(X,Y) :- m(X,Y) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(X,g(X,Y)) :- v1(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) uAssume v1(a,b).

13 Example --- (2) r1: manc(X,Y) :- m(X,Y) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(a,g(a,b)) :- v1(a,b) r5: m(g(a,b),b) :- v1(a,b) r6: m(X,Y) :- v2(X,Y) uAssume v1(a,b).

14 Example --- (3) r1: manc(g(a,b),b) :- m(g(a,b),b) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(a,g(a,b)) :- v1(a,b) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) uAssume v1(a,b).

15 Example --- (4) r1: manc(X,Y) :- m(X,Y) r2: manc(a,b) :- f(a,g(a,b)) & manc(g(a,b),b) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(X,g(X,Y)) :- v1(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) uAssume v1(a,b).

16 Example --- Concluded uNotice that given v1(a,b), we were able to infer manc(a,b), even though we never found out what the value of g(a,b) [the father of a ] is.

17 Rule-Rewriting uDuschka’s approach moves the function symbols out of the seminaïve evaluation and into a rule-rewriting step. uIn effect, the function symbols combine with the predicates. wPossible only because there are never any nested function symbols.

18 Necessary Technique: Unification uWe unify two atoms by finding the simplest substitution for the variables that makes them identical. uLinear-time algorithm known.

19 Example uThe unification of p(f(X,Y), Z) and p(A,g(B,C)) is p(f(X,Y),g(B,C)). uUses A -> f(X,Y); Z -> g(B,C); identity mapping on other variables. up(X,X) and p(Y,f(Y)) have no unification. uNeither do p(X) and q(X).

20 Elimination of Function Symbols uRepeat: 1.Take any rule with function symbol(s) in the head. 2.Unify that head with any subgoals, of any rule, with which it unifies. uBut first make head variables be new,unique symbols. uFinally, replace IDB predicates + function-symbol patterns by new predicates.

21 Example r1: manc(X,Y) :- m(X,Y) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(X,g(X,Y)) :- v1(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) Unify

22 Example --- (2) r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r4: f(A,g(B,C)) :- r7: manc(X,Y) :- f(X,g(B,C)) & manc(g(B,C),Y) Important point: in the unification of X and A, any variable could be used, but it must appear in both these places.

23 Example --- (3) r1: manc(X,Y) :- m(X,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r5: m(g(A,B),C) :- r8: manc(g(A,B),Y) :- m(g(A,B),Y) r9 :manc(g(A,B),Y) :- m(g(A,B),Z) & manc(Z,Y)

24 Example --- (4)  Now we have a new pattern: manc(g(A,B),C).  We must unify it with manc subgoals in r2, r3, r7, and r9. ur2 and r7 yield nothing new, but r3 and r9 do.

25 Example --- (5) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r9 :manc(g(A,B),Y) :- m(g(A,B),Z) & manc(Z,Y) manc(g(C,D),E) r10: manc(X,Y) :- m(X,g(A,B)) & manc(g(A,B),Y) r11: manc(g(A,B),Y) :- m(g(A,B),g(C,D)) & manc(g(C,D),Y)

26 Cleaning Up the Rules 1.For each IDB predicate ( manc in our example) introduce a new predicate for each function-symbol pattern. 2.Replace EDB predicates (m and f in our example) by their definition in terms of views, but only if no function symbols are introduced.

27 Justification for (2) uA function symbol in a view is useless, since the source (stored) data has no tuples with function symbols. uA function symbol in an IDB predicate has already been taken care of by expanding the rules using all function- symbol patterns we can construct.

28 New IDB Predicates  In our example, we only need manc1 to represent the pattern manc(g(.,.),.).  That is: manc1(X,Y,Z) = manc(g(X,Y),Z).

29 Example --- r1 r1: manc(X,Y) :- m(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) Substitution OK; yields manc(X,Y) :- v2(X,Y) Illegal --- yields g in head. Note the case manc(g(.,.),.) is taken care of by r8.

30 Example --- r2 and r3 r2: manc(X,Y) :- f(X,Z) & manc(Z,Y) r3: manc(X,Y) :- m(X,Z) & manc(Z,Y) r4: f(X,g(X,Y)) :- v1(X,Y) r5: m(g(X,Y),Y) :- v1(X,Y) r6: m(X,Y) :- v2(X,Y) Illegal --- put function symbol g in manc. OK; yields manc(X,Y) :- v2(X,Z) & manc(Z,Y)

31 Example --- r4, r5, r6 uThe inverse rules have played their role and do not appear in the final rules.

32 Example --- r7 r7: manc(X,Y) :- f(X,g(B,C)) & manc(g(B,C),Y) r4: f(X,g(X,Y)) :- v1(X,Y) Replace by manc1(B,C,Y). Unify. Note no function symbols are introduced, but X =B. r7: manc(X,Y) :- v1(X,C) & manc1(X,C,Y)

33 Example --- r8 and r9 r8: manc(g(A,B),Y) :- m(g(A,B),Y) r9 :manc(g(A,B),Y) :- m(g(A,B),Z) & manc(Z,Y) r5: m(g(X,Y),Y) :- v1(X,Y) Become manc1(A,B,Y) Unify; set B =Y. Unify; set B =Z. r8: manc1(A,Y,Y) :- v1(A,Y) r9 :manc1(A,Z,Y) :- v1(A,Z)& manc(Z,Y)

34 Example --- r10 and r11 uNo substitutions possible --- unifying m –subgoal with head of r5 or r6 introduces a function symbol into the view subgoal.

35 Summary of Rules r1: manc(X,Y) :- v2(X,Y) r3: manc(X,Y) :- v2(X,Z) & manc(Z,Y) r7: manc(X,Y) :- v1(X,C) & manc1(X,C,Y) r8: manc1(A,Y,Y) :- v1(A,Y) r9 :manc1(A,Z,Y) :- v1(A,Z)& manc(Z,Y)

36 Finishing Touch: Replace manc1 Substitute the bodies of r8 and r9 for the manc1 subgoal of r7. r7: manc(X,Y) :- v1(X,C) & manc1(X,C,Y) r8: manc1(A,Y,Y) :- v1(A,Y) r9 :manc1(A,Z,Y) :- v1(A,Z)& manc(Z,Y) Becomes another v1(X,C). Becomes v1(X,C) & manc(C,Y)

37 Final Rules r1: manc(X,Y) :- v2(X,Y) r3: manc(X,Y) :- v2(X,Z) & manc(Z,Y) r7-8: manc(X,Y) :- v1(X,Y) r7-9 : manc(X,Y) :- v1(X,C) & manc(C,Y)