Presentation is loading. Please wait.

Presentation is loading. Please wait.

Andy King Computing Laboratory University of Kent at Canterbury

Similar presentations


Presentation on theme: "Andy King Computing Laboratory University of Kent at Canterbury"— Presentation transcript:

1 A Goal-Independent Suspension Analysis for Logic Programs with Dynamic Scheduling
Andy King Computing Laboratory University of Kent at Canterbury Samir Genaim Universita’ degli Studi di Verona Italy Abstract. The talk will describe a goal-independent analysis that infers a class of goals which ensure that a ccp program, or a logic program with delay, can be executed without suspension. The crucial point is that the analysis does not verify that an (abstract) goal does not lead to non-suspension but infers (abstract) goals that do not lead to non-suspension. Put simply, the analysis is to suspension analysis what termination inference [Mesnard and Neumerkel01] is to termination analysis. The analysis has applications in debugging and program optimisation. 09/12/2018

2 Background Since the early days of abstract interpretation, the connection between backward reasoning and debugging has been known [Cousot82, Bourdoncle93] Forward reasoning is usually applied in ccp and clp to verify that certain properties hold [Ciao-Prolog] Forward analysis checks that a certain property holds for a given (abstract) query In the context of clp, backward analysis infers properties that the query must satisfy for the program to satisfy certain requirements 09/12/2018

3 Forward suspension analysis
Suspension analysis [Codognet90, Codish94] checks that a class of goals will not lead to suspension These analyses use local fixpoints [Codognet90] or star-abstractions to avoid the state-space explosion that arises from goal interleaving In the context of the ccp language Janus, Debray [Debray96] checks that a program does not suspend by attempting to schedule atoms left-to-right 09/12/2018

4 Backward suspension analysis
The advantage of backward suspension analysis is that the programmer need not rerun the analysis for different (abstract) queries The programmer need not even be aware of how to invoke the program, thus zero effort to apply. Analysis infers where depth-first scheduling can be (locally) applied without compromising suspension Conditions sufficient for depth-first scheduling are reported to the programmer; these conditions guarantee non-suspension and hint at where efficiency can be improved [Parlog] 09/12/2018

5 Example analysis for inorder (Prolog with delay style)
inorder(nil,[]). inorder(tree(L,V,R),I) :- app(LI,[V|RI],I), inorder(L,LI), inorder(R,RI). :- block app(-, ?, -). app([], X, X). app([X|Xs], Ys, [X|Zs]) :- app(Xs,Ys,Zs). 09/12/2018

6 Example analysis for inorder (ccp style)
inorder(T, I) :- true : T = nil, I = [] : true. T = tree(L,V,R), A = [V|RI] : app(LI,A,I), inorder(L,LI), inorder(R,RI). app(L, Ys, A) :- nonvar(L) V nonvar(A): L = [], A = Ys : true. nonvar(L) V nonvar(A): L = [X|Xs], A = [X|Zs] : app(Xs,Ys,Zs). 09/12/2018

7 Pos abstraction for inorder
inorder(T, I) :- true : T /\ I. T  (L /\ V /\ R), A  (V /\ RI) : app(LI,A,I), inorder(L,LI), inorder(R,RI). app(L, Ys, A) :- L \/ A : L /\ (A  Ys) : true. L \/ A : L  (X /\ Xs), A  (X /\ Zs) : app(Xs,Ys,Zs). Note that asks are abstracted from below whereas tells are abstracted from above 09/12/2018

8 lfp calculation The success patterns of the ccp program (and thus the Prolog with delay program) are described by the lfp of the abstract Pos program A success pattern is an atom with distinct variables for arguments paired with a Pos formula over those variables The lfp of the Pos program can be computed in TP-style to give F = { inorder(x1, x2):- x1  x2, app(x1, x2, x3) :- (x1 /\ x2)  x3 } Observe that F faithfully describes the grounding behaviour of inorder and app 09/12/2018

9 gfp calculation A gfp is computed to characterise the safe call patterns of the program A call pattern has the same syntactic form as a success pattern Iteration commences with D0 = top and incrementally strengthens the call pattern formulae until they are safe, that is, they describe queries that do not violate the ask constraints 09/12/2018

10 gfp calculation (under the microscope, part I)
Di+1 is computed from Di by considering each clause p(x) :- d : f : p1(x1),… pn(xn) in the abstract program and calculating a formula that (possibly) strengthens the call pattern Specifically, let fi denote the success pattern formula for pi(xi) in F and let di denote the call pattern formula for pi(xi) in Di Compute e = /\i = 1n (di => fi) which describes the grounding behaviour of the compound goal p1(x1),… pn(xn), Calculate e' = /\i = 1n di which describes a groundness property sufficient for scheduling the compound goal depth-first without suspension. 09/12/2018

11 gfp calculation (under the microscope, part II)
The formula e => e' then describes a grounding property which, if satisfied when the compound goal is called, ensures the goal can be scheduled depth-first without suspension Similarly, g = d /\ (f => (e => e')) describes a grounding property which ensures that the ask is satisfied and the body atoms can be scheduled depth-first without suspension Variables not present in p(x), Y = {y1,..yn} say, are then eliminated by g' = forallY1(... forallYn (g)) A safe calling mode for this particular clause is then given by g' 09/12/2018

12 gfp calculation (under the microscope, part III)
This procedure generates the following Di sequence that converges from above: D0 = top D1 = { inorder(x1, x2):- true, app(x1, x2, x3) :- x1 \/ x3 } D2 = { inorder(x1, x2):- x1 \/ x2 , D3 = D2 so that the gfp is reached and checked in 2 iterations 09/12/2018

13 Pre-requisites for backward suspension analysis
Logical implication <= coincides with the intuitionistic implication for Pos Any (abstract) domain equipped with intuitionistic implication is condensing (and vice versa) [Giacobazzi98] Backwards suspension analysis can be applied with any condensing abstract domain 09/12/2018

14 Future work Weaken requirements for ccp
Relate to [Hoarau and Mesnard99] after TPLP paper is accepted Run larger programs through 09/12/2018


Download ppt "Andy King Computing Laboratory University of Kent at Canterbury"

Similar presentations


Ads by Google