+ All Categories
Home > Documents > Environments for Tabled Prolog: Progress and Open Issues

Environments for Tabled Prolog: Progress and Open Issues

Date post: 25-Jan-2016
Category:
Upload: waseem
View: 32 times
Download: 1 times
Share this document with a friend
Description:
Environments for Tabled Prolog: Progress and Open Issues. Terrance Swift CENTRIA Universidade Nova de Lisboa. Motivation * Tabling has proven its usefulness over the past decade -- cf. How tabling solves real problems www.cs.sunysb.edu/~tswift/talks.html - PowerPoint PPT Presentation
Popular Tags:
47
Environments for Tabled Prolog: Progress and Open Issues Terrance Swift CENTRIA Universidade Nova de Lisboa
Transcript
Page 1: Environments for Tabled Prolog: Progress and Open Issues

Environments for Tabled Prolog: Progress and Open

Issues

Environments for Tabled Prolog: Progress and Open

Issues

Terrance Swift

CENTRIAUniversidade Nova de Lisboa

Terrance Swift

CENTRIAUniversidade Nova de Lisboa

Page 2: Environments for Tabled Prolog: Progress and Open Issues

MotivationMotivation

* Tabling has proven its usefulness over the past decade* Tabling has proven its usefulness over the past decade-- cf. -- cf. How tabling solves real problemsHow tabling solves real problems www.cs.sunysb.edu/~tswift/talks.html

* Tabling is supported in XSB, YAP, B Prolog; packages * Tabling is supported in XSB, YAP, B Prolog; packages have been developed or are being developed for have been developed or are being developed for Mercury, ALS, CiaoMercury, ALS, Ciao

* User environment issues have received * User environment issues have received somesome attention, attention, but there are many open issues in analysis and language but there are many open issues in analysis and language designdesign

* Unlike tabling implementation, environment issues do * Unlike tabling implementation, environment issues do not depend on engine-level coding, and so results may be not depend on engine-level coding, and so results may be applicable to several systems and may require less applicable to several systems and may require less specialized knowledge to implementspecialized knowledge to implement

* Talk is high-level, but a general knowledge of tabling is * Talk is high-level, but a general knowledge of tabling is assumedassumed

Page 3: Environments for Tabled Prolog: Progress and Open Issues

XSB’s tabling methodology as discussed in this talk was XSB’s tabling methodology as discussed in this talk was developed and implemented by (in alphabetical developed and implemented by (in alphabetical order)Luis de Castro, Baoqiu Cui, Steve Dawson,Ernie order)Luis de Castro, Baoqiu Cui, Steve Dawson,Ernie Johnson, Juliana Freire, Michael Kifer,Johnson, Juliana Freire, Michael Kifer,

Rui F. Marques, C.R. Ramakrishnan, I.V. Rui F. Marques, C.R. Ramakrishnan, I.V. Ramakrishnan,Prasad Rao, Konstantinos Sagonas, Ramakrishnan,Prasad Rao, Konstantinos Sagonas, Diptikalyan Saha,Terrance Swift,David S. WarrenDiptikalyan Saha,Terrance Swift,David S. Warren

Page 4: Environments for Tabled Prolog: Progress and Open Issues

What environmental issues are important?What environmental issues are important?

It depends on what a future tabling system might look likeIt depends on what a future tabling system might look like

Page 5: Environments for Tabled Prolog: Progress and Open Issues

Non-monotonic Deductive Non-monotonic Deductive databases databases reasoningreasoning

Logic programmingLogic programming

** Most work in tabling has been from the LP perspective Most work in tabling has been from the LP perspective (including enviroment support)(including enviroment support)

* Some work has been done to support NMR with residual * Some work has been done to support NMR with residual programs and XASPprograms and XASP

* Less has been done to support deductive database features* Less has been done to support deductive database features

Page 6: Environments for Tabled Prolog: Progress and Open Issues

Two PremisesTwo Premises

1)1) Deductive databases are not dead (they’re just Deductive databases are not dead (they’re just asleep)asleep)

Logic programming can be a basis for (mostly) in-Logic programming can be a basis for (mostly) in-memory DDBs usingmemory DDBs using

-- -- TablingTabling which can help with querying, given which can help with querying, given analysis support for optimizationanalysis support for optimization-- -- Multi-threadingMulti-threading as in SWI, Ciao, YAP and XSB as in SWI, Ciao, YAP and XSB-- -- Adaptive indexingAdaptive indexing as in YAP [CSL as in YAP [CSL007] (or perhaps 7] (or perhaps even good analysis-based indexing with XSB)even good analysis-based indexing with XSB)

For deductive database applications, queries may For deductive database applications, queries may rely less user programming and more compiler rely less user programming and more compiler analysis and transformationsanalysis and transformations

Page 7: Environments for Tabled Prolog: Progress and Open Issues

Two PremisesTwo Premises

2) 2) The well-founded semantics is important for The well-founded semantics is important for knowledge representationknowledge representation

* Some cognitive scientists model human cognition as a * Some cognitive scientists model human cognition as a logic program under a 3-valued semantics (SvLlogic program under a 3-valued semantics (SvL008)8)

* Other advantages of WFS* Other advantages of WFS-- Relevancy-- Relevancy-- Cumulativity-- Cumulativity-- Polynomial complexity (in practice usually linear)-- Polynomial complexity (in practice usually linear)-- ... and it can be used as a step toward a (partial) -- ... and it can be used as a step toward a (partial) stable modelstable model

* But like stable models, WFS may be difficult for a * But like stable models, WFS may be difficult for a programmer to understandprogrammer to understand

Page 8: Environments for Tabled Prolog: Progress and Open Issues

10 Topics in Environments for Tabled Logic 10 Topics in Environments for Tabled Logic ProgamsProgams

What topics might an ideal compiler address to support What topics might an ideal compiler address to support all the functionality we’d like?all the functionality we’d like?

#1 Managing table space#1 Managing table space#2 Updating tables when dynamic code changes#2 Updating tables when dynamic code changes

#3 Automatically deciding which predicates to table#3 Automatically deciding which predicates to table#4 Deciding what kind of tabling to use#4 Deciding what kind of tabling to use#5 Optimizing transformations#5 Optimizing transformations#6 Choosing a scheduling strategy#6 Choosing a scheduling strategy

