1 / 12

Inferring Non-Suspension Conditions for Logic Programs with Dynamic Scheduling

Inferring Non-Suspension Conditions for Logic Programs with Dynamic Scheduling. Samir Genaim Universita’ degli Studi di Verona, Italy Andy King University of Kent, UK.

jeneil
Download Presentation

Inferring Non-Suspension Conditions for Logic Programs with Dynamic Scheduling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inferring Non-Suspension Conditionsfor Logic Programs with Dynamic Scheduling Samir Genaim Universita’ degli Studi di Verona, Italy Andy King University of Kent, UK The idea: Coding the control for logic programs with delay is tricky. The talk will describe an analysis for logic program with delay which aids the debugging process. The analysis does not verify that an input goal will not generate suspending sub-goals (standard approach) but rather infers a class of goals that do not lead to suspending sub-goals (new approach). Short version in European Symposium on Programming, 2003

  2. A logic program with a delay (1 of 2) | ?- inorder(T, [a,b]). T = tree(nil,a,tree(nil,b,nil)) ? ; T = tree(tree(nil,a,nil),b,nil) ? ; no | ?- 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).

  3. A logic program with a delay (2 of 2) | ?- inorder(tree(nil, a, tree(nil, b, nil)), L). Call: inorder(tree(nil,a,tree(nil,b,nil)),_285) Block: app(_808,[a|_782],_813) Call: inorder(nil,_808) ? Unblock: app([],[a|_782],_813) Call: app([],[a|_782],_813) ? Exit: app([],[a|_782],[a|_782]) ? Exit: inorder(nil,[]) ? Call: inorder(tree(nil,b,nil),_782) Block: app(_3242,[b|_3216],_3247) Call: inorder(nil,_3242) Unblock: app([],[b|_3216],_3247) Call: app([],[b|_3216],_3247) Exit: app([],[b|_3216],[b|_3216]) Exit: inorder(nil,[]) Call: inorder(nil,_3216) Exit: inorder(nil,[]) Exit: inorder(tree(nil,b,nil),[b]) Exit: inorder(tree(nil,a,tree(nil,b,nil)),[a,b]) L = [a,b] 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).

  4. Forward versus backward suspension analysis • Suspension analysis traditionally verifies that a class of goals will not lead to suspension • These analyses use local fixpoints [Codognet90] or star-abstractions [Codish94] to avoid the state-space explosion that arises from goal interleaving • One advantage of backward suspension analysis is that the programmer need not rerun the analysis for different (abstract) queries; another is automation.

  5. Example analysis for inorder (Prolog with delay and ccp style) inorder(T, I) :- true : T = nil, I = [] : true. inorder(T, 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)  nonvar(A): L = [], A = Ys : true. app(L, Ys, A) :- nonvar(L)  nonvar(A): L = [X|Xs], A = [X|Zs] : app(Xs,Ys,Zs). 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).

  6. Boolean function (Pos) abstraction 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). app(L, Ys, A) :- nonvar(L)  nonvar(A): L = [], A = Ys : true. app(L, Ys, A) :- nonvar(L)  nonvar(A): L = [X|Xs], A = [X|Zs] : app(Xs,Ys,Zs). 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). Note that asks are abstracted from below whereas tells are abstracted from above

  7. 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

  8. gfp calculation • A gfp is computed to characterise the 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 describe queries that do not violate the ask constraints: 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

  9. 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 • Then compute: • e = i = 1n (di fi) which captures the grounding behaviour of the compound goal p1(x1),… pn(xn) • e' = i = 1n di is a groundness property sufficient for scheduling the compound goal without suspension

  10. gfp calculation (under the microscope, part II) • The formula in the Di are monotonic (within Mon), that is, constructed from the connectives  and  • Proposition • Let f, fi Pos and di Mon for all i  [1, m] and suppose f |= e  e' = (i = 1i = m (di fi))  (i = 1i = m di). • Then a permutation  : [1, m]  [1, m] exists such that f  (j = 1j = i-1 f(j)) |= d(i) for all i  [1, m] • Thus compute e  e' since this is sufficient for the compound goal p1(x1),…, pn(xn) to not suspension

  11. gfp calculation (under the microscope, part III) • Likewise g = d  (f  (e  e')) is a grounding property which ensures the ask is satisfied and the body can be scheduled without suspension • Variables not present in p(x), Y = {y1,…,yn} say, are then eliminated by g' = Y1(... Yn (g)) • In fact x(f) = f’ if f’ is positive else x(f) = false where f’ = f[x  true]  f[x  false] • For example x(x  y) = y • A safe calling mode for this clause is then given by g’ because x(f) |= f, hence g' |= g

  12. Experimental work • Analysis takes less than 1 second on each of the Super Monaco benchmarks with a 500MHz Pentium III • Unexpected call patterns reveal buggy synchronisation • The analysis appears to be practical and scalable and the analyser is available at http://www.cs.bgu.ac.il/cgi-bin/genaim/susweb.cgi

More Related