Description and Evaluation of a Generic Design to Integrate CLP and - - PowerPoint PPT Presentation

description and evaluation of a generic design to
SMART_READER_LITE
LIVE PREVIEW

Description and Evaluation of a Generic Design to Integrate CLP and - - PowerPoint PPT Presentation

www.software.imdea.org Description and Evaluation of a Generic Design to Integrate CLP and Tabled Execution Joaqun Arias 1 , 2 Manuel Carro 1 , 2 1 IMDEA Software Institute, 2 Technical University of Madrid 1 / 23 www.software.imdea.org


slide-1
SLIDE 1

1 / 23

www.software.imdea.org

Description and Evaluation of a Generic Design to Integrate CLP and Tabled Execution

Joaquín Arias1,2 Manuel Carro1,2

1IMDEA Software Institute, 2Technical University of Madrid

slide-2
SLIDE 2

1 / 23

www.software.imdea.org

Integration of CLP and Tabled Execution

  • TCLP is an extension of Prolog which combines the benefits of:

CLP: Reduce search, add expressiveness. Tabling: Detect loops, avoid recomputation.

  • Our design, Modular TCLP

, facilitates the connection of CLP solvers with tabling.

  • The interface is implemented in Ciao Prolog, a system with tabling and CLP

.

  • To validate our design we implemented the interface of several CLP solvers.

Tabling engine Modular TCLP Interface Prolog-based CLP solver External CLP solver WAM

madrid institute for advanced studies in software development technologies

slide-3
SLIDE 3

2 / 23

www.software.imdea.org

Background & Motivation

Example: Find nodes in a weighted graph within a distance K from each other

n 1 2 3 4

Comparison of termination properties of similar programs: Written using: Prolog | CLP | Tabling | TCLP. Traversal: Acyclic graphs | Cyclic graphs. With: Right recursion | Left recursion.

madrid institute for advanced studies in software development technologies

slide-4
SLIDE 4

3 / 23

www.software.imdea.org

Background & Motivation - Prolog vs CLP

Example: Find nodes in a weighted graph within a distance K from each other

Prolog

                                    