#7 Debugging#7 Debugging#8 Support for transformation-based semantic #8 Support for transformation-based semantic extensionsextensions#9 Better ASP Integration#9 Better ASP Integration#10 Making answer subsumption usable by real #10 Making answer subsumption usable by real programmersprogrammers

Page 9: Environments for Tabled Prolog: Progress and Open Issues

#1 Managing table space#1 Managing table space* Tables can consume a lot of space, and so must be reclaimed* Tables can consume a lot of space, and so must be reclaimed

-- do we want tables to amortize time for multiple queries?-- do we want tables to amortize time for multiple queries?-- do we want to reclaim tables after each top-level query?-- do we want to reclaim tables after each top-level query?-- do we want to reclaim tables within a query?-- do we want to reclaim tables within a query?

* Reclamation can be for * Reclamation can be for -- All tables (XSB, YAP, BProlog)-- All tables (XSB, YAP, BProlog)-- All tables for a given predicate (XSB,YAP, BProlog)-- All tables for a given predicate (XSB,YAP, BProlog)-- All tables for predicates in a given module (XSB)-- All tables for predicates in a given module (XSB)-- All thread-private/thread-shared tables (XSB)-- All thread-private/thread-shared tables (XSB)-- A single table for a given call (XSB)-- A single table for a given call (XSB)

* Reclamation can be automatic -- based on a LRU algorithm * Reclamation can be automatic -- based on a LRU algorithm [Roc](YAP)[Roc](YAP)

* Safe reclamation requires garbage collection for tables.* Safe reclamation requires garbage collection for tables.-- XSB has full garbage collection for thread-private tables-- XSB has full garbage collection for thread-private tables-- Space for thread-shared tables can only be reclaimed when -- Space for thread-shared tables can only be reclaimed when there is a single active threadthere is a single active thread

Page 10: Environments for Tabled Prolog: Progress and Open Issues

#1 Managing table space#1 Managing table space

* Space reclamation becomes more complicated when * Space reclamation becomes more complicated when supporting well-founded reductssupporting well-founded reducts

* XSB maintains the well-founded reduct in its table, called the * XSB maintains the well-founded reduct in its table, called the residual progam e.g inresidual progam e.g in

the table the table p(X)p(X) depends on the table depends on the table b(X) b(X) through the answer through the answer b(2) b(2) which is undefined under WFSwhich is undefined under WFS

* Abolishing * Abolishing b(2)b(2) but not but not p(X)p(X) changes the residual program changes the residual program with semantic implications when integrating with ASP solvers, with semantic implications when integrating with ASP solvers, not to mention core dumps.not to mention core dumps.

* XSB has a flag indicating whether table abolishes are to be * XSB has a flag indicating whether table abolishes are to be cascadedcascaded

p(X)

p(1)

p(2):- b(2)b(X)|

p(3)

Page 11: Environments for Tabled Prolog: Progress and Open Issues

#1 Managing table space#1 Managing table space

* These approaches are already sophisticated, but how * These approaches are already sophisticated, but how should space be reclaimed? should space be reclaimed?

-- Ignore for a minute reclaiming tables that depend on -- Ignore for a minute reclaiming tables that depend on dynamic clauses that have changeddynamic clauses that have changed

* A combined approach that * A combined approach that -- Automatically reclaims-- Automatically reclaims-- Reclaims safely with no possibility of backtracking into -- Reclaims safely with no possibility of backtracking into a reclaimed tablea reclaimed table-- Takes into account inter-table dependencies for WFS-- Takes into account inter-table dependencies for WFS

* Allow users (or a compiler) to specify the level of * Allow users (or a compiler) to specify the level of persistence of a tablepersistence of a table

-- Never reclaimable-- Never reclaimable-- Automatically reclaimable at system threshold-- Automatically reclaimable at system threshold-- Reclaimable at end of query-- Reclaimable at end of query-- Reclaimable after last use within a query (determined -- Reclaimable after last use within a query (determined by analysis)by analysis)

Page 12: Environments for Tabled Prolog: Progress and Open Issues

#2 Updating tables when dynamic code changes#2 Updating tables when dynamic code changes

* If a table depends on dynamic clauses, the table should be * If a table depends on dynamic clauses, the table should be updated when those clauses are alteredupdated when those clauses are altered

* In XSB this works for definite programs under call variance * In XSB this works for definite programs under call variance [Sah06], but the logical view of updates is not supported., but the logical view of updates is not supported.

* Multiple declarations are required* Multiple declarations are required-- a tabled predicate must be declared as incremental as do -- a tabled predicate must be declared as incremental as do the relevant dynamic predicates.the relevant dynamic predicates.-- special assert/retract predicates must be used. -- special assert/retract predicates must be used. incr_assert(p(a))incr_assert(p(a)) asserts asserts p(a)p(a) and updates the incremental and updates the incremental tables that depend on tables that depend on p/1p/1. Similarly, . Similarly, incr_assert_inval(p(a))incr_assert_inval(p(a)) invalidates tables that depend on invalidates tables that depend on p/1p/1

** Analysis work is needed to determine whether a predicate Analysis work is needed to determine whether a predicate should be tabled as incremental (easy), and whether the table should be tabled as incremental (easy), and whether the table should be incrementally updated or invalidated (hard).should be incrementally updated or invalidated (hard).

Page 13: Environments for Tabled Prolog: Progress and Open Issues

Global Analysis for TablingGlobal Analysis for Tabling

Page 14: Environments for Tabled Prolog: Progress and Open Issues

Global Analysis for TablingGlobal Analysis for Tabling

* The most common way to table is to choose * The most common way to table is to choose predicates to table by handpredicates to table by hand

* This may be difficult to do in certain cases (e.g. * This may be difficult to do in certain cases (e.g. generated code)generated code)

* As tabling systems mature, different tables may * As tabling systems mature, different tables may have different attributes, increasing the complexityhave different attributes, increasing the complexity

