Section 19.2.7

Abstraction, concretization, and Galois connection

Definition

Abstraction and concretization are the two maps between the summaries computed by abstract interpretation §3.4, a kind of static analysis §3.1, and the program states described. Concretization γ\gamma sends a summary to the set of states it stands for. Abstraction α\alpha sends a set of states to a summary that covers it. They form a Galois connection when, for every set CC of states and every summary aa, α(C)\alpha(C) is at least as precise as aa exactly when γ(a)\gamma(a) contains all of CC. Then α(C)\alpha(C) is the most precise summary covering CC.

The idea

A summary is only data. The interval [1,3][1, 3] is two numbers, and an analysis that stores it must say what it claims about the program: that the variable holds one of the integers 1, 2 or 3. Concretization is that meaning, written as a function. Without it, “the analysis is correct” has no content, because correctness means that the meaning of each computed summary includes every state a real run can be in at that point.

Abstraction goes the other way. Given an exact set of values, say {1,3}\{1, 3\}, it picks the summary to store, and the natural choice is the most precise summary that still includes the set: the interval [1,3][1, 3], which also admits 2 because an interval cannot leave a gap. The Galois connection condition says that the two directions agree. The question “does summary aa cover the set CC?” gets the same answer whether it is asked about states, as C⊆γ(a)C \subseteq \gamma(a), or about summaries, as α(C)⊑a\alpha(C) \sqsubseteq a.

A shop that sells boxes in a range of sizes, each of which fits inside the next, gives a fair picture. Concretization is the space inside a box. Abstraction is the smallest box in the range that holds a given object. The object fits in box aa exactly when its smallest box is no larger than aa. The picture stops being accurate when boxes come in different shapes: an object may fit a long thin box and a short wide box with no single smallest box that holds it. Some abstract domains §3.6 behave that way, and they have no abstraction map.

How it works

The setting has two ordered sets and two maps.

The Galois connection condition is α(C)⊑a⇔C⊆γ(a)\alpha(C) \sqsubseteq a \iff C \subseteq \gamma(a) for every set CC of states and every summary aa, where ⇔\iff reads “exactly when”. It has four consequences.

  1. Abstraction covers: C⊆γ(α(C))C \subseteq \gamma(\alpha(C)). Take a=α(C)a = \alpha(C); the left side α(C)⊑α(C)\alpha(C) \sqsubseteq \alpha(C) holds, so the right side holds.

  2. Abstraction is the best cover: whenever C⊆γ(a)C \subseteq \gamma(a), also α(C)⊑a\alpha(C) \sqsubseteq a. So α(C)\alpha(C) is at least as precise as every summary that covers CC.

  3. Abstracting a meaning again loses nothing: α(γ(a))⊑a\alpha(\gamma(a)) \sqsubseteq a. Take C=γ(a)C = \gamma(a); the right side holds, so the left side holds.

  4. Each map determines the other. Because α(C)\alpha(C) is the most precise summary aa with C⊆γ(a)C \subseteq \gamma(a), a designer who has fixed γ\gamma has no freedom left in choosing α\alpha.

When in addition α(γ(a))=a\alpha(\gamma(a)) = a for every summary aa, so that no two summaries stand for the same set, the pair is called a Galois insertion.

The connection is used to design abstract transfer functions, the counterparts of instructions on summaries. Let F:𝒫(Σ)→𝒫(Σ)F : \mathcal{P}(\Sigma) \to \mathcal{P}(\Sigma) map a set of states to the set of states that one real instruction can produce from them, and let F#:A→AF^{\#} : A \to A (read “F sharp”) be its counterpart on summaries. F#F^{\#} is sound when F(γ(a))⊆γ(F#(a))F(\gamma(a)) \subseteq \gamma(F^{\#}(a)) for every summary aa: the output covers every real result. The connection, applied with C=F(γ(a))C = F(\gamma(a)), turns this into the equivalent condition α(F(γ(a)))⊑F#(a)\alpha(F(\gamma(a))) \sqsubseteq F^{\#}(a). The composition α∘F∘γ\alpha \circ F \circ \gamma, which concretizes, applies the real instruction and abstracts again (∘\circ applies the right-hand map first), is therefore the most precise sound transfer function, called the best abstract transformer: no sound transfer function gives a more precise output for any summary.

