Program Slicing via FermaT Transformations M. P. Ward Software Technology Research Lab De Montfort University The Gateway, Leicester LE1 9BH, UK Martin.Ward@durham.ac.uk Abstract In this paper we give a brief introduction to the foundations of WSL transformation theory and de- scribe how the concept of program slicing can be form- alised in the theory. This formalism naturally lends itself to several generalisations including amorphous slicing and conditioned slicing. One novel general- isation is “semantic slicing” which combines slicing and abstraction to a specification. Interprocedural semantic slicing has been implemented in the FermaT transformation system [16]: an industrial-strength transformation system designed for forward and re- verse engineering, re-engineering and program com- prehension. 1 Introduction In the development of methods for program ana- lysis and manipulation it is important to start from a rigorous mathematical foundation. Without such a foundation, it is all too easy to assume that a particular transformation is valid, and come to rely upon it, only to discover that there are certain special cases where the transformation is not valid. The way to get a rigorous proof of the correctness of a transformation is to first define precisely when two programs are “equivalent”, and then show that the transformation in question will turn any suitable program into an equivalent program. To do this, we need to make some simplifying assumptions: for example, we usually ignore the execution time of the program. This is not because we do not care about efficiency—far from it—but because we want to be able to use the theory to prove the correctness of optimising transformations: where a program is trans- formed into a more efficient version. More generally, we ignore the internal sequence of state changes that a program carries out: we are only interested in the initial and final states (but see Section 4 for a discussion of operational semantics). Our mathematical model defines the semantics of a program as a function from states to sets of states. For each initial state s, the function f returns the set of states f (s) which are all the possible final states of the program when it is started in state s. A special state ⊥ indicates nontermination or an error condition. If ⊥ is in the set of final states, then the program might not terminate for that initial state (in which case, we put all the other states into f (s)). If two programs have the same semantic function then they are equivalent. A transformation is an operation which takes any program satisfying its ap- plicability conditions and returns an equivalent pro- gram. A refinement of a program is any program which terminates on all the initial states for which the original program terminates, and for each such state it is guaranteed to terminate in a possible final state for the original program. In terms of semantic functions, the relation is: ∀s. f 2 (s) ⊆ f 1 (s) since if f 1 may not terminate on s then f 1 (s) contains all possible states, including ⊥. 2 Transformation Theory Our transformation theory developed in roughly the following stages: 1. Start with a very simple and tractable kernel language; 2. Develop proof techniques based on set theory and mathematical logic, for proving the correctness of transformations in the kernel language;