Top Banner
Advanced tabling mechanisms Advanced tabling mechanisms A call subsumption based tabling engine for Yap Prolog Fl´avio Cruz <[email protected]> Advisor: Ricardo Rocha <[email protected]> 1 Center for Research in Advanced Computing Systems 2 Faculdade de Ciˆ encias da Universidade do Porto February 1, 2010 CRACS Fl´ avio Cruz February 1, 201 0 1 / 17
17

Advanced Tabling Mechanisms

May 30, 2018

Download

Documents

flaviocruz250
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 1/17

Advanced tabling mechanisms

Advanced tabling mechanismsA call subsumption based tabling engine for Yap Prolog

Flavio Cruz <[email protected]>Advisor: Ricardo Rocha <[email protected]>

1Center for Research in Advanced Computing Systems2Faculdade de Ciencias da Universidade do Porto

February 1, 2010

CRACS Flavio Cruz February 1, 2010 1 / 17

Page 2: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 2/17

Advanced tabling mechanisms Outline

1 Prolog and SLDLimitations

2 TablingEvaluationVariant Tabling

3 Subsumptive TablingEvaluation

4 Table SpaceVariant Table SpaceSubsumptive Table Space

5 Objectives

6 Work Plan

CRACS Flavio Cruz February 1, 2010 2 / 17

Page 3: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 3/17

Advanced tabling mechanisms Prolog and SLD

Prolog and SLD evaluation

In Logic Programming, Selective Linear Definite  (SLD) is a top-downresolution mechanism.

SLD is inherently non-deterministic and does not force any specificsearch strategy.

The Prolog language uses depth first  search.

Despite being widely used, the current evaluation method has a fewshortcomings.

CRACS Flavio Cruz February 1, 2010 3 / 17

Page 4: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 4/17

Advanced tabling mechanisms Prolog and SLD

SLD shortcomings

?- path(1, Z)

1. path(1, Z)

2. path(1, Y), edge(Y, Z)

3. path(1, Y)

Infinite Loop

Program

path(X, Z) :- path(X, Y),

edge(Y, Z).

path(X, Z) :- edge(X, Z).

edge(1, 2).

edge(2, 3).

1 2 3

CRACS Flavio Cruz February 1, 2010 4 / 17

Ad d bli h i T bli

Page 5: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 5/17

Advanced tabling mechanisms Tabling

Tabling

Tabling is a refinement of the SLD resolution.

Consists in storing intermediate answers for subgoals so that they can

be reused when a repeated subgoal appears in the resolution process.Tabling evaluation reduces the search space, prunes redundantcomputations and has better termination properties.

Enables more expressive logic programs.

CRACS Flavio Cruz February 1, 2010 5 / 17

Ad d t bli h i T bli

Page 6: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 6/17

Advanced tabling mechanisms Tabling

Tabled Evaluation

Example

1. path(1, Z)

2. path(1, Y), edge(Y, Z) 3. edge(1, Z)

4. Z = 2 5. fail6. edge(2, Z)

7. Z = 3

9. edge(3, Z)

10. fail8. fail

Y = 2 Y = 3

11. complete

Answers: { (4) Z = 2, (7) Z = 3 }.

CRACS Flavio Cruz February 1, 2010 6 / 17

Advanced tabling mechanisms Tabling

Page 7: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 7/17

Advanced tabling mechanisms Tabling

Variant Tabling

In the previous example, when a subgoal is called, we verify if avariant subgoal  is already in the table space .

A subgoal G  is variant of subgoal G �, when G  and G � represent the

same subgoal by variable renaming.path(X, Y) is variant of  path(A, B), because both representpath(VAR0, VAR1).

While this is a simple approach, more sophisticated techniques areknown.

The YapTab tabling engine from Yap only supports variant checking.

CRACS Flavio Cruz February 1, 2010 7 / 17

Advanced tabling mechanisms Subsumptive Tabling

Page 8: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 8/17

Advanced tabling mechanisms Subsumptive Tabling

Subsumptive Tabling

Tabling by call subsumption aims to reuse answer computations bysharing answers from more general goals.

Theorem

If two subgoals G and G � exist, such that S and S � are the respective 

answer sets and G � subsumes G, then S ⊆ S �.

Example: path(X, Z) subsumes path(1, Z).

Subsumptive checking is implemented in SLG-WAM from XSB.

In the past, a technique called Dynamic Threaded Sequential 

Automata (DTSA) was used, currently they use Time Stamped Tries 

(TST).

CRACS Flavio Cruz February 1, 2010 8 / 17

Advanced tabling mechanisms Subsumptive Tabling

Page 9: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 9/17