-- Call subsumption vs. call variance (XSB)-- Call subsumption vs. call variance (XSB)-- Incremental vs. non-incremental (XSB)-- Incremental vs. non-incremental (XSB)-- Thread-private vs. thread-shared (XSB)-- Thread-private vs. thread-shared (XSB)-- Tabling with scheduling strategies (YAP)-- Tabling with scheduling strategies (YAP)

Page 15: Environments for Tabled Prolog: Progress and Open Issues

Example: A Fragment of the OWL Wine OntologyExample: A Fragment of the OWL Wine Ontology

<owl:Class rdf:ID="PinotBlanc"> <rdfs:subClassOf> <owl:Restriction> <owl:Class rdf:ID="PinotBlanc"> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty rdf:resource="#hasColor" /> <owl:hasValue <owl:onProperty rdf:resource="#hasColor" /> <owl:hasValue rdf:resource="#White" /> </owl:Restriction> </rdfs:subClassOf> rdf:resource="#White" /> </owl:Restriction> </rdfs:subClassOf> <owl:intersectionOf rdf:parseType="Collection"> <owl:Class <owl:intersectionOf rdf:parseType="Collection"> <owl:Class rdf:about="#Wine" /> <owl:Restriction> <owl:onProperty rdf:about="#Wine" /> <owl:Restriction> <owl:onProperty rdf:resource="#madeFromGrape" /> <owl:hasValue rdf:resource="#madeFromGrape" /> <owl:hasValue rdf:resource="#PinotBlancGrape" /> </owl:Restriction> rdf:resource="#PinotBlancGrape" /> </owl:Restriction> <owl:Restriction> <owl:onProperty rdf:resource="#madeFromGrape" /> <owl:Restriction> <owl:onProperty rdf:resource="#madeFromGrape" /> <owl:maxCardinality <owl:maxCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality> rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxCardinality> </owl:Restriction> </owl:intersectionOf> </owl:Class></owl:Restriction> </owl:intersectionOf> </owl:Class>

Page 16: Environments for Tabled Prolog: Progress and Open Issues

The ontology is translated by KAON2 to a definite program with The ontology is translated by KAON2 to a definite program with about 1000 clausesabout 1000 clauses

pinotblanc(X)pinotblanc(X) :- :- q24(X)q24(X)..pinotblanc(X) :- pinotblanc(Y)pinotblanc(X) :- pinotblanc(Y),kaon2equal(X, ,kaon2equal(X, Y).Y).pinnotblanc(X) :-pinnotblanc(X) :- wine(X)wine(X),madefromgrape(X, Y),ot____nom21(Y).,madefromgrape(X, Y),ot____nom21(Y).madefromgrape(Y, X) :- madefromgrape(Y, X) :- madeintowinmadeintowinee(X, Y).madefromgrape(X, X) :- (X, Y).madefromgrape(X, X) :- riesling(X),kaon2namedobjects(X).madefromgrape(X, X) :- riesling(X),kaon2namedobjects(X).madefromgrape(X, X) :- wine(X),wine(X),kaon2namedobjects(X).% 18 otherskaon2namedobjects(X).% 18 others

wine(X)wine(X) :- q14(X). :- q14(X).wine(X)wine(X) :- texaswine(X).% 24 others :- texaswine(X).% 24 otherswine(X)wine(X) :- :- q24(X)q24(X)..% 31 others% 31 othersq24(X)q24(X) :- :- pinotblanc(X)pinotblanc(X)..q24(X)q24(X) :- muscadet(X). :- muscadet(X).q24(X) q24(X) :- :- q24(Y)q24(Y),kaon2equal(X, Y),kaon2equal(X, Y)..

Page 17: Environments for Tabled Prolog: Progress and Open Issues

Global Analysis for Tabling Global Analysis for Tabling

Regardless of whether this program can be Regardless of whether this program can be optimized, it is highly recursiveoptimized, it is highly recursive

pinotblanc(yellowTail)pinotblanc(yellowTail) depends on depends onpinotblanc(X)pinotblanc(X) depends on depends on wine(X)wine(X)

and onand onwine(yellowTail)wine(yellowTail)

Nearly every concept depends on nearly every Nearly every concept depends on nearly every other concept (more or less)other concept (more or less)

Each predicate is called with multiple instantiationsEach predicate is called with multiple instantiations

Page 18: Environments for Tabled Prolog: Progress and Open Issues

#3 Automatically deciding which predicates to #3 Automatically deciding which predicates to tabletable

* The * The autotableautotable declaration can be used to declaration can be used to automatically select predicates to table (XSB). This automatically select predicates to table (XSB). This declaration has proven useful for certain problemsdeclaration has proven useful for certain problems

-- All loops in the predicate dependency graph are -- All loops in the predicate dependency graph are brokenbroken-- No effort is made to determine a minimal set of -- No effort is made to determine a minimal set of predicates to table (a previous version did, but it predicates to table (a previous version did, but it was to expensive)was to expensive)-- No effort is made to distinguish structural -- No effort is made to distinguish structural recursion (e.g. recursion (e.g. append/3append/3) from datalog recursion) from datalog recursion

* Analysis routines are needed to distinguish * Analysis routines are needed to distinguish structural from datalog recursion, and then derive a structural from datalog recursion, and then derive a good approximation of a minimal set of predicates to good approximation of a minimal set of predicates to tabletable

Page 19: Environments for Tabled Prolog: Progress and Open Issues

Call SubsumptionCall SubsumptionXSBXSB

Call VarianceCall VarianceXSB, YAP, BPrologXSB, YAP, BProlog

Global TablesGlobal TablesYAPYAP

#4 Deciding what kind of tabling to use#4 Deciding what kind of tabling to use

Page 20: Environments for Tabled Prolog: Progress and Open Issues

#4 Deciding what kind of tabling to use #4 Deciding what kind of tabling to use Call subsumption vs. Call VarianceCall subsumption vs. Call Variance

Call subsumption [JRRCall subsumption [JRR009,Swi9,Swi009] -- e.g. the goal 9] -- e.g. the goal p(a,Y)p(a,Y) can can use the table for the goal use the table for the goal p(X,Y)p(X,Y) -- can greatly increase -- can greatly increase efficiency for some programs by sharing more computationsefficiency for some programs by sharing more computations