d i s t (X,Y,D) : edge (X, Z ,D1) , d i s t (Z ,Y,D2) , D i s D1 + D2. d i s t (X,Y,D) : edge (X,Y,D) . edge (1 ,2 ,50). edge ( . . . ? d i s t (1 ,Y,D) , D < 150 .

CLP

                                    

: use_package ( clpq ) . d i s t (X,Y,D) : D1 #> 0 , D2 #> 0 , D #= D1 + D2 , edge (X, Z ,D1) , d i s t (Z ,Y,D2 ) . d i s t (X,Y,D) : edge (X,Y,D) . ? D #< 150 , d i s t (1 ,Y,D) .

madrid institute for advanced studies in software development technologies

slide-5
SLIDE 5

3 / 23

www.software.imdea.org

Background & Motivation - Prolog vs CLP

Example: Find nodes in a weighted graph within a distance K from each other

Prolog

                                    

d i s t (X,Y,D) : edge (X, Z ,D1) , d i s t (Z ,Y,D2) , D i s D1 + D2. d i s t (X,Y,D) : edge (X,Y,D) . edge (1 ,2 ,50). edge ( . . .

CLP

                                    

: use_package ( clpq ) . d i s t (X,Y,D) : D1 #> 0 , D2 #> 0 , D #= D1 + D2 , edge (X, Z ,D1) , d i s t (Z ,Y,D2 ) . d i s t (X,Y,D) : edge (X,Y,D) .

Prolog CLP Left recursion x x Without Right recursion

X X

cycles Left recursion x x With Right recursion x

X

cycles madrid institute for advanced studies in software development technologies

slide-6
SLIDE 6

4 / 23

www.software.imdea.org

Background & Motivation - Prolog vs Tabling

Example: Find nodes in a weighted graph within a distance K from each other

Prolog

                                    

d i s t (X,Y,D) : edge (X, Z ,D1) , d i s t (Z ,Y,D2) , D i s D1 + D2. d i s t (X,Y,D) : edge (X,Y,D) . edge (1 ,2 ,50). edge ( . . . ? d i s t (1 ,Y,D) , D < 150.

Tabling

                                    

: use_package ( t a b l i n g ) . : table d i s t / 3 . d i s t (X,Y,D) : d i s t (X, Z ,D1) , edge (Z ,Y,D2) , D i s D1 + D2. d i s t (X,Y,D) : edge (X,Y,D) . ? d i s t (1 ,Y,D) , D < 150.

madrid institute for advanced studies in software development technologies

slide-7
SLIDE 7

4 / 23

www.software.imdea.org

Background & Motivation - Prolog vs Tabling

Example: Find nodes in a weighted graph within a distance K from each other

Prolog

                                    

d i s t (X,Y,D) : edge (X, Z ,D1) , d i s t (Z ,Y,D2) , D i s D1 + D2. d i s t (X,Y,D) : edge (X,Y,D) . edge (1 ,2 ,50). edge ( . . .

Tabling

                                    

: use_package ( t a b l i n g ) . : table d i s t / 3 . d i s t (X,Y,D) : d i s t (X, Z ,D1) , edge (Z ,Y,D2) , D i s D1 + D2. d i s t (X,Y,D) : edge (X,Y,D) .

Prolog Tabling Left recursion x

X

Without Right recursion

X X

cycles Left recursion x x With Right recursion x x cycles madrid institute for advanced studies in software development technologies

slide-8
SLIDE 8

5 / 23

www.software.imdea.org

Background & Motivation - TCLP (with entailment)

Example: Find nodes in a weighted graph within a distance K from each other

TCLP

                                              

: use_package ( t a b l i n g ) . : use_package ( t_clpq ) . : table d i s t / 3 . d i s t (X,Y,D) : D1 #> 0 , D2 #> 0 , D #= D1 + D2, d i s t (X, Z ,D1) , edge (Z ,Y,D2 ) . d i s t (X,Y,D) : edge (X,Y,D) . ? D #< 150 , d i s t (1 ,Y,D) .

madrid institute for advanced studies in software development technologies

slide-9
SLIDE 9

5 / 23

www.software.imdea.org

Background & Motivation - TCLP (with entailment)

Example: Find nodes in a weighted graph within a distance K from each other

TCLP

                                              

: use_package ( t a b l i n g ) . : use_package ( t_clpq ) . : table d i s t / 3 . d i s t (X,Y,D) : D1 #> 0 , D2 #> 0 , D #= D1 + D2, d i s t (X, Z ,D1) , edge (Z ,Y,D2 ) . d i s t (X,Y,D) : edge (X,Y,D) . ? D #< 150 , d i s t (1 ,Y,D) .

Prolog TCLP Left recursion x

X

Without Right recursion

X X

cycles Left recursion x

X

With Right recursion x

X

cycles madrid institute for advanced studies in software development technologies

slide-10
SLIDE 10

5 / 23

www.software.imdea.org

Background & Motivation - TCLP (with entailment)

Example: Find nodes in a weighted graph within a distance K from each other

TCLP

                                              

: use_package ( t a b l i n g ) . : use_package ( t_clpq ) . : table d i s t / 3 . d i s t (X,Y,D) : D1 #> 0 , D2 #> 0 , D #= D1 + D2, d i s t (X, Z ,D1) , edge (Z ,Y,D2 ) . d i s t (X,Y,D) : edge (X,Y,D) . ? D #< 150 , d i s t (1 ,Y,D) .

Graph

                  

edge (1 ,2 ,50). edge (2 ,1 ,D) : D #> 30 , D #< 60. edge ( . . .

Prolog TCLP Left recursion x

X

Without Right recursion

X X

cycles Left recursion x

X

With Right recursion x

X

cycles madrid institute for advanced studies in software development technologies

slide-11
SLIDE 11

6 / 23

www.software.imdea.org

Background & Motivation

Example: Find nodes in a weighted graph within a distance K from each other

Prolog CLP Tabling TCLP Left recursion x x

X X

Without Right recursion

X X X X

cycles Left recursion x x x

X

With Right recursion x

X

x

X

cycles

Termination properties of similar programs.

n 1 2 3 4 madrid institute for advanced studies in software development technologies

slide-12
SLIDE 12

7 / 23

www.software.imdea.org

Background & Motivation - Applications

Abstract interpretation: Tabling reaches the fixpoint. The constraint solvers detect more particular calls and make it possible to state preconditions. Reasoning on ontologies: Tabling makes it possible to define terminating left-recursive rules. The constraint solver formalize the types, properties, and interrelationships defined in the ontologies. Constraint-based verification: Tabling ensures termination and saves execution

  • time. The constraint solvers encode verification rules.

madrid institute for advanced studies in software development technologies

slide-13
SLIDE 13

7 / 23

www.software.imdea.org

Background & Motivation - Applications

Abstract interpretation: Tabling reaches the fixpoint. The constraint solvers detect more particular calls and make it possible to state preconditions. Reasoning on ontologies: Tabling makes it possible to define terminating left-recursive rules. The constraint solver formalize the types, properties, and interrelationships defined in the ontologies. Constraint-based verification: Tabling ensures termination and saves execution

  • time. The constraint solvers encode verification rules.

Different types of problems may require different constraint domains / solvers. Integrating constraint solvers and tabling brings many advantages.

madrid institute for advanced studies in software development technologies

slide-14
SLIDE 14

8 / 23

www.software.imdea.org

Background & Motivation - Previous Work

DatalogD Theoretical bases (Bottom-up evaluation) (Toman [1997]) XSB’s TCLP Does not use call entailment check (Cui and Warren [2000]) Tabled Constraint Handling Rules (TCHR) (in XSB). Removes the constraints from calls (Schrijvers et al. [2008]) Tabled Constraint Logic Programming (TCLP) (in Ciao Prolog) Is an Ad-hoc interface for disequality and difference constraints

(Chico de Guzmán et al. [2012]) madrid institute for advanced studies in software development technologies

slide-15
SLIDE 15

9 / 23

www.software.imdea.org

Design of the Interface - Operations from the Constraint Solvers

Projection: Used to obtain an “equivalent” constraint store involving only the variables that appear in the call. Projection of {D  150, D1 > 0, D2 > 0, D = D1 + D2} onto D1 is {D1 > 0, D1 < 150} Entailment: Used to detect a more particular call (which will reuse the solutions

  • f a more general one) and to discard redundant answers.

{D1 > 0, D1 < 150} v {D1  150} Variant Entailment Generator dist(1,X,D )

hdist(1,X,D ), {D  150}i

Consumer dist(1,Z,D1)

hdist(1,X,D1), {D1 > 0, D1< 150}i

Add constraints: Used to apply the answer from a call to the current store and check its consistency.

madrid institute for advanced studies in software development technologies

slide-16
SLIDE 16

10 / 23

www.software.imdea.org

Design of the Interface - Generic interface specification

store_projection(+Vars, -ProjStore) call_entail(+Vars, +ProjStore, +ProjStoregen) answer_compare(+Vars, +ProjStore, +ProjStoreans, -Res) apply_answer(+Vars, +ProjStore) current_store(+Vars, +ProjStore, -CuSt) reinstall_store(+Vars, +CuSt)

madrid institute for advanced studies in software development technologies

slide-17
SLIDE 17

11 / 23

www.software.imdea.org

Design of the Interface - The Flowchart

tabled call lookup table 1 store projection 2 retrieve projection 3 current store 4 save generator 5 call entail 6 suspend consumer 7 execute generator 8 lookup table 9 store projection 10 retrieve projection 11 save answer 12 answer compare 13 remove answer 14 reinstall store 15 retrieve answer 16 apply answer 17 no yes no yes new answer no yes >  fails resume complete yes no fails success

madrid institute for advanced studies in software development technologies

slide-18
SLIDE 18

12 / 23

www.software.imdea.org

Validation of the Design

CLP(D) We re-engineered the previously existing constraint solver for difference constraint completely written in C and used in the initial TCLP implementation. CLP(Q) and CLP(R) We integrated the constraint solver for linear equations over rationals (CLP(Q)) and over reals (CLP(R)) (Holzbaur [1995]). CLP(Lat) We implemented and integrated a new constraint solver over finite lattices.

madrid institute for advanced studies in software development technologies

slide-19
SLIDE 19

13 / 23

www.software.imdea.org

Validation of the Design - Modular TCLP interface for CLP(Q)

: use_package ( . . . : active_tclp . store_projection (V, (F, St ) ) : clpqr_dump_constraints (V, F, St ) . c a l l _ e n t a i l (V, _ , (V, StGen ) ) : clpq_entailed (StGen ) . answer_compare (V, _ , (V, StAns ) , =<) : clpq_entailed ( StAns ) , ! . answer_compare (_ , (F, St ) , (F, StAns ) , >) : clpq_meta ( StAns ) , clpq_entailed ( St ) . apply_answer (V, (V, St ) ) : clpq_meta ( St ) .

madrid institute for advanced studies in software development technologies

slide-20
SLIDE 20

13 / 23

www.software.imdea.org

Validation of the Design - Modular TCLP interface for CLP(Q)

: use_package ( . . . : active_tclp . store_projection (V, (F, St ) ) : clpqr_dump_constraints (V, F, St ) . c a l l _ e n t a i l (V, _ , (V, StGen ) ) : clpq_entailed (StGen ) . answer_compare (V, _ , (V, StAns ) , =<) : clpq_entailed ( StAns ) , ! . answer_compare (_ , (F, St ) , (F, StAns ) , >) : clpq_meta ( StAns ) , clpq_entailed ( St ) . apply_answer (V, (V, St ) ) : clpq_meta ( St ) .

A bridge to existing predicates

madrid institute for advanced studies in software development technologies

slide-21
SLIDE 21

14 / 23

www.software.imdea.org

Performance evaluation - Initial TCLP vs Modular TCLP

CLP(D) Initial TCLP(D) Modular TCLP(D) truckload(300) 40452 2903 7268 truckload(200) 4179 1015 2239 truckload(100) 145 140 259 step_bound(30)

  • 2657

1469 step_bound(20)

  • 2170

1267 step_bound(10)

  • 917

845

Run time (ms) for truckload/4 and step_bound/4, parametrized by Load and Limit resp.

truckload(30, Load, chicago, Time), solves a shipment problem. step_bound(X, Y, Steps, Limit), is a left-recursive graph reachability program.

madrid institute for advanced studies in software development technologies

slide-22
SLIDE 22

15 / 23

www.software.imdea.org

Performance evaluation - Answer Management Strategy

Save all Discard new answer Remove previous Discard and remove

Time Ans. Time Ans. Time Ans. Time Ans.

truckload(300) 742039 14999 7806 41 7780 30 7268 5 truckload(200) 11785 1520 2314 23 2354 18 2239 5 truckload(100) 300 58 263 6 263 9 259 3 step_bound(30) – – 8450 252 – – 1469 25 step_bound(20) – – 6859 242 38107 441 1267 25 step_bound(10) – – 2846 165 8879 221 845 25

Run time (ms) and total # answers returned. A ‘–’ “means out of memory”. Save all: {..., D=50, D<60, D<35, ...} Discard new answer: {..., D=50, D<60, ...} Remove previous: {..., D=50, D<60, D<35, ...} Discard and remove: {..., D=50, D<60, ...}

madrid institute for advanced studies in software development technologies

slide-23
SLIDE 23

16 / 23

www.software.imdea.org

Performance evaluation - Answer Management Strategy

Execution of truckload(30, 300, chicago, Time).

Save all Discard new Remove previous Discard remove 101 102 103 104 105 106 4.49 · 105 67,503 75,272 48,524 9,971 6,596 9,460 1,740 14,999 41 30 5 number of answers (log.)

Saved Discarded Removed Returned

madrid institute for advanced studies in software development technologies

slide-24
SLIDE 24

17 / 23

www.software.imdea.org

Performance evaluation - Answer Management Strategy

Execution of step_bound(X, Y, Steps, 20).

Discard new Remove previous Discard remove 101 102 103 104 105 106 37,548 9.46 · 105 9,352 5.99 · 105 71,658 8.91 · 105 4,371 242 441 25 number of answers (log.)

Saved Discarded Removed Returned

madrid institute for advanced studies in software development technologies

slide-25
SLIDE 25

18 / 23

www.software.imdea.org

Performance evaluation - Prolog vs CLP(Q) vs Tabling vs TCLP(Q)

Example: Find nodes in a weighted graph within a distance K from each other

Prolog CLP(Q) Tabling TCLP(Q) Left recursion – – 144 45 Without Right recursion 1917 200 291 184 cycles1 Left recursion – – – 420 With Right recursion – 4261 – 1027 cycles2

Run time (ms) for dist/3. A ‘–’ means no termination.

n 1 2 3 4

1Graph of 25 nodes and 584 edges. 2Graph of 25 nodes and 785 edges.

madrid institute for advanced studies in software development technologies

slide-26
SLIDE 26

19 / 23

www.software.imdea.org

Performance evaluation - Tabling vs TCLP(Lat)

We implemented a simple Abstract Interpreter which executes the programs to be analyzed, using an abstract domain, until a fixpoint is reached.

top num

±

0+

  • +

bottom var str atom

Sign abstract domain.

t(x1, x2, . . . , xn) = i f x1  x2 then x2 else t(t(x1 1, x2, . . . , xn), . . . , t(xn 1, x1, . . . , xn1)) takeuchi(X1, X2, ..., _Xn, R) : X1 < X2, R = X2 . takeuchi(X1, X2, ..., _Xn, R) : X1 =:= X2, R = X2 . takeuchi(X1, X2, ..., Xn, R) : X1 > X2, N1 is X1 1, takeuchi(N1, X2, ..., Xn, R1 ) , N2 is X2 1, takeuchi(N2, X3, ..., X1, R2 ) , . . . , Nn is Xn 1, takeuchi(Nn, X1, ..., Xn1, Rn ) , takeuchi(R1, R2, ..., Rn, R).

n-dimensional Takeuchi function (Knuth [1991]) and its implementation.

madrid institute for advanced studies in software development technologies

slide-27
SLIDE 27

20 / 23

www.software.imdea.org

Performance evaluation - Tabling vs TCLP(Lat)

We compare two version of the Abstract Interpreter: Tabling This version uses the variant-base check of tabling. TCLP(Lat) The entailment check provided by TCLP(Lat) suspends and saves computation time using results from a previous, more general, call. Tabling TLCP(Lat) analyze(takeuchi/9) 31.44 8.09 analyze(takeuchi/7) 13.75 5.85 analyze(takeuchi/4) 2.42 3.12

Run time (ms) for analyze(takeuchi/m)

madrid institute for advanced studies in software development technologies

slide-28
SLIDE 28

21 / 23

www.software.imdea.org

TCLP( \=)

  • = Constructive unification.
  • \= Constructive disunification.

(At least one of the argument must be ground)

  • v Entailment.
  • A \= [1] v B \= [1,2,...]

NegA ✓ NegB

  • A \= [1,2] v B = 3

· · · v B = p(X) 8Ai 2 NegA . Ai \= B

  • f(A1, . . . , An) v f(B1, . . . , Bn)

Ai v Bi, (1  i  n)

  • Lattice:
  • ^ Join.
  • _ Meet.

\=[] \=[1] \=[1,3] \=[1,2] \=[1,4] =3 =4 =2 bottom

. . . f/n . . . . . .

madrid institute for advanced studies in software development technologies

slide-29
SLIDE 29

22 / 23

www.software.imdea.org

Conclusion

  • The interface only requires three operations from the constraint solver and covers

many possible implementations.

  • The interface implements an improved answer management strategy.
  • We integrated four constraint solvers and evaluated their performance with a

series of benchmarks.

madrid institute for advanced studies in software development technologies

slide-30
SLIDE 30

22 / 23

www.software.imdea.org

Conclusion

  • The interface only requires three operations from the constraint solver and covers

many possible implementations.

  • The interface implements an improved answer management strategy.
  • We integrated four constraint solvers and evaluated their performance with a

series of benchmarks.

Further Work

Abstract Interpreter: Perform a more extensive evaluation with additional abstract domains. Reasoning over Ontologies: Extend CLP(Lat) to implement a reasoning system which reuses more general concepts and combines answers into more general concepts. CLP(FD): It is expensive to calculate projection and entailment inside CLP(FD) but partial projection can be used to check call entailment.

madrid institute for advanced studies in software development technologies

slide-31
SLIDE 31

23 / 23

www.software.imdea.org

Questions

madrid institute for advanced studies in software development technologies

slide-32
SLIDE 32

24 / 23

www.software.imdea.org

Bibliography

P . Chico de Guzmán, M. Carro, M. Hermenegildo, and P . Stuckey. A General Implementation Framework for Tabled CLP. In Tom Schrijvers and Peter Thiemann, editors, FLOPS’12, number 7294 in LNCS, pages 104–119. Springer Verlag, May 2012. Baoqiu Cui and David Scott Warren. A System for Tabled Constraint Logic

  • Programming. In Computational Logic, pages 478–492, 2000.
  • C. Holzbaur. OFAI clp(q,r) manual, edition 1.3.3. Technical Report TR-95-09,

Austrian Research Institute for Artificial Intelligence, Vienna, 1995. Donald E Knuth. Textbook examples of recursion. Artificial Intelligence and Mathematical Theory of Computation: Papers in Honor of John McCarthy, pages 207–230, 1991. Tom Schrijvers, Bart Demoen, and David Scott Warren. TCHR: a Framework for Tabled CLP. TPLP, 8(4):491–526, 2008. David Toman. Memoing Evaluation for Constraint Extensions of Datalog. Constraints, 2(3/4):337–359, 1997.

madrid institute for advanced studies in software development technologies