1. Conditioned Slicing for
First-Order Functional Programs
Author: Diego Cheda
Supervisor: Germ´an Vidal
DSIC, Universidad Polit´ecnica de Valencia
Camino de Vera s/n, 46022, Valencia, Espa˜na.
— Septiembre de 2008 —
3. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Motivation
[Wadler, 1998] → Why No One Uses Functional Languages
[Peyton Jones et al, 2007] → A History of Haskell
[Cheda and Silva, 2008] → State of the Practice in Alg.
Debugging
Improvements to address effective and efficiently errors
detection in functional programs.
Functional programs debugging:
traditionals,
profiling,
tracing,
algorithmic debugging, and
program slicing.
Diego Cheda 3 / 32
4. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Program Slicing [Mark Weiser, 1979]
Extract sentences that are related to some criterion
Slicing criterion
Example
P r o g r a m Slice
Slicing
Criterion
Applications
debugging,
comprehension,
maintenance,
testing,
parallelization,
integration,
reverse engineering,
program restructuring,
etc.
Diego Cheda 4 / 32
5. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Static Slicing [Cheda, Silva and Vidal, 2006]
TDG
Slicing Criterion: (function, slicing pattern)
where
function is an initial function call, and
slicing pattern [Ochoa et al, 2004] denotes the shape of the
result (constructor term) by ignoring part of its term structure.
• ⊥ denotes a subexpression whose computation is not relevant.
• a subexpression which is relevant.
Diego Cheda 5 / 32
6. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Example
Static Slicing Criterion: (triangle x y z, Pair ⊥ )
triangle x y z = Pair (sum x y z)(kind x y z)
sum x y z = add x (add y z)
add Zero x = x
add (Succ x) y = (Succ (add x y))
kind x y z = if (x == y) then
(if (y == z) then Equilateral else Isosceles)
else
(if (y == z) then Isosceles else Scalene)
Diego Cheda 6 / 32
7. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Dynamic Slicing [Ochoa, Silva and Vidal, 2004]
Redex Trails
Slicing Criterion: (function, partial value, slicing pattern)
where
function is an initial function call with concrete argument
values, and
partial value is a partial value obtained as result,
slicing pattern denotes which part of the function result is
relevant or not.
Diego Cheda 7 / 32
8. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Example
Dynamic Slicing Criterion: (main, Pair Equilateral, Pair ⊥ )
main = triangle (Succ Zero) (Succ Zero) (Succ Zero)
triangle x y z = Pair (sum x y z)(kind x y z)
sum x y z = add x (add y z)
add Zero x = x
add (Succ x) y = (Succ (add x y))
kind x y z = if (x == y) then
(if (y == z) then Equilateral else Isosceles)
else
(if (y == z) then Isosceles else Scalene)
Diego Cheda 8 / 32
9. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Conditioned Slicing [Canfora et al, 1998]
Slicing Criterion: (function, logical formula, slicing pattern)
where
function is an initial function call,
logical formula is a logical formula on the input variables, and
slicing pattern denotes which part of the function result is
relevant or not.
Important
As far as we know, conditioned slicing has not been defined before
in the declarative paradigm.
Diego Cheda 9 / 32
10. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Motivation
Example
Conditioned Slicing Criterion: (triangles x y z, x==y, Pair ⊥ )
triangle x y z = Pair (sum x y z)(kind x y z)
sum x y z = add x (add y z)
add Zero x = x
add (Succ x) y = (Succ (add x y))
kind x y z = if (x == y) then
(if (y == z) then Equilateral else Isosceles)
else
(if (y == z) then Isosceles else Scalene)
Diego Cheda 10 / 32
11. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Contributions
Contributions
Definition of conditioned slicing for the domain of declarative
programming.
A slicing technique suitable to be applied to first-order
functional languages.
A prototype that implements the technique proposed in this
work.
Diego Cheda 11 / 32
12. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Syntax of a Simple Functional Language
(program) R ::= D1 . . . Dn
(functions) D ::= f (xn) = e
(expressions) e ::= t | case t of {pk → ek }
(terms) t :: = x | c(tn) | f (tn)
(patterns) p ::= c(xn)
Diego Cheda 12 / 32
13. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Semantics
Lazy Narrowing with Definitional Trees (LNT)
(fun eval) f(tn) =⇒id σ(e)
if f(xn) = e ∈ R, and σ = {xn → tn}
(case select) case c(tn) of {pk → ek } =⇒id σ(ei )
if pi = c(xn), c ∈ C, and σ = {xn → tn}
(case guess) case x of {pk → ek } =⇒σ σ(ei )
if σ = {x → pi }, and i ∈ {1, . . . , k}
(case eval) case t of {pk → ek } =⇒σ σ(case t of {pk → ek })
if t is not in head normal form and t =⇒σ t
LNT derivation, noted e0 =⇒∗
σ en, is a sequence
e0 =⇒σ1 . . . =⇒σn en, where σ = σn ◦ · · · ◦ σ1, and it is successful
when en is in head normal form.
Diego Cheda 13 / 32
14. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Slice Definition
Definition (Slice [Silva and Vidal, 2007])
Given a program R = Dn with Di = (f (xm) = e), R = Dn with
Di = (f (xm) = e ) is a slice of R, noted R R, iff e e
e e =
true if e = ⊥ or e = e
true if e = case x of {pk → ek},
e = case x of {pk → ek}, and
ek ek for all k.
false otherwise
Diego Cheda 14 / 32
15. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Conditioned Slicing Criterion
Definition (Conditioned Slicing Criterion)
Given a program R, a slicing criterion for R is (f (xn), φ, π) where
f is a function symbol such that f (xn) = e ∈ R, and
φ is a first-order logical formula on the arguments x1, . . . , xn
of f , and
π is a slicing pattern defined as follows:
π ∈ ⊥ | | c(πk)
where
c is a constructor symbol of arity k ≥ 0,
⊥ denotes a subexpression of the value whose computation is
not relevant, and
a subexpression which is relevant.
Diego Cheda 15 / 32
16. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Conditioned Slice
Definition (Conditioned Slice)
Given a program R, and SC = (f (xn), φ, π), R is a conditioned
slice w.r.t. (f (xn), φ, π), noted ¡(R, SC), iff
1 R R, and
2 xn satisfies φ, f (xn) =⇒∗
σ v with R, f (xn) =⇒∗
σ v with R ,
where v and v are values (i.e., in head normal form) such
that v = v , and σ = σ , and
3 v ∈ γ(π) and for all subterm v|p and π|q / p = q and
π|q = ⊥ where γ(π) is a concretization of π –i.e. v has the
shape of π–.
Diego Cheda 16 / 32
17. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Conditioned Slice
Example
¡(R, SC) with SC=(triangles x y z, x==y, Pair ⊥ ) is R :
triangle x y z = Pair (sum x y z)(kind x y z)
sum x y z = add x (add y z)
add Zero x = x
add (Succ x) y = (Succ (add x y))
kind x y z = if (x == y) then
(if (y == z) then Equilateral else Isosceles)
else
(if (y == z) then Isosceles else Scalene)
Diego Cheda 17 / 32
18. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Computing Conditioned Slicing
[Canfora et al, 1998]
Conditioned slice ∼ (forward) slice of a conditioned program.
Two phases slicing process:
1 We augment the language semantics to collect those part
of the program that can be executed when a logical formula
holds true.
We symbolically execute the program considering a logical
condition −→ conditioned program.
2 We (forward) slice the conditioned program w.r.t. a slicing
pattern in order to obtain the conditioned slice [Cheda, Silva
and Vidal, 2006].
Diego Cheda 18 / 32
19. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Augmented Semantics
Definition (Program Position [Ochoa el al, 2004])
A program position is a pair (f , q) where f is a function symbol
such that f (xn) = e and q is the position of a subterm of e.
Diego Cheda 19 / 32
20. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Augmented Semantics
(fun eval) f (tn), g, P, φ =⇒id σ(e), f , pp ∪ P, φ
if f (xn) = e ∈ R, σ = {xn → tn}, and
if f ∈ SC and φ ⇒ σ(xn) then pp = {(f , )} else pp = ∅
(case select) case c(tn) of {pk → ek }, g, P, φ =⇒id σ(ei ), g, pp ∪ P, φ
if pi = c(xn), c ∈ C, and σ = {xn → tn} then pp = {(g, 2.j) | j = i}
(case guess) case x of {pk → ek }, g, P, φ =⇒σ σ(ei ), g, pp ∪ P, φ
if σ = {x → pi }, i ∈ {1, . . . , k}, and
if g ∈ SC and φ ⇒ σ(x) then pp = {(g, 2.i)}, and φ = φ ∧ (x = pi )
else pp = ∅
(case eval) case t of {pk → ek }, g, P, φ =⇒σ σ(case t of {pk → ek }), g, P, φ
if t is not in head normal form and t =⇒σ t
Diego Cheda 20 / 32
21. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Conditioned Slicing Algorithm
Input: a program R, and SC = (f(xn), φ)
Output: conditioned program S
i = 0;
Si = { f (xn), f , , φ };
repeat
R = unfold(Si , R, φ);
Si+1 = abstract(Si , R );
i = i + 1;
until (Si = Si−1);
return build slice(Si ,R);
Diego Cheda 21 / 32
22. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Implementation
goal x = CSLICE (and x False) (x == False)
CSLICE x y = x
and x1 x2 = (FCase x1 of
(True -> (FCase x2 of
(True -> (True ))
(False -> (False ))
))
(False -> (FCase x2 of
(True -> (False ))
(False -> (False ))
Diego Cheda 22 / 32
23. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Implementation
goal x = CSLICE (and x False) (x == False)
CSLICE x y = x
In this function call:
(and x1 (False ))
this arguments x1, (False ), satisfy (== x1 (False )), ? [y / n] y
Diego Cheda 23 / 32
24. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Implementation
goal x = CSLICE (and x False) (x == False)
CSLICE x y = x
In this program fragment:
(FCase x1 of
(True -> (FCase (False ) of
(True -> (True ))
(False -> (False ))
)) )
if x1 is substituted by (-> x1 (True )), satisfy (== x1 (False )), ? [y
/ n] n
Diego Cheda 24 / 32
25. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Implementation
goal x = CSLICE (and x False) (x == False)
CSLICE x y = x
In this program fragment:
(FCase x1 of
(False -> (FCase (False ) of
(True -> (False ))
(False -> (False ))
))
)
if x1 is substituted by (-> x1 (False )), satisfy (== x1 (False )), ?
[y / n] y
Diego Cheda 25 / 32
26. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Implementation
goal x = CSLICE (and x False) (x == False)
CSLICE x y = x
[("and",[]),("and",[2,2]),("and",[2,2,2,2])]
and x1 x2 = (FCase x1 of
(True -> (FCase x2 of
(True -> (True ))
(False -> (False ))
))
(False -> (FCase x2 of
(True -> (False ))
(False -> (False ))
Diego Cheda 26 / 32
27. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Conclusions
We define conditioned slice for first-order functional programs.
We provide an algorithm to compute conditioned slice.
Conditioned slicing provides a common slicing framework for
both static and dynamic slices [Canfora et al, 1998].
Static slice can be computed using the conditioned slicing
criterion as (function, True, π),
Dynamic slice as (function, φ, π) where φ is composed by
concrete values on the inputs rather than a logical formula.
We implement a first prototype version of the conditioned
slicer.
Diego Cheda 27 / 32
28. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Publications
The following publications were made during the development of
the thesis project:
D. Cheda and S. Cavadini (INRIA),
Conditioned Slicing for First Order Functional Logic Languages.
In Proc. of the 17th Int’l WFLP 2008 - ENTCS.
D. Cheda and J. Silva,
An Evaluation of Algorithmic Debugger Implementations.
In Proc. of the 17th Int’l WFLP 2008 - ENTCS.
D. Cheda and J. Silva,
State of the Practice in Algorithmic Debugging. In PROLE 2007.
D. Cheda, J. Silva, and G. Vidal,
Static Slicing of Rewrite Systems. Proc. 15th Int’l WFLP 2006 -
ENTCS.
D. Cheda, J. Silva, and G. Vidal,
Term Dependence Graph. In PROLE 2006.
Diego Cheda 28 / 32
29. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Publications
Other publications:
S. Cavadini (INRIA) and D. Cheda,
Run-time Information Flow Monitoring based on Dynamic
Dependence Graphs,
3th Int’l Conference on Availability, Reliability and Security.
In IEEE Proceedings, pp. 586-591, 2008.
S. Cavadini (INRIA) and D. Cheda,
Program Slicing Based on Sentence Executability.
In XIII Congreso Argentino de Ciencias de la Computaci´on, 2007.
S. Cavadini (INRIA) and D. Cheda,
The Necessary Condition for Execution and its Use in Program
Slicing. In PROLE 2007.
Diego Cheda 29 / 32
30. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Future Work
We plan as future work:
Teorem Prover.
Abstract Interpretation.
Compare static and dynamic slices.
Diego Cheda 30 / 32
31. Thank you for your attention!
Conditioned Slicing for
First-Order Functional Programs
Author: Diego Cheda
Supervisor: Germ´an Vidal
DSIC, Universidad Polit´ecnica de Valencia
Camino de Vera s/n, 46022, Valencia, Espa˜na.
32. Conditioned Slicing for First-Order Functional Programs
Motivation Contributions Preliminaries Conditioned Slicing Computing Conditioned Slicing Conclusions
Termination
Termination of the unfolding process (local termination), and
Termination of the repeat-until loop (global termination).
Diego Cheda 32 / 32