Call subsumption accrues about a 25% overhead if not Call subsumption accrues about a 25% overhead if not neededneeded

Call subsumption may not be desired when tabling a meta Call subsumption may not be desired when tabling a meta interpreterinterpreter

Call subsumption with term depth abstraction can ensure Call subsumption with term depth abstraction can ensure that any program with a finite model terminatesthat any program with a finite model terminates

-- e.g. -- e.g. p(X):- p(s(X)) p(X):- p(s(X)) can terminate if abstraction occurs at a can terminate if abstraction occurs at a depth of, say 10. Then a subgoal such as depth of, say 10. Then a subgoal such as p(s(s(s(s(s(s(s(s(s(s(X)))))))))))p(s(s(s(s(s(s(s(s(s(s(X)))))))))))is abstracted tois abstracted to p(s(s(s(s(s(s(s(s(s(X))))))))))p(s(s(s(s(s(s(s(s(s(X))))))))))

* * Within XSB, sharing is only performed if the subsumed call Within XSB, sharing is only performed if the subsumed call occurs after the subsuming call (occurs after the subsuming call (p(a,Y)p(a,Y) after after p(X,Y)p(X,Y)))

Page 21: Environments for Tabled Prolog: Progress and Open Issues

#4 Deciding what kind of tabling to use #4 Deciding what kind of tabling to use Global Tables vs Call VarianceGlobal Tables vs Call Variance

* Similar to call subsumption, YAP’s global tables * Similar to call subsumption, YAP’s global tables [CR09] allow answers to be shared between different [CR09] allow answers to be shared between different calls calls

* Unlike call subsumption, global tables can share * Unlike call subsumption, global tables can share answer information for two calls that unify even if answer information for two calls that unify even if neither subsumes the other (e.g. neither subsumes the other (e.g. p(a,X)p(a,X) and and p(X,b)p(X,b)))

* On the other hand, unlike call subsumption, * On the other hand, unlike call subsumption, computation is not shared between two calls with computation is not shared between two calls with global tablesglobal tables

* However, global tables accrue a time cost over call * However, global tables accrue a time cost over call variance, as well as a space cost if they are not used.variance, as well as a space cost if they are not used.

Page 22: Environments for Tabled Prolog: Progress and Open Issues

#4 Deciding what kind of tabling to use#4 Deciding what kind of tabling to use

* So in addition to deciding what predicates to * So in addition to deciding what predicates to table, our perfect compiler decides between call table, our perfect compiler decides between call variance, call subsumption and global tables (and variance, call subsumption and global tables (and BDDs and other data structures)BDDs and other data structures)

* Some work has been done on analyzing when to * Some work has been done on analyzing when to use call subsumption [RRR96], but it has not been use call subsumption [RRR96], but it has not been put into a compilerput into a compiler

Page 23: Environments for Tabled Prolog: Progress and Open Issues

#5 Optimizing Transformations#5 Optimizing Transformations

Let’s say you have a fully connected graph of Let’s say you have a fully connected graph of NN nodes and you want to find all nodes reachable from nodes and you want to find all nodes reachable from a given node a given node aa (e.g. your goal is (e.g. your goal is ?- p(a,Y)?- p(a,Y)). You can ). You can use:use:

-- left recursion: -- left recursion: path(X,Y):- path(X,Z),edge(Z,Y) path(X,Y):- path(X,Z),edge(Z,Y) which creates one table with which creates one table with N-1N-1 nodes and nodes and returns returns N-1N-1 answers answers-- right recursion: -- right recursion: path(X,Y):- edge(X,Z), path(Z,Y) path(X,Y):- edge(X,Z), path(Z,Y) which which

-- creates -- creates NN tables each with tables each with N-1N-1 nodes and nodes and returns returns (N-1)(N-1)22 answers under call variance answers under call variance-- would create -- would create 11 table under call subsumption table under call subsumption if if ?- p(X,Y)?- p(X,Y) were used, but still would return were used, but still would return (N-(N-1)1)22 answers answers

-- double recursion: -- double recursion: path(X,Y):- path(X,Z), path(X,Y):- path(X,Z), path(Z,Y) path(Z,Y) which returns which returns N(N-1)N(N-1) answers under call answers under call variancevariance

Page 24: Environments for Tabled Prolog: Progress and Open Issues

#5 Optimizing Transformations#5 Optimizing Transformations

* So its usually best to transform into left recursion * So its usually best to transform into left recursion (if the bindings can be maintained)(if the bindings can be maintained)

* However, not all recursion can be transformed into * However, not all recursion can be transformed into left recursion without losing bindingsleft recursion without losing bindings

sg(X,X).sg(X,X).sg(X,Y):- p(X,Z),sg(Z,Z1),p(Z1,Y)sg(X,Y):- p(X,Z),sg(Z,Z1),p(Z1,Y)

* When is it useful to transform recursion into left-* When is it useful to transform recursion into left-recursion? Does call subsumption affect the decision recursion? Does call subsumption affect the decision of when to transform?of when to transform?

sg(X,X).sg(X,X).sg(X,Y):- sg(Z,Z1),p(X,Z),p(Z1,Y)sg(X,Y):- sg(Z,Z1),p(X,Z),p(Z1,Y)

Page 25: Environments for Tabled Prolog: Progress and Open Issues

Example: compiling away recursion [NAU89]Example: compiling away recursion [NAU89]

buys(X,Y):- likes(X,Y).buys(X,Y):- likes(X,Y).buys(X,Y):- trendy(X),buys(Z,Y)buys(X,Y):- trendy(X),buys(Z,Y)

is equivalent to is equivalent to buys(X,Y):- likes(X,Y).buys(X,Y):- likes(X,Y).buys(X,Y):- trendy(X),likes(Z,Y)buys(X,Y):- trendy(X),likes(Z,Y)

butbutbuys(X,Y):- likes(X,Y).buys(X,Y):- likes(X,Y).buys(X,Y):- knows(X,Z),buys(Z,Y)buys(X,Y):- knows(X,Z),buys(Z,Y)