Worked example

Use the interval domain for one integer variable. Its summaries are ⊥\bot, which stands for the empty set, and the intervals [l,u][l, u] with l≤ul \le u, whose bounds may be −∞-\infty or +∞+\infty. Concretization gives γ([l,u])\gamma([l, u]), the set of integers from ll to uu, and γ(⊥)=∅\gamma(\bot) = \emptyset. Abstraction of a non-empty set CC of integers gives [minC,maxC][\min C, \max C], with −∞-\infty if CC has no smallest element and +∞+\infty if it has no largest; α(∅)=⊥\alpha(\emptyset) = \bot.

Check the condition for C={1,3}C = \{1, 3\}, whose abstraction is α(C)=[1,3]\alpha(C) = [1, 3].

Also γ(α(C))={1,2,3}\gamma(\alpha(C)) = \{1, 2, 3\}, which contains CC and adds 2: abstraction covers, but it can lose information.

Now derive the transfer function for x = x + 1 on mathematical integers. Start from a=[1,3]a = [1, 3]. Concretize: γ(a)={1,2,3}\gamma(a) = \{1, 2, 3\}. Apply the instruction: F({1,2,3})={2,3,4}F(\{1, 2, 3\}) = \{2, 3, 4\}. Abstract: α({2,3,4})=[2,4]\alpha(\{2, 3, 4\}) = [2, 4]. The same three steps for any [l,u][l, u] give [l+1,u+1][l + 1, u + 1], the best abstract transformer for this instruction. The output [2,5][2, 5] would also be sound, since {2,3,4}⊆{2,3,4,5}\{2, 3, 4\} \subseteq \{2, 3, 4, 5\}, but less precise. The output [2,3][2, 3] would be unsound, since it omits the real result 4.

For x = x * x with a=[−1,2]a = [-1, 2]: γ(a)={−1,0,1,2}\gamma(a) = \{-1, 0, 1, 2\}, the squares are 1, 0, 1 and 4, so F(γ(a))={0,1,4}F(\gamma(a)) = \{0, 1, 4\}, and the best abstract transformer gives α({0,1,4})=[0,4]\alpha(\{0, 1, 4\}) = [0, 4]. A simpler rule multiplies the bounds as if the two factors were independent and takes the smallest and largest of (−1)(−1)=1(-1)(-1) = 1, (−1)(2)=−2(-1)(2) = -2, (2)(−1)=−2(2)(-1) = -2 and (2)(2)=4(2)(2) = 4, giving [−2,4][-2, 4]. That rule is sound but less precise, because it forgets that both factors are the same number.

Stated precisely

Let Σ\Sigma be the set of program states and 𝒫(Σ)\mathcal{P}(\Sigma) the set of its subsets, ordered by ⊆\subseteq, and let (A,⊑)(A, \sqsubseteq) be a partially ordered set of summaries. Maps α:𝒫(Σ)→A\alpha : \mathcal{P}(\Sigma) \to A and γ:A→𝒫(Σ)\gamma : A \to \mathcal{P}(\Sigma) form a Galois connection when α(C)⊑a⇔C⊆γ(a)for every C⊆Σ and every a∈A.\alpha(C) \sqsubseteq a \iff C \subseteq \gamma(a) \qquad \text{for every } C \subseteq \Sigma \text{ and every } a \in A. Equivalently: α\alpha and γ\gamma are both monotone, C⊆γ(α(C))C \subseteq \gamma(\alpha(C)) for every CC, and α(γ(a))⊑a\alpha(\gamma(a)) \sqsubseteq a for every aa. The pair is a Galois insertion when moreover α(γ(a))=a\alpha(\gamma(a)) = a for every aa.

