Online Encyclopedia
Abstract interpretation
Abstract interpretation is a theory of sound approximation of the semantics of computer programs, based on monotonic functions over ordered sets, especially lattices. It can be viewed as a partial execution of a computer program which gains information about its semantics (e.g. control structure, flow of information ) without performing all the calculations.
Its main concrete application is formal static analysis, the automatic extraction of information about the possible executions of computer programs; such analyses have two main usages:
- inside compilers, to analyse programs in order to decide whether certain optimisations or transformations are applicable;
- for debugging or even the certification of programs against classes of bugs.
Abstract interpretation was formalized by Pr Patrick Cousot .
Contents |
Intuition
We shall now illustrate what abstract interpretation would mean on concrete, not computing examples.
Let us consider the people in a conference room. If we wish to prove that some persons were not present, one concrete method is to look up a list the names and social security numbers of all participants.
We may however have restricted ourselves to registering only their names. If the name of a person is not found in the list, we may safely conclude that that person was not present; but if it is, we cannot conclude definitely without further enquiries, due to the possibility of homonyms. Let us note that this imprecise information will still be adequate for most purposes, because homonyms are rare in practice.
If we are only interested in some specific information, say, "was there a person of age n in the room", keeping a list of all names and dates of births is unnecessary. We may safely and without loss of precision restrict ourselves to keeping a list of the participants' ages. If this is already too much to handle, we might keep only the minimal m and maximal M ages. If the question is about an age strictly lower than m or stricty higher than M, then we may safely respond that no such participant was present. Otherwise, we may only be able to say that we do not know.
In the case of computing, concrete, precise information is in general not computable within finite time and memory (see Rice's theorem and the halting problem). Abstraction is used to simplify problems up to problems amenable to automatic solutions. One crucial issue is to diminish precision so as to make problems manageable while still keeping enough precision for answering the questions (such as "may the program crash?") one is interested in.
Abstract interpretation of computer programs
Given a programming or specification language, abstract interpretation consists in giving several semantics linked by relations of abstraction. The most precise semantics, describing very closely the actual execution of the program, is called the concrete semantics. For instance, the concrete semantics of an imperative programming language may associate to each program the set of execution traces it may produce – an execution trace being a sequence of possible consecutive states of the execution of the program; a state typically consists of the value of the program counter and the memory locations (globals, stack and heap). More abstract semantics are then derived; for instance, one may consider only the set of reachable states in the executions (which amounts to considering the last states in finite traces).
For goals of static analysis, some computable abstract semantics must be derived at some point. For instance, one may choose to represent the state of a program manipulating integer variables by forgetting the actual values of the variables and only keeping their signs (+, - or 0). For some elementary operations, such as multiplication, such an abstraction does not lose any precision: to get the sign of a product, it is sufficient to know the sign of the operands. For some other operations, the abstraction may lose precision: for instance, it is impossible to know the sign of a sum whose operands are respectively positive and negative.
Such loss of precision may not, in general, be avoided so as to make a decidable semantics (see Rice's theorem, halting problem). There is, in general, a compromise to be made between the precision of the analysis and its tractability, either from a computability point of view or from a complexity point of view.
Formalization
Let L_{1}, L_{2}, L'_{1}, L'_{2} be ordered sets. Let γ_{1} and γ_{2}; be two monotonic (order-preserving) functions between L_{1} and L'_{1}, L_{2} and L'_{2} respectively. These functions are the concretization functions, and an element x' in L'_{i} is said to be an abstraction of an element x in L if x ≤ γ(x').
The concrete semantics f is a monotonic function from L_{1} to L_{2}. A function f' from L'_{1} to L'_{2} is said to be a valid abstraction of f if for all x'_{1} in L'_{1}, f ∘ γ(x') ≤ γ ∘ f'(x').
Program semantics are generally described using fixed points in the presence of loops or recursive procedures. Let us suppose that L is a complete lattice and let f be a monotonic function from L into L. Then, any x' such that f'(x') ≤ x' is an abstraction of the least fixed-point of f, which exists, according to the Knaster-Tarski theorem.
The difficulty is now to obtain such an x'. If L' is of finite height, or at least verifies the "ascending chain condition" (all ascending sequences are ultimately stationary), then such an x' may be obtained as the stationary limit of the ascending sequence x'_{n} defined by induction as follows: x'_{0}=⊥ (the least element of L') and x'_{n+1}=f'(x'_{n}).
In other cases, it is still possible to obtain such an x' through a widening operator ∇: for all x and y, x ∇ y should be greater or equal than both x and y, and for all sequence y'_{n}, the sequence defined by x'_{0}=⊥ and x'_{n+1}=x'_{n} ∇ y'_{n} is ultimately stationary. We can then take y'_{n}=f(x'_{n}).
In some cases, it is possible to define abstractions using Galois connections (α, γ) where α if from L to L' and γ is from L' to L. This supposes the existence of best abstractions, while is not necessarily the case. For instance, if we abstract sets of couples (x,y) of real numbers by enclosing convex polyhedra, there is no optimal abstraction to the disc defined by x^{2}+y^{2} ≤ 1.