Linear Tabling1 Tabled Prolog and Linear Tabling Neng-Fa Zhou (City Univ. of New York) Yi-Dong Shen (Chinese Academy of Sciences) Taisuke Sato (Tokyo Inst.

Slides:



Advertisements
Similar presentations
Recursion and the order of terms in a PROLOG clause.
Advertisements

AI/ES (Artificial Intelligence / Expert System) Visual Prolog: Part 2
Heuristic Search techniques
C O - INDUCTIVE LOGIC PROGRAMMING AND ITS APPLICATIONS.
Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
AI Pathfinding Representing the Search Space
Introduction to Recursion and Recursive Algorithms
SLD-resolution Introduction Most general unifiers SLD-resolution
Optimizing Compilers for Modern Architectures Allen and Kennedy, Chapter 13 Compiling Array Assignments.
1 Chapter 7: Controlling Search. 2 Controlling Search u Estimating Efficiency of a CLP Program u Rule Ordering u Literal Ordering u Adding Redundant Constraints.
Introduction to Prolog, cont’d Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
1 Overview Assignment 5: hints  Garbage collection Assignment 4: solution.
PROLOG Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages – It’s elegant, minimal, can.
Zhiguo Ge, Weng-Fai Wong, and Hock-Beng Lim Proceedings of the Design, Automation, and Test in Europe Conference, 2007 (DATE’07) April /4/17.
Search Strategies Reading: Russell’s Chapter 3 1.
Chapter 8: The Logical Paradigm Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
Mahgul Gulzai Moomal Umer Rabail Hafeez
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 23, 2009.
Query Execution Optimizing Performance. Resolving an SQL query Since our SQL queries are very high level, the query processor must do a lot of additional.
Programming with Constraints Jia-Huai You. Subject of Study Constraint Programming (CP) studies the computational models, languages, and systems for solving.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Controlling Backtracking Notes for Ch.5 of Bratko For CSCE 580 Sp03 Marco Valtorta.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
U NIVERSITY OF M ASSACHUSETTS, A MHERST D EPARTMENT OF C OMPUTER S CIENCE Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
CS 286, UC Berkeley, Spring 2007, R. Ramakrishnan 1 Evaluation of Recursive Queries Part 1: Efficient fixpoint evaluation “Seminaïve Evaluation”
By Neng-Fa Zhou1 PRISM: A Probabilistic Language for Modeling and Learning Joint work with Taisuke Sato (Tokyo Institute of Technology)
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Data Warehouse View Maintenance Presented By: Katrina Salamon For CS561.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Coursenotes CS3114: Data Structures and Algorithms Clifford A. Shaffer Yang Cao Department of Computer Science Virginia Tech Copyright ©
Query Processing Presented by Aung S. Win.
Sequence Control Chapter 6. 2 l Control structures: the basic framework within which operations and data are combined into programs. Sequence control.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Context Tailoring the DBMS –To support particular applications Beyond alphanumerical data Beyond retrieve + process –To support particular hardware New.
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
Recursion. Basic problem solving technique is to divide a problem into smaller subproblems These subproblems may also be divided into smaller subproblems.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
 2003, G.Tecuci, Learning Agents Laboratory 1 Learning Agents Laboratory Computer Science Department George Mason University Prof. Gheorghe Tecuci 5.
CS 415 – A.I. Slide Set 5. Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and.
 2007 Pearson Education, Inc. All rights reserved C Functions -Continue…-
Dynamic Programming Louis Siu What is Dynamic Programming (DP)? Not a single algorithm A technique for speeding up algorithms (making use of.
Data Structures R e c u r s i o n. Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain.
Java Programming: Guided Learning with Early Objects Chapter 11 Recursion.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
PROGRAMMING LANGUAGES: PROLOG, CLOJURE, F# Jared Wheeler.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 15 – Query Optimization.
Simplifying Dynamic Programming via Tabling Hai-Feng Guo University of Nebraska at Omaha, USA Gopal Gupta University of Texas at Dallas, USA.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Done By :- -Nesreen Basem -Sara nabil -Rawan Prolog Program.
Logic Programming Lecture 2: Unification and proof search.
Cs7120 (Prasad)L26-ProgTech1 Programming Techniques
Recursion Topic 5.
Virtual memory.
Data Flow Analysis Suman Jana
Database Management System
Efficient Tabling of Structured Data with Enhanced Hash-Consing
University Of Virginia
Resolving collisions: Open addressing
Data Flow Analysis Compiler Design
Problem Spaces & Search
Problem Spaces & Search
Mode-Directed Tabling for Dynamic Programming, Machine Learning, and Constraint Solving Neng-Fa Zhou (City Univ. of New York) Yoshitaka Kameya and Taisuke.
Chapter 2 A Survey of Simple Methods and Tools
Presentation transcript:

Linear Tabling1 Tabled Prolog and Linear Tabling Neng-Fa Zhou (City Univ. of New York) Yi-Dong Shen (Chinese Academy of Sciences) Taisuke Sato (Tokyo Inst. of Technology)

Linear Tabling2 Tabling is Useful 4 Eliminate infinite loops path(X,Y):-edge(X,Y). path(X,Y):-edge(X,Z),path(Z,Y). 4 Reduce redundant computations fib(0,1). fib(1,1). fib(N,F):-N>1, N1 is N-1,fib(N1,F1), N2 is N-2,fib(N2,F2), F is F1+F2.

Linear Tabling3 Tabling in OLDT (SLG-WAM) A... A’ producer consumer 4 suspend/resume –Complicate implementation freeze stacks overhead on standard programs garbage collection table A’ is suspended after the existing answers are exhausted

Linear Tabling4 A... A’ pioneer follower table A’ fails or becomes a producer after consuming existing answers A needs to be re-evaluated in some cases 4 Advantages –Easy to implement –Space efficient –Overhead-free 4 Disadvantage –Re-computation 4 Optimizations –Subgoal optimization –Semi-naïve evaluation

Linear Tabling5 The Linear Tabling Framework 4 Augmented programs p(X,Y):-p(X,Z),e(Z,Y),memo(p(X,Y)). p(X,Y):-e(X,Y),memo(p(X,Y)). p(X,Y):-check_completion(p(X,Y)). p(X,Y):-p(X,Z),e(Z,Y). p(X,Y):-e(X,Y).

Linear Tabling6 The Linear Tabling Framework (cont.) 4 table_start(A) –Executed when a tabled subgoal A is encountered 4 memo(A) –Executed when a clause succeeds 4 check_completion(A) –Executed after all clauses have been tried.

Linear Tabling7 Definitions  Loops, pioneers and followers A derivation G i  …  G j forms a loop if 1.G i =(A,…) and G j =(A’,…) 2.A and A’ are variants 3.A is an ancestor of A’ Subgoal A is called a pioneer and A’ is called a follower of A.

Linear Tabling8 Definitions (cont.) 4 Top-most looping nodes and subgoals A node in an SLD-tree is called a top-most looping node if the selected subgoal of the node is the pioneer of a loop that is not contained in any other loops.

Linear Tabling9 A Linear Tabling Method 4 table_start(A) –If A is complete, resolve A by using answers. –If A is a pioneer, register A and resolve A by using program clauses. –If A is a follower, resolve A by using answers and fail A after all existing answers are exhausted.

Linear Tabling10 A Linear Tabling Method (cont.) 4 memo(A) –Add A into the table and fail.

Linear Tabling11 A Linear Tabling Method (cont.) 4 check_completion(A) –If A has never occurred in a loop, complete A and resolve A by using the answers. –If A is a top-most looping subgoal If no new answer was produced in the last round, then complete A and resolve A by using the answers Otherwise, start a new round of evaluation of A. –If A is a looping subgoal but not a top-most one Set A ’s state to temporary complete and resolve A by using the answers

Linear Tabling12 Example p(X,Y):-p(X,Z),e(Z,Y),memo(p(X,Y)).(p1) p(X,Y):-e(X,Y),memo(p(X,Y)).(p2) p(X,Y):-check_completion(p(X,Y)). (p3) e(a,b).(e1) e(b,c).(e2) 1. p(a,Y0). 2. p(a,Z1), e(Z1,Y0), memo(p(a,Y0)). 3. e(a,Y0), memo(p(a,Y0)). 4. memo(p(a,b)). 5. check_comp(p(a,Y0)). First round p1 p2 e1 p3 program

Linear Tabling13 1. p(a,Y0). 6. p(a,Z1), e(Z1,Y0), memo(p(a,Y0)). 10. check_comp(p(a,Y0)). Second round p1p3 7. e(b,Y0), memo(p(a,Y0)). 8. memo(p(a,c)). use p(a,b) e2 9. e(c,Y0), memo(p(a,Y0)). use p(a,c) p(X,Y):-p(X,Z),e(Z,Y),memo(p(X,Y)).(p1) p(X,Y):-e(X,Y),memo(p(X,Y)).(p2) p(X,Y):-check_completion(p(X,Y)). (p3) e(a,b). (e1) e(b,c).(e2) p(a,b). program table p2 … p(a,b). p(a,c).

Linear Tabling14 Characteristics of the Method 4 Fixpoints are computed by iterating the evaluation of top-most looping subgoals 4 Followers consume answers only 4 Pioneers consume answers lazily –Top-most looping subgoals consume answers after they are complete –Other looping subgoals consume answers after all clauses have been tried

Linear Tabling15 Adopted and Related Tabling Strategies 4 Lazy answer consumption –Local scheduling strategy in SLG-WAM [Freire96] 4 What to do after a follower consumes all available answers? –Steals the pioneer’s choice pointer [Zhou00] –Fails the follower [Guo & Gupta 01] 4 Where to start re-computation? –At the top-most looping subgoal [Shen98] –At every looping subgoal [Guo01]

Linear Tabling16 Strengths and Weaknesses 4 Lazy answer consumption is suitable for all- solution search –A basic operation used in PRISM 4 Not suitable for single-solution search or programs with cuts –For the query, once(p(X)), a ll solutions are computed even though only one is needed.

Linear Tabling17 Optimization Techniques 4 Subgoal Optimization In each round of evaluation of a top-most looping subgoal, each subgoal needs to be evaluated only once. 4 Semi-naïve Optimization Mimic the semi-naïve technique in bottom-up evaluation: at least one new answer is involved in the join of answers for each rule.

Linear Tabling18 Semi-naïve Evaluation in Linear Tabling  Let H:-A 1,…,A k,…,A n be a rule where A k is the last dependent subgoal of H. For a subgoal C of H, it is safe for A k to consume only new answers if: –1. C has occurred in an early round –2. No subgoal A i (i<k) has consumed a new answer.

Linear Tabling19 Performance Evaluation 4 BP vs. XSB (CPU time) 4 BP vs. XSB (Stack space)

Linear Tabling20 Papers 1.N.F. Zhou, Y.D. Shen, L. Yuan, and J. You: A Linear Tabling Mechanism, The Journal of Functional and Logic Programming, N.F. Zhou and T. Sato: Efficient Fixpoint Computation in Linear Tabling, ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP), pp , N.F. Zhou, Y. Shen, and T. Sato: Semi-naive Evaluation in Linear Tabling, ACM PPDP, pp.90-97, 2004.