Advanced tabling mechanisms Subsumptive Tabling

Subsumptive Evaluation

Answerspath(X, Z): {(3) X=1 Z=2, (4) X=2Z=3, (9) X=1 Z=3}

path(2, Z) {(9) Z=3}

path(3, Z): ∅

Programpath(X, Z) :- edge(X, Z).path(X, Z) :- edge(X, Y), path(Y, Z).

edge(1, 2). edge(2, 3).

Example1. path(X, Z)

2. edge(X, Z)

3. X = 1

Z = 2

4. X = 2

Z = 35. fail

7. edge(X, Y), path(Y, Z)

8. path(2, Z) 10. path(3, Z)

9. Z = 3

11. fail

12. complete

X=1,Y=2X=2,Y=3

CRACS Flavio Cruz February 1, 2010 9 / 17

Advanced tabling mechanisms Table Space

Page 10: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 10/17

Advanced tabling mechanisms Table Space

Variant Table Space

Tries are used to index terms.

Tries are a tree-structured automaton where common term prefixesare represented only once.

Two levels of tries:� Call Trie : stores subgoals for a specific predicate, like path/2.� Answer Trie : where answers are stored.

Only the values of variables are stored in the answer trie, in amechanism called substitution factoring .

A leaf state in a subgoal trie points to a subgoal frame  where stateabout the subgoal evaluation is kept.

CRACS Flavio Cruz February 1, 2010 10 / 17

Advanced tabling mechanisms Table Space

Page 11: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 11/17

g p

Variant Table Space

Example

Table entry for path/2

Subgoal trie for path/2

root

a

VAR0

b

VAR0

VAR0

VAR1

Subgoal Frame forpath(a, VAR0)

Subgoal Frame forpath(b, VAR0)

Subgoal Frame forpath(VAR0, VAR1)

Answer trie for path(a, VAR0)

root

ba

CRACS Flavio Cruz February 1, 2010 11 / 17

Advanced tabling mechanisms Table Space

Page 12: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 12/17

g p

Time Stamped Tries

A subsumptive approach to tabling.

Instead of using an answer trie, in this technique we use a timestamped trie.

Whenever a new answer is found, the timestamps along the answerpath are updated to the incremented maximum time stamp .

Each subsumed goal keeps track of the last time stamp used, thus itcan retrieve only the new answers by unification when consuming.

The main objective is to avoid repeated answers.

CRACS Flavio Cruz February 1, 2010 12 / 17

Advanced tabling mechanisms Table Space

Page 13: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 13/17

g

Time Stamped Tries

Time stamped trie for subgoal p(X, Y, Z):

Example (before)

root node

a, 5

a, 5

a, 1c, 3d, 5

b, 4

b, 4

b, 2

a, 2

VAR0, 2

Example (new answer p(a, b, c))

root node

a, 6

a, 5

a, 1c, 3d, 5

b, 6

b, 4

b, 2

a, 2

VAR0, 2c, 6

CRACS Flavio Cruz February 1, 2010 13 / 17

Advanced tabling mechanisms Table Space

Page 14: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 14/17

Finding subsuming goals

Another important component in call by subsumption deals withlocating more generals subgoals in the call trie.

Unification and backtracking are used by SLG-WAM.

The algorithm finds a minimally subsuming call , hence it can be usedto efficiently check wether the found subgoal is a variant or not.

CRACS Flavio Cruz February 1, 2010 14 / 17

Advanced tabling mechanisms Objectives

Page 15: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 15/17

Objectives

Implement a subsumptive tabling engine in Yap, using theSLG-WAM’s time stamped tries approach.

Work on new approaches and optimizations using the previous work.We are trying to reuse as much code from XSB as possible to enablenovel features to be used by both Prolog systems.

Produce original work.

CRACS Flavio Cruz February 1, 2010 15 / 17

Advanced tabling mechanisms Work Plan

Page 16: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 16/17

Work Plan

Until the end of February: complete a prototype version using timestamped tries.

March, April, May: implement a few optimizations and try some new

approaches.

May, June: write the dissertation.

Lots of testing!

Produce one or two papers.

CRACS Flavio Cruz February 1, 2010 16 / 17

Advanced tabling mechanisms Work Plan

Page 17: Advanced Tabling Mechanisms

8/14/2019 Advanced Tabling Mechanisms

http://slidepdf.com/reader/full/advanced-tabling-mechanisms 17/17

Some useful links

http://github.com/flavioc/yap/

http://cracs.fc.up.pt/http://www.dcc.fc.up.pt/~vsc/Yap/

http://flaviocruz.net/

CRACS Flavio Cruz February 1, 2010 17 / 17