Let FF be the real effect of an instruction on sets of states. A transfer function F#F^{\#} is sound when F(γ(a))⊆γ(F#(a))F(\gamma(a)) \subseteq \gamma(F^{\#}(a)) for every a∈Aa \in A, which under a Galois connection holds exactly when α(F(γ(a)))⊑F#(a)\alpha(F(\gamma(a))) \sqsubseteq F^{\#}(a) for every aa. The conclusion for a whole program needs only γ\gamma, and the Abstract interpretation entry proves it: let FF now be one step of the whole program, F#F^{\#} a sound counterpart, γ\gamma monotone and S0S_0 the set of initial states. If a summary a*a^{*} satisfies S0⊆γ(a*)S_0 \subseteq \gamma(a^{*}) and F#(a*)⊑a*F^{\#}(a^{*}) \sqsubseteq a^{*}, then every reachable state §3.21 lies in γ(a*)\gamma(a^{*}).

Limits and common mistakes

The connection does not make any code correct. It defines what the best transfer function is; each implemented F#F^{\#} must still be proved to satisfy the soundness §3.7 inclusion for every summary, including ⊥\bot and unbounded intervals.

FF must be the machine’s real behavior. On a 32-bit unsigned register, x = x + 1 turns 4294967295 into 0, an unsigned wraparound §4.16. The rule [l,u]↦[l+1,u+1][l, u] \mapsto [l + 1, u + 1] is then unsound for u=4294967295u = 4294967295: it claims an upper bound of 4294967296 and omits the real result 0. A sound rule returns the full range [0,4294967295][0, 4294967295] whenever u+1u + 1 exceeds 4294967295.

Abstracting after every step loses relationships between variables. After y = x with xx in [0,1][0, 1], the interval domain stores xx in [0,1][0, 1] and yy in [0,1][0, 1] separately, so z = x - y gets [0−1,1−0]=[−1,1][0 - 1, 1 - 0] = [-1, 1], although zz is always 0. Each step used its best abstract transformer; the loss comes from abstracting between the steps. A relational domain §15.12, which records relations between variables, keeps x=yx = y.

Not every useful domain has an abstraction map. In the domain of convex polyhedra, regions bounded by flat sides, which in two dimensions are convex polygons, a disc has no smallest enclosing polygon: any polygon around a disc can be made smaller by cutting off a corner. Analyses with such domains use γ\gamma alone and state soundness with the inclusion above.

α\alpha is a definition, not usually an algorithm §14.1. The set of reachable states is infinite or unknown, so an analysis never applies α\alpha to it; it iterates F#F^{\#} and relies on the soundness inclusion. A correct initial summary, termination of the iteration and a faithful model of the machine are separate obligations.

Questions answered

What must an abstract transfer prove?

An abstract transfer function must prove that its output summary covers every state that the real instruction can produce from any state its input summary stands for. In symbols, F(γ(a))⊆γ(F#(a))F(\gamma(a)) \subseteq \gamma(F^{\#}(a)) for every summary aa. Here concretization γ\gamma maps a summary to the set of concrete states §3.5 it stands for, FF maps a set of states to the set of results of the real instruction, and F#F^{\#} is the abstract transfer function being checked.

When abstraction α\alpha, which maps a set of states to its most precise covering summary, forms a Galois connection with γ\gamma, the same condition can be checked on summaries: α(F(γ(a)))⊑F#(a)\alpha(F(\gamma(a))) \sqsubseteq F^{\#}(a), where ⊑\sqsubseteq means “is at least as precise as”. That is, the output may be no more precise than the best abstract transformer α∘F∘γ\alpha \circ F \circ \gamma. For x = x + 1 and the input interval [1,3][1, 3], the real results are 2, 3 and 4, so [2,4][2, 4] and [2,5][2, 5] are sound outputs and [2,3][2, 3] is not.

The proof must hold for every input summary, including the empty summary and unbounded intervals, and for the machine’s real arithmetic, including wraparound. The Galois connection does not supply this proof; each transfer function needs its own.

Related entries: Abstract interpretation (§3.4), Abstract domain (§3.6), Relational abstract domain (§15.12), Partial order, lattice, join, and meet (§19.2.6). Further reading: [68].