is is notnot equivalent to equivalent to buys(X,Y):- likes(X,Y).buys(X,Y):- likes(X,Y).buys(X,Y):- knows(X,Z),likes(Z,Y)buys(X,Y):- knows(X,Z),likes(Z,Y)

Page 26: Environments for Tabled Prolog: Progress and Open Issues

#5 Optimizing Transformations#5 Optimizing Transformations

* How do these tabling optimizations recall * How do these tabling optimizations recall optimizations for optimizations for

-- Prolog (e.g. transformations to get rid of -- Prolog (e.g. transformations to get rid of existential variables [PP95])existential variables [PP95])-- Deductive databases (e.g. separable recursion -- Deductive databases (e.g. separable recursion [Nau88])[Nau88])-- Grammars (e.g. the complexity reduction of -- Grammars (e.g. the complexity reduction of Earley Grammars when they are translated into Earley Grammars when they are translated into Chomsky Normal Form [Ear70])Chomsky Normal Form [Ear70])

-- XSB has a declaration for this transformation, -- XSB has a declaration for this transformation, called called suppl_tablesuppl_table, but no support on whether it , but no support on whether it should be used.should be used.

Page 27: Environments for Tabled Prolog: Progress and Open Issues

#6 Choosing a scheduling strategy#6 Choosing a scheduling strategy

* Tabled evaluations can differ in their scheduling strategy * Tabled evaluations can differ in their scheduling strategy [FSW98] -- the decision about when answers are to be [FSW98] -- the decision about when answers are to be returned to (possibly suspended) subgoalsreturned to (possibly suspended) subgoals

* The two most popular strategies are * The two most popular strategies are -- -- locallocal evaluation which is efficient in terms of stack evaluation which is efficient in terms of stack usage; and efficient for returning all answers. It can also usage; and efficient for returning all answers. It can also reduce the complexity when answer subsumption is used reduce the complexity when answer subsumption is used (e.g. for finding shortest paths)(e.g. for finding shortest paths)-- -- batchedbatched evaluation which is efficient for finding the first evaluation which is efficient for finding the first answer for a subgoal, and for parallelizing tabled answer for a subgoal, and for parallelizing tabled evaluations evaluations

* The scheduling strategy can be dynamically selected in YAP * The scheduling strategy can be dynamically selected in YAP [RSC[RSC005], but is only a configuration option in XSB5], but is only a configuration option in XSB

* Altering a scheduling strategy may be a factor in extracting * Altering a scheduling strategy may be a factor in extracting certain types of table parallelism that are based on threads certain types of table parallelism that are based on threads communicating through tables (XSB) or in a full or-parallel communicating through tables (XSB) or in a full or-parallel tabling system (OptYAP)tabling system (OptYAP)

Page 28: Environments for Tabled Prolog: Progress and Open Issues

Supporting TransformationsSupporting Transformations

Page 29: Environments for Tabled Prolog: Progress and Open Issues

#7 Debugging#7 Debugging

Tabling may need to repeatedly suspend Tabling may need to repeatedly suspend computation of a tabled subgoal computation of a tabled subgoal S S and resume the and resume the computation when further answers are derived for computation when further answers are derived for SS

This change in search strategy can break the model This change in search strategy can break the model of the 4-port Prolog debugger -- i.e. “skip” may have of the 4-port Prolog debugger -- i.e. “skip” may have no meaningno meaning

-- at the least, a trace-based debugger becomes -- at the least, a trace-based debugger becomes more complex for a usermore complex for a user

XSB has a justification package [PGD+XSB has a justification package [PGD+004]; similar 4]; similar packages have been created for ASP systems packages have been created for ASP systems [PSE[PSE009] 9]

-- after computation has terminated, produce a -- after computation has terminated, produce a representation of the search tree that justifies the representation of the search tree that justifies the resultresult

Page 30: Environments for Tabled Prolog: Progress and Open Issues

#7 Debugging #7 Debugging

Justification-based debugging works as follows:Justification-based debugging works as follows:

1) Assertions are made of the form1) Assertions are made of the form justify_pred(Pred) justify_pred(Pred)2) The annotated program is transformed2) The annotated program is transformed2) A call is made 2) A call is made just_true(Goal,JustTruejust_true(Goal,JustTrue) or ) or just_false(Goal,JustFalse)just_false(Goal,JustFalse)

-- JustTrue -- JustTrue unifies with a proof ofunifies with a proof of Goal Goal-- JustFalse -- JustFalse unifies with witnesses of failure for all unifies with witnesses of failure for all clauses forclauses for Goal Goal-- -- IfIf Goal Goal is undefined, it will have both a true and a is undefined, it will have both a true and a false justificationfalse justification

Currently, justification does not appear to be heavily Currently, justification does not appear to be heavily used, due in part to the fact that it is not well used, due in part to the fact that it is not well integrated with XSB (a program has to be transformed integrated with XSB (a program has to be transformed then reloaded to run the justifier)then reloaded to run the justifier)

Page 31: Environments for Tabled Prolog: Progress and Open Issues

#7 Debugging #7 Debugging

Thus, to support debugging of tabled programs Thus, to support debugging of tabled programs either either

--justification must be performed (via a meta---justification must be performed (via a meta-interpreter or pre-processor); orinterpreter or pre-processor); or-- some sort of trace-based debugging needs to be -- some sort of trace-based debugging needs to be developed for tabling; ordeveloped for tabling; or-- some other approach must be developed-- some other approach must be developed

No solution is currently satisfactory, so debugging No solution is currently satisfactory, so debugging tabling remains an open issue, especially with non-tabling remains an open issue, especially with non-stratified programsstratified programs

Page 32: Environments for Tabled Prolog: Progress and Open Issues

#8 Support for transformation-based language #8 Support for transformation-based language extensionsextensions

* Consider well-founded * Consider well-founded atom-basedatom-based preferences. A preferences. A preference clause has the formpreference clause has the form prefer(A1,A2):- Body prefer(A1,A2):- Body which means that if Body is true, a derivation of A2 which means that if Body is true, a derivation of A2 will be true only if a derivation of A1 is false (if A1 is will be true only if a derivation of A1 is false (if A1 is undefined, A2 will be also)undefined, A2 will be also)

