Definitioncore
Interval abstract domain
Also called box domain.
Abstracts each numeric variable by a lower and an upper bound, a non-relational domain of infinite height that needs widening.
The interval domain describes each integer name by a lower and an upper bound, such as . A state of the analysis keeps one interval per name, so it describes a box in the space of values. It is the simplest numeric domain that can bound the range of a loop counter, prove that a divisor is never 0 or that an index stays inside an array, and it costs per operation for names. It keeps no relation between two names, and it has infinite ascending chains, so an analysis with it needs a widening.
Definition
The general domain, its meaning and its Galois connection with sets of integers are on the abstract interpretation page; this page gives the parts that an analyzer of the toy IR needs. The order is the Cousot order: lower is more precise, and means that no state reaches the point.
The lattice for one name. The elements are and the pairs with , and . The order is inclusion of meanings: when and . The join is , and the meet is , or when that pair is empty. The top element is . The height is infinite: never stops. The map makes a Galois insertion with , so every operation below can be compared with the best one, .
The state. A state is a map from the names to intervals, or . A map in which some name has is the same as . This is the non-relational construction of the abstract domain page, and its meaning is the box . Join, meet and work name by name.
Transfer functions. Let be the state before the instruction, and write and for the intervals of the operands, with for a constant . An instruction x = ... sets and keeps the other names.
| instruction | new interval of x |
best? |
|---|---|---|
x = k |
yes | |
x = y |
yes | |
x = y + z |
yes | |
x = y - z |
yes | |
x = y * z |
with and | yes |
x = y / z |
split into its negative part and its positive part, divide by each part using the four corners, and join | yes |
x = y % z |
with : if , if , else | sound, not best |
x = y < z |
if , if , else | yes |
x = y op z, other op |
for a comparison, a simple bound or for the bit operations | sound |
"Best" means that the result is of the set of all concrete results, for any operand intervals that do not contain ; a check over all operand intervals inside confirms the claim for / and the soundness of the % rule. Division truncates toward zero, as in the toy IR. For a divisor of one sign, the truncated quotient is monotone in each operand, so the extremes are at the corners. The value 0 is left out of the divisor because a run with divisor 0 traps and does not reach the next instruction. If , the result is : no run gets past the instruction. When an operand bound is infinite, a corner uses the limits, for example and .
Guards. Suppose the block ends with t = y < z followed by br t L1 L2, and neither name changes between the two. On the edge to L1 the condition holds, so the state is refined:
On the edge to L2, holds, and , . The other comparisons are similar. If a meet gives , the whole state is and the edge is dead. A guard on a name that the block does not compare directly gives no refinement.
Equations and the solution. The equations have the shape given on the abstract domain page: at each block, the join over the incoming edges of the edge transformer. The join over all paths, the analogue of the meet-over-all-paths solution in this order, is more precise than the fixed point, because the transfer functions are monotone but do not distribute over the join (see the example below). An analyzer computes the fixed point side. Plain iteration from may run forever, so the analyzer applies a widening at a set of points that cuts every cycle, such as the heads of a weak topological ordering, and then a few steps of narrowing. The result is a map with , not in general the least fixed point of .
Soundness. Each transfer function and each guard is sound, and the join is sound. By the claim on the abstract domain page, any with satisfies at each block .
Precision. The domain loses information in three ways. It forgets relations between names at each join. It treats two uses of one name as independent, so x * x and y - x lose the link between the operands. And the widening jumps over the exact bound, which narrowing only partly recovers.
Cost. In the word-RAM model, with each bound in one word, a state takes space, and a join, a meet, a test or a widening takes time. A transfer function changes one name, so it takes time if the state is updated in place, or if it is copied. With widening at the chosen points, the value at each such point changes at most times: once from , then at most once for each of the bounds.
Examples and non-examples
An absolute value and a division. The parameter x has the precondition .
entry:
t = x < 0
br t neg pos
neg:
y = 0 - x
jump join
pos:
y = x
jump join
join:
d = y - x
e = y + 1
q = 100 / e
ret q
The guard on t = x < 0 refines x on each edge. The results at the end of each block are in the table, with the exact sets for comparison.
| point | interval result | exact set |
|---|---|---|
| neg | , | same |
| pos | , | same |
| join, after the join | , | |
d = y - x |
||
e = y + 1 |
||
q = 100 / e |
The analysis proves that , so the division never traps; that is the main use of the domain. It cannot prove : after the join it knows and but not , and is computed as if the two were unrelated. A relational domain such as the octagon domain keeps and and proves .
The fixed point is less precise than the join over paths. Two paths reach a block, one with and one with , and the block computes z = x + y. On each path the result is , so the join over paths gives . The fixed point first joins the states, , and then adds: . Addition does not distribute over the join of states.
A loop. The block that sums i from 0 to 9 into s is analyzed step by step on the widening operator and narrowing operator pages. The result at the exit is and . The upper bound of s is lost because it depends on the number of passes, which the domain does not track.
Non-example: one interval for the whole state. A single pair of bounds for all names together, and , is a domain too, but it is not this one: it cannot say that i is small and n is large at the same time. The interval domain has one pair per name.
Non-example: machine integers. On a machine with 32-bit integers that wrap around, y + 1 with gives a result in , not . The table above is sound only for the unbounded integers of the toy IR. An analyzer for C either reports an integer overflow and continues with the wrapped range, or uses intervals modulo .
Non-example: interval arithmetic. Interval arithmetic on floating-point numbers uses the same operations with outward rounding, and it bounds the error of one computation. The interval domain is that arithmetic plus a join, guards and a widening, so that it can run over a control flow graph with loops.
Related definitions
- Abstract domain: the general definition and the non-relational construction used here.
- Galois connection: the interval insertion, and the best transformer that the table is compared with.
- Widening operator and narrowing operator: the operators that make the analysis stop and then recover precision.
- Weak topological ordering: an order of the blocks and a set of widening points.
- Octagon domain and polyhedra domain: relational domains that keep the facts that intervals lose, at a higher cost.
- Reduced product: a combination with other domains, such as parity or congruences.
- Constant propagation problem: the analysis with intervals of width 0, of finite height.
- Abstract interpretation: the general technique, with the interval widening and a worked loop.
References
- Patrick Cousot and Radhia Cousot, Static determination of dynamic properties of programs, Proceedings of the Second International Symposium on Programming, B. Robinet (ed.), Dunod, Paris, 1976, pages 106 to 130, the interval analysis of programs, its abstract operations, and the widening and narrowing that make it stop
- Patrick Cousot and Radhia Cousot, Abstract interpretation: a unified lattice model for static analysis of programs by construction or approximation of fixpoints, POPL 1977, pages 238 to 252, the interval example of an abstract interpretation with an infinite ascending chain and its widening
- Xavier Rival and Kwangkeun Yi, Introduction to Static Analysis, An Abstract Interpretation Perspective, MIT Press, 2020, Chapter 2 and Chapter 3 (the interval domain as a non-relational abstraction, its operations, and the analysis of conditions and loops)
- Flemming Nielson, Hanne Riis Nielson and Chris Hankin, Principles of Program Analysis, Springer, 1999, Chapter 4 (Abstract Interpretation), the interval lattice and its widening as the running example
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 86D96R Edit this page History Report an error Markdown