Title: A Goal-Independent Suspension Analysis for Logic Programs with Dynamic Scheduling
1A Goal-Independent Suspension Analysisfor 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.
2Background
- 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
3Forward 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
4Backward 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
5Example analysis for inorder (Prolog with delay
style)
- inorder(nil,).
- inorder(tree(L,V,R),I) -
- app(LI,VRI,I),
- inorder(L,LI),
- inorder(R,RI).
- - block app(-, ?, -).
- app(, X, X).
- app(XXs, Ys, XZs) -
- app(Xs,Ys,Zs).
6Example analysis for inorder (ccp style)
- inorder(T, I) -
- true
- T nil,
- I true.
- inorder(T, I) -
- true
- T tree(L,V,R),
- A VRI
- app(LI,A,I),
- inorder(L,LI),
- inorder(R,RI).
app(L, Ys, A) - nonvar(L) V nonvar(A) L
, A Ys true. app(L, Ys, A) -
nonvar(L) V nonvar(A) L XXs, A
XZs app(Xs,Ys,Zs).
7Pos abstraction for inorder
- inorder(T, I) -
- true
- T /\ I.
- inorder(T, I) -
- true
- 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. app(L, Ys, A) - 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
8lfp 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
9gfp 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
10gfp calculation (under the microscope, part I)
- Di1 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 gt 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.
11gfp calculation (under the microscope, part II)
- The formula e gt 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 gt (e gt 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'
12gfp 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 ,
- app(x1, x2, x3) - x1 \/ x3
- D3 D2 so that the gfp is reached and checked
in 2 iterations
13Pre-requisites for backward suspension analysis
- Logical implication lt 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
14Future work
- Weaken requirements for ccp
- Relate to Hoarau and Mesnard99 after TPLP paper
is accepted - Run larger programs through http//www.cs.bgu.ac.i
l/cgi-bin/genaim/susweb.cgi