* This has been used for * This has been used for -- Amalgamating psychiatric rules [GST+-- Amalgamating psychiatric rules [GST+0000]]-- Disambiguating grammars [GJM95,CS-- Disambiguating grammars [GJM95,CS002]2]-- Adding local policies to workflows-- Adding local policies to workflows

* Implemented though a (fairly) simple * Implemented though a (fairly) simple transformation transformation prefer(A1,A2)prefer(A1,A2) adds a literal adds a literal tnot(overridden(A2))tnot(overridden(A2)) to clauses that may derive A2 to clauses that may derive A2

Page 33: Environments for Tabled Prolog: Progress and Open Issues

#8 Support for transformation-based #8 Support for transformation-based extensionsextensions

* Work is being done to integrate preferences into XSB’s* Work is being done to integrate preferences into XSB’s compiler, however, this gives rise to questionscompiler, however, this gives rise to questions

-- how to debug in a cognitively meaningful manner -- how to debug in a cognitively meaningful manner -- specialization to ensure that -- specialization to ensure that overridden/1overridden/1 literals literals are not added to bodies unnecessarilyare not added to bodies unnecessarily

* Explicit negation under WFS [ADP94] is another * Explicit negation under WFS [ADP94] is another transformation-based extensiontransformation-based extension

* In general a compiler must be architected so that the * In general a compiler must be architected so that the analysis and optimizations mentioned above happen “at analysis and optimizations mentioned above happen “at the right time”the right time”

-- e.g. recursion separation, determination of what to -- e.g. recursion separation, determination of what to table, etc. should happen after the semantic table, etc. should happen after the semantic transformationstransformations-- optimizations specific to preferences, explicit -- optimizations specific to preferences, explicit negation, etc. may determine the exact form of the negation, etc. may determine the exact form of the transformationtransformation

Page 34: Environments for Tabled Prolog: Progress and Open Issues

#8 Support for transformation-based #8 Support for transformation-based extensionsextensions

* In general a compiler must be architected so that the * In general a compiler must be architected so that the analysis and optimizations mentioned above happen “at analysis and optimizations mentioned above happen “at the right time”the right time”

-- e.g. recursion separation, determination of what to -- e.g. recursion separation, determination of what to table, etc. should happen after the semantic table, etc. should happen after the semantic transformationstransformations-- optimizations specific to preferences, explicit -- optimizations specific to preferences, explicit negation, etc. may determine the exact form of the negation, etc. may determine the exact form of the transformationtransformation

* How can we ensure that a sequence of * How can we ensure that a sequence of transformations is semantically valid?transformations is semantically valid?

* How can we ensure that a sequence of * How can we ensure that a sequence of transformations is operationally valid (e.g. transformations is operationally valid (e.g. optimizations work, debugging meaningful)?optimizations work, debugging meaningful)?

Page 35: Environments for Tabled Prolog: Progress and Open Issues

#9 Better ASP integration#9 Better ASP integration

The XSB distribution now includes Smodels, and the The XSB distribution now includes Smodels, and the XASP package provides a way to evaluate the partial XASP package provides a way to evaluate the partial stable models of a residual program --(well-founded stable models of a residual program --(well-founded reduct of the portion of a program relevant to a reduct of the portion of a program relevant to a query).query).

-- -- init_smodels(Query)init_smodels(Query) sends the residual of a sends the residual of a query to Smodelsquery to Smodels-- -- in_all_stable_models(Goal)in_all_stable_models(Goal) andand pstable_model(Goal,Model) pstable_model(Goal,Model) provide a means to query provide a means to query SmodelsSmodels-- each XSB thread can have its own instance of -- each XSB thread can have its own instance of SmodelsSmodels-- XASP has been used for agent programs -- XASP has been used for agent programs [PL07,LMP08, PA09] and has been extended to [PL07,LMP08, PA09] and has been extended to handle Plog-style probabilities [PR09]handle Plog-style probabilities [PR09]

Page 36: Environments for Tabled Prolog: Progress and Open Issues

#9 Better ASP integration#9 Better ASP integration

* Using XASP, query evaluation may perform grounding, and * Using XASP, query evaluation may perform grounding, and may identify relevent portions of the program for solvingmay identify relevent portions of the program for solving

-- e.g. for inferences from ontologies, not all of the A-box -- e.g. for inferences from ontologies, not all of the A-box or T-box or T-box isaisa hierarchy may need to be materialized hierarchy may need to be materialized

* At the same time, a programmer has to have a priori * At the same time, a programmer has to have a priori knowledge knowledge

-- what parts of the program require a full ASP semantics-- what parts of the program require a full ASP semantics-- that the partial stable model obtained from the query -- that the partial stable model obtained from the query reduct is semantically valid (e.g. can be extended into reduct is semantically valid (e.g. can be extended into one or more total stable models)one or more total stable models)

* How can modules (or some other constructs) be made to * How can modules (or some other constructs) be made to support the notion that various queries have useful partial support the notion that various queries have useful partial stable models? stable models?

* Currently, XSB does not evaluate cardinality or weight * Currently, XSB does not evaluate cardinality or weight constraints, and so rules with such constraints must be constraints, and so rules with such constraints must be passed to Smodels separatelypassed to Smodels separately

Page 37: Environments for Tabled Prolog: Progress and Open Issues

* Suppose we want to annotate an answer with an explicit * Suppose we want to annotate an answer with an explicit truth valuetruth value

* If * If p(a):truep(a):true and and p(a):falsep(a):false are both derived, then the table are both derived, then the table should only contain should only contain p(a):topp(a):top -- which wasn’t directly -- which wasn’t directly derivedderived

* This can be performed through a mechanism called * This can be performed through a mechanism called answer subsumption (for want of a better name)answer subsumption (for want of a better name)

#10 Making answer subsumption usable by real #10 Making answer subsumption usable by real programmersprogrammers

Page 38: Environments for Tabled Prolog: Progress and Open Issues

#10 Making answer subsumption usable#10 Making answer subsumption usable

* Consider a model of quantitative degrees of belief * Consider a model of quantitative degrees of belief [van86]. An annotated atom [van86]. An annotated atom A:[EA:[ETT,E,EFF]] is an atom is an atom AA is is annotated with annotated with

-- -- EETT, a number between 0 and 1 indicating a , a number between 0 and 1 indicating a measure of evidence that measure of evidence that A A is true; and is true; and -- -- EEFF, a number between 0 and 1 indicating that , a number between 0 and 1 indicating that AA is is false. false. -- [-- [EETT E EFF] join [E] join [ETT E EFF] = [] = [ max(Emax(ETT E ETT),max( E),max( EFF E EFF)])]

* Resolution for these annotated literals can be defined. * Resolution for these annotated literals can be defined. The main idea is:- A goal The main idea is:- A goal A:[EA:[ETT,E,EFF]] is true in an is true in an interpretation interpretation JJ of a program of a program PP if there is are rules if there is are rulesAAII::[E[EII

TT,E,EIFIF] :- Body] :- BodyIIin in PP such that each A such that each AII unifies with unifies with A, A, each each BodyBodyII is true inis true in J, [E’ J, [E’TT,E’,E’FF] = join [E] = join [EII

TT,E,EIIFF], E'], E'TT >= E >= ETT

and and FFTT =< F' =< F'TT

Page 39: Environments for Tabled Prolog: Progress and Open Issues

#10 Making answer subsumption usable#10 Making answer subsumption usable

* Generalizing this approach to upper semi-lattices, you * Generalizing this approach to upper semi-lattices, you get get Generalized Annotated Programs Generalized Annotated Programs (GAPs) [KS92] that (GAPs) [KS92] that can model many kinds of quantitative, paraconsistent, can model many kinds of quantitative, paraconsistent, and temporal reasoning.and temporal reasoning.* From our perspective, GAPs can be implemented using * From our perspective, GAPs can be implemented using answer subsumption [Swi99]. To illustrate on ground answer subsumption [Swi99]. To illustrate on ground programs, when an answer programs, when an answer A:[anA:[annewnew] ] is derived:-- Add is derived:-- Add A:A:[an[annewnew] ] if the table does not have an answer with if the table does not have an answer with substitution substitution AA; or-- Add ; or-- Add A:[anA:[anjoinjoin]] -- the join of -- the join of anannewnew and and ananoldold where where A:[anA:[anoldold]] is the answer for is the answer for AA in the table. in the table.

* This formalism is similar to others, such as * This formalism is similar to others, such as Residuated Lattice Programs {DP01]Residuated Lattice Programs {DP01]

* XSB has a meta-interpreter for stratified GAP’s in its gap * XSB has a meta-interpreter for stratified GAP’s in its gap librarylibrary

Page 40: Environments for Tabled Prolog: Progress and Open Issues

#10 Making answer subsumption usable#10 Making answer subsumption usable

* Answer subsumption essentially depends on a * Answer subsumption essentially depends on a destructive tabling operation -- it may be fairly easily destructive tabling operation -- it may be fairly easily implementable in YAP or B Prologimplementable in YAP or B Prolog

* Answer subsumption can also handle some lattices * Answer subsumption can also handle some lattices used for program analysis, so that perhaps tabling can used for program analysis, so that perhaps tabling can be used for some of the previous analysis techniquesbe used for some of the previous analysis techniques

* Constraints can be tabled -- so that the join of * Constraints can be tabled -- so that the join of different constraints for an answers can be maintaineddifferent constraints for an answers can be maintained

-- This works in theory, but needs more testing -- This works in theory, but needs more testing before I can recommend people use it.before I can recommend people use it.

* But right now answer subsumption in XSB is ugly and * But right now answer subsumption in XSB is ugly and hard to usehard to use

Page 41: Environments for Tabled Prolog: Progress and Open Issues

#10 Making answer subsumption usable#10 Making answer subsumption usable

reachable(InConf,NewConf):- reachable(InConf,NewConf):- filterPOA(reachable(InConf),Conf,gte_omega,omega_abstr,call_abstfilterPOA(reachable(InConf),Conf,gte_omega,omega_abstr,call_abstr),r), hasTransition(Conf,NewConf).reachable(InConf,NewConf):- hasTransition(Conf,NewConf).reachable(InConf,NewConf):- hasTransition(InConf,NewConf)hasTransition(InConf,NewConf)

* filterPOA/5 * filterPOA/5 is somewhat arcane. is somewhat arcane. -- 1st argument: call (minus argument to be subsumed)-- 1st argument: call (minus argument to be subsumed)-- 2nd argument: argument to be subsumed-- 2nd argument: argument to be subsumed-- 3rd argument: comparison function (for subsumption)-- 3rd argument: comparison function (for subsumption)-- 4th argument: abstraction function for answer-- 4th argument: abstraction function for answer-- 5th argument: abstraction function to find relevant -- 5th argument: abstraction function to find relevant answers from subgoalanswers from subgoal

* This is the most complicated of the XSB answer subsumption * This is the most complicated of the XSB answer subsumption predicates. Other predicates do not require the 4th and 5th predicates. Other predicates do not require the 4th and 5th argumentsarguments

Page 42: Environments for Tabled Prolog: Progress and Open Issues

ConclusionsConclusions

Because tables require space and are based on a given state of the Because tables require space and are based on a given state of the environment issues arise for environment issues arise for

-- table management-- table management-- automatic table updating-- automatic table updating

It should be possible to partially automate or assist choices of It should be possible to partially automate or assist choices of -- what to table-- what to table-- what data structure to use-- what data structure to use-- what search strategy to use-- what search strategy to use-- how to transform a program to one that is efficiently executed-- how to transform a program to one that is efficiently executed

Tabling can support more powerful semantics than Prolog alone Tabling can support more powerful semantics than Prolog alone leading to questions of how to leading to questions of how to

-- debug-- debug-- implement transformation-based semantics and constructs in -- implement transformation-based semantics and constructs in an easy-to-use, cognitively clear manneran easy-to-use, cognitively clear manner-- unite a query-based system with stable model generation-- unite a query-based system with stable model generation-- allow users to easily exploit answer subsumptions ability to join -- allow users to easily exploit answer subsumptions ability to join the results of derivations and to abstract answersthe results of derivations and to abstract answers

Page 43: Environments for Tabled Prolog: Progress and Open Issues

References

[ADP94] J. Alferes, C. V. Dam´asio, and L. M. Pereira. A top-down query evaluation for well-founded semantics with explicit negation. In European Conference on Artificial Intelligence, pages 140–144. Morgan Kaufmann, 1994.

[CR09] J. Costa and R. Rocha. One table fits all. In Practical Applications of Declarative Languages, pages 195–208, 2009.

[CS02] B. Cui and T. Swift. Preference logic programs: Fixed-point semantics and application to data standardization. Artificial Intelligence, 138:117–147, 2002.

[CSL07] V. Santos Costa, K. Sagonas, and R. Lopes. Demand-driven indexing of prolog clauses. In Proceedings of the 23rd International Conference Logic Programming, pages 395–409. Springer, 2007.

[DP01] C. V. Dam´asio and L. Pereira. Monotonic and residuated logic programs. In ECSQARU, pages 748–759, 2001.

[Ear70] Jay Earley. An efficient context-free parsing algorithm. Communications of the ACM, 13(2):94–102, 1970.

[FSW98] J. Freire, T. Swift, and D. S. Warren. Beyond depth-first: Improving tabled logic programs through alternative scheduling strategies. Journal of Functional and Logic Programming, 1998(3), 1998.

[GJM95] K. Govindarajan, B. Jayaraman, and S. Mantha. Preference logic programming. In International Conference on Logic Programming, pages 731–746, 1995.

[GST+00] J. Gartner, T. Swift, A. Tien, L. M. Pereira, and C. Dam´asio. Psychiatric diagnosis from the viewpoint of computational logic. In 8th International Workshop on Non-Monotonic Reasoning, 2000.

[JRRR99] E. Johnson, C.R. Ramakrishnan, I.V. Ramakrishnan, and P. Rao. A space-efficient engine for subsumption based tabled evaluation of logic programs. In 4th International Symposium on Functional and Logic Programming, 1999.

Page 44: Environments for Tabled Prolog: Progress and Open Issues

[KS92] M. Kifer and V. S. Subrahmanian. Theory of generalized annotated logic programming and its applications. Journal of Logic Programming, 12(4):335–368, 1992.

[LMP08] P. Dell’Acqua L. M. Pereira, Gonalo Lopes. On preferring and inspecting abductive models. In Practical Applications of Declarative Languages, 2008.

[Nau88] J. Naughton. Compiling separable recursions. In SIGMOD, pages 312–319, 1988.

[Nau89] J. Naughton. Data independent recursion in deductive databases. J. Computer and System Sciences, 38:259-289, 1989.

[PA09] L. M. Pereira and H. T. Anh. Evolution prospection. In KES-IDT, 2009.

[PGD+04] G. Pemmasani, H. Guo, Y. Dong, C. R. Ramakrishnan, and I. V. Ramakrishnan. Online justification for tabled logic programs. In FLOPS, 2004.

[PL07] L. M. Pereira and G Lopes. Prospective logic agents. In EPIA, pages 73–86, 2007.

[PP95] M. Proetti and A. Petterossi. Unfolding - definition - folding, in that order, for avoiding unecessary variables in logic programs. Theoretical Computer Science, 142:89–124, 1995.

[PR09] L. M. Pereira and Carroline Ramli. Modelling probabilistic causation in decision making. In KES-IDT, 2009.

[PSE09] E. Pontelli, T.C. Son, and O. Elkatib. Justifications for logic programs under the answer set semantics. Theory and Practice of Logic Programming, 9:1–56, 2009.

Page 45: Environments for Tabled Prolog: Progress and Open Issues

[Roc07] R. Rocha. On Improving the Efficiency and Robustness of Table Storage Mechanisms for Tabled Evaluation. In Practical Applications of Declarative Languages, pages 155–169, 2007.

[RRR96] P. Rao, C.R. Ramakrishnan, and I.V. Ramakrishnan. A thread in time saves tabling time. In Joint International Conference/Symposium on Logic Programming, 1996.

[RSC05] R. Rocha, F. Silva, and V. Santos Costa. Dynamic mixed-strategy evaluation of tabled logic programs. In International Conference on Logic Programming, page 250264, 2005.

[Sah06] D. Saha. Incremental Evaluation of Tabled Logic Programs. PhD thesis, SUNY Stony Brook, 2006.

[SvL08] K. Stenning and M. van Lambalgen. Human Reasoning and Cognitive Science. MIT Press, 2008.

[Swi99] T. Swift. Tabling for non-monotonic programming. Annals of Mathematics and Artificial Intelligence, 25(3-4):201–240, 1999.

[Swi09] T. Swift. An engine for efficiently computing (sub-)models. In International Conference on Logic Programming, 2009.

[van86] M. van Emden. Quantitative deduction and its fixpoint theory. Journal of Logic Programming, 4:37–53, 1986.

Page 46: Environments for Tabled Prolog: Progress and Open Issues
Page 47: Environments for Tabled Prolog: Progress and Open Issues

#8 Treating the table as (readable) data#8 Treating the table as (readable) data

* Given a term T, users can inspect tabled subgoals that are * Given a term T, users can inspect tabled subgoals that are variants of T, subsume T, are subsumed by T, or unify with T; variants of T, subsume T, are subsumed by T, or unify with T; users may want to determine whether these tables are users may want to determine whether these tables are complete, and associate answers with the subgoalcomplete, and associate answers with the subgoal

* Given a set of subgoals S, users may wish to find the * Given a set of subgoals S, users may wish to find the residual subprogram reachable from S, as well as its strongly residual subprogram reachable from S, as well as its strongly connected componentsconnected components

-- Reachability can be from heads to body literals, or -- Reachability can be from heads to body literals, or -- Reachability can be from body literals to heads-- Reachability can be from body literals to heads

* Mostly handled in XSB, but not always efficiently or cleanly * Mostly handled in XSB, but not always efficiently or cleanly (e.g. attributed variables in tables are not always passed (e.g. attributed variables in tables are not always passed back by table inspection routinesback by table inspection routines

* Users may wish to ground a residual program (no interface * Users may wish to ground a residual program (no interface yet)yet)


Recommended