ROBERTO BRUNI, University of Pisa, Italy

ROBERTO GIACOBAZZI, University of Verona, Italy

ROBERTA GORI, University of Pisa, Italy

FRANCESCO RANZATO, University of Padova, Italy

只记录重点信息。

# 一个例子

考虑两个程序:

c1=if even(x) then 0 else 1c2=if even(x) then x else x+1c_1=\textbf{if }\text{even}(x)\textbf{ then }0\textbf{ else }1\\ c_2=\textbf{if }\text{even}(x)\textbf{ then }x\textbf{ else }x+1\\

然后定义[c]A=α[c]γ[|c|]^A=\alpha\circ[|c|]\circ\gamma,对于某个 abstract domain AA。那么假如A=IntervalA=\textbf{Interval},那么:

  [c1]A[c2]A([0,1])=[c1]A([0,2])=[0,1]\begin{aligned} \;[|c_1|]^{A}\circ[|c_2|]^A([0,1])&=[|c_1|]^A([0,2])\\ &=[0,1] \end{aligned}

([c1][c2])A([0,1])=[0,0]([|c_1|]\circ[|c_2|])^A([0,1])=[0,0]。故有:

([c1][c2])A[c1]A[c2]A([|c_1|]\circ[|c_2|])^A\subsetneq[|c_1|]^A\circ[|c_2|]^A

原文中对其的意义说明是:

The lack of compositionality is the main cause of the interdependence between the precision of an abstract interpretation and the way programs are written.

# Correctness/Incorrectness Logic 要做的事情

首先它们想做的事仍然是 combine proof for correctness and incorrectness,和 outcome logic 的 motivation 是一样的。

然后做法是:利用 triple 去 under-approximation 证明 incorrectness,然后利用 abstract interpretation 去 over-approximation 证明 correctness。形式化地,考虑一个 triple 和 abstract domain AA,如果令函数A=γαA=\gamma\circ\alpha

A[p]c[q]\vDash_A[p]c[q] 当且仅当同时满足:

  1. qpost[c]pq\subseteq\text{post}[c]p,即 under-approximation。
  2. A(q)=A(post[c]p)A(q)=A(\text{post}[c]p)。即有相同的 abstraction。
  3. post[c]\text{post}[c] is locally complete for input pp on AA

这三个条件其实是说,一个是qpost[c]pA(post[c]p)=A(q)q\subseteq\text{post}[c]p\subseteq A(\text{post}[c]p)=A(q),即post[c]p\text{post}[c]p 是夹在[q,A(q)][q,A(q)] 之间的。

# Global Completeness and Local Completeness

Definition. The abstract domain AA is called a complete abstraction for ff if there exists a complete approximation f#:AAf^\#:A\rightarrow A satisfying:

αf=f#α\alpha\circ f=f^\#\circ\alpha

这个定义实际上说明了:In a complete approximation f#f^\#, then only loss of precision is due to the abstract domain and not to the definition of the abstract function itself !

可以证明,AA is a complete abstraction for ff if and only if αf=(αfγ)α\alpha\circ f=(\alpha\circ f\circ\gamma)\circ\alpha (前提是α,γ\alpha,\gamma 是 Galois embedding)

A=γαA=\gamma\circ\alpha,由于γ\gamma 是单射,那么上述条件其实也可以等价于Af=AfAA\circ f=A\circ f\circ A

我们记CA(f)\mathbb{C}^A(f) 表示 A is a complete abstraction for ff。即CA(f)Af=AfA\mathbb{C}^A(f):Af=AfA

其实在程序语言中,我们也希望对于所有程序cc 都有CA(f)\mathbb{C}^A(f)。但这是非常罕见的情况:

…the standard notion of (global) completeness for Boolean guards is a too strong requirement for abstract domains, often met in practice just by trivial guards or domains.

所以试图引入 local completeness:

Definition. An abstract domain AA is locally complete for f:CCf:C\rightarrow C at a concrete value cCc\in C, written CcA(f)\mathbb{C}^A_c(f), if:

CcA(f)    Af(c)=AfA(c)\mathbb{C}^A_c(f)\iff Af(c)=AfA(c)

而 local 和 complete 联系就是:CA(f)    cC.  CcA(f)\mathbb{C}^A(f)\iff\forall c\in C.\;\mathbb{C}_c^A(f).

Proposition: CA(c)A(f)\mathbb{C}_{A(c)}^A(f) 自然成立。(AA is trivially locally complete for any ff on any abstract value A(c)A(c))

证明:考虑到α,γ\alpha,\gamma 是 Galois embedding,那么有:

AfA(A(c))=Afγαγα(c)=Afγ(αγ)α(c)=AfA(c)=Af(A(c)).\begin{aligned} AfA(A(c))&=Af\gamma\alpha\gamma\alpha(c)\\ &=Af\gamma(\alpha\gamma)\alpha(c)\\ &=AfA(c)\\ &=Af(A(c))\\ &\square. \end{aligned}

:考虑函数[0<x?][|0<x?|] 和 Intervals,它不是 global complete 的,譬如对c={0,4}c=\{0,4\} 那么:

A[0<x?](c)=A({4})={4}A[0<x?]A(c)=A[0<x?]({0,1,2,3,4})=A({1,2,3,4})={1,2,3,4}A\circ[|0<x?|](c)=A(\{4\})=\{4\}\\ A\circ[|0<x?|]\circ A(c)=A\circ[|0<x?|](\{0,1,2,3,4\})=A(\{1,2,3,4\})=\{1,2,3,4\}

因此A[0<x?]A[0<x?]AA\circ[|0<x?|]\neq A\circ[|0<x?|]\circ A。但是当cc 满足以下情况之一时,它是 complete 的:

  • cZ>0c\subseteq\mathbb{Z}_{>0}.
  • cZ0c\subseteq\mathbb{Z}_{\leq 0}.
  • {0,1}c\{0,1\}\subseteq c.

譬如c={0,1,4}c=\{0,1,4\},那么:

A[0<x?](c)=A({1,4})={1,2,3,4}A[0<x?]A(c)=A[0<x?]({0,1,2,3,4})=A({1,2,3,4})={1,2,3,4}A\circ[|0<x?|](c)=A(\{1,4\})=\{1,2,3,4\}\\ A\circ[|0<x?|]\circ A(c)=A\circ[|0<x?|](\{0,1,2,3,4\})=A(\{1,2,3,4\})=\{1,2,3,4\}

Theorem: AA is locally complete for both [b?][|b?|] and [¬b?][|\neg b?|] on pp if and only if:

CpA([b?]) and CpA([¬b?])    A(c)=c\mathbb{C}^A_p([|b?|])\text{ and }\mathbb{C}^A_p([|\neg b?|])\iff A(c)=c

其中,c=([b?]A[b?]p)([¬b?]A[¬b?]p)c=([|b?|]\circ A\circ[|b?|]p)\cup([|\neg b?|]\circ A\circ[|\neg b?|]p)

证明:

  • (=>) 假设CpA([b?]) and CpA([¬b?])\mathbb{C}^A_p([|b?|])\text{ and }\mathbb{C}^A_p([|\neg b?|]),那么:

    A(c)=A(([b?]A[b?]p)([¬b?]A[¬b?]p))[by monotonicity]A((A[b?]p)(A[¬b?]p))[by following lemma]=A([b?]p[¬b?]p)=A(p)\begin{aligned} A(c)&=A(([|b?|]\circ A\circ[|b?|]p)\cup([|\neg b?|]\circ A\circ[|\neg b?|]p))\\ \text{[by monotonicity]}&\subseteq A((A\circ[|b?|]p)\cup (A\circ[|\neg b?|]p))\\ \text{[by following lemma]}&=A([|b?|]p\cup[|\neg b?|]p)\\ &=A(p) \end{aligned}

    其中,我们要说明A(A(q)A(w))=A(qw)A(A(q)\cup A(w))=A(q\cup w)。由于 Galois embedding 可以得到α\alpha is additive,那么:

    γα(A(q)A(w))=γ(αA(q)αA(w))=γ((αγ)α(q)(αγ)α(w))[Since Galois embedding]=γ(α(q)α(w))=A(qw).\begin{aligned} \gamma\alpha(A(q)\cup A(w))&=\gamma(\alpha A(q)\cup\alpha A(w))\\ &=\gamma((\alpha\gamma)\alpha(q)\cup(\alpha\gamma)\alpha(w))\\ \text{[Since Galois embedding]}&=\gamma(\alpha(q)\cup\alpha(w))\\ &=A(q\cup w)\\ &\square. \end{aligned}

    因此,有:

    [b?]A(c)[b?]A(p)[b?]A[b?]A(p)=[b?]A[b?](p)[|b?|]A(c)\subseteq[|b?|]A(p)\subseteq [|b?|]\circ A\circ[|b?|]\circ A(p)=[|b?|]A[|b?|](p)

    其中,第三个等号是因为 local completeness,第二个\subseteq 是因为:

    p.  [b?]p[b?]A[b?]p\forall p.\;[|b?|]p\subseteq [|b?|]A[|b?|]p

    证明也很显然,不妨设t[b?]pt\triangleq [|b?|]p,那么因为 Galois embedding 有tA(t)t\subseteq A(t)。那么对于任意σt\sigma\in t,都有[b]expσ=true[|b|]_{exp}\sigma=\textbf{true}σA(t)\sigma\in A(t)。所以也就有σ[b?]A(t)\sigma\in[|b?|]A(t),证毕。

    因此,实际上有:

    [b?]A(c)[b?]A[b?](p)[¬b?]A(c)[¬b?]A[¬b?](p)[|b?|]A(c)\subseteq[|b?|]A[|b?|](p)\\ [|\neg b?|]A(c)\subseteq [|\neg b?|]A[|\neg b?|](p)

    所以:

    A(c)=[b?]A(c)[¬b?]A(c)[b?]A[b?](p)[¬b?]A[¬b?](p)=c\begin{aligned} A(c)&=[|b?|]A(c)\cup[|\neg b?|]A(c)\\ &\subseteq[|b?|]A[|b?|](p)\cup [|\neg b?|]A[|\neg b?|](p)\\ &=c \end{aligned}

    cA(c)c\subseteq A(c) 是显然的,因为AA 的单调性,故A(c)=cA(c)=c

  • (<=) 首先,我们有p=[b?]p[¬b?]p([b?]A[b?]p)([¬b?]A[¬b?]p)=cp=[|b?|]p\cup[|\neg b?|]p\subseteq ([|b?|]A[|b?|]p)\cup([|\neg b?|]A[|\neg b?|]p)=c.

    所以有

    A(p)A(c)=c=([b?]A[b?]p)([¬b?]A[¬b?]p)A(p)\subseteq A(c)=c=([|b?|]A[|b?|]p)\cup([|\neg b?|]A[|\neg b?|]p)

    所以有

    [b?]A(p)[b?]c=[b?]A[b?]pA[b?]p[|b?|]A(p)\subseteq[|b?|]c=[|b?|]A[|b?|]p\subseteq A[|b?|]p

    又因为AA=γ(αγ)α=γα=AA\circ A=\gamma(\alpha\gamma)\alpha=\gamma\alpha=A,故左右同时套上AA

    A[b?]A(p)AA[b?]p=A[b?]pA[|b?|]A(p)\subseteq AA[|b?|]p=A[|b?|]p

    此外,因为A(p)pA(p)\supseteq p,故有A[b?]A(p)A[b?]pA[|b?|]A(p)\supseteq A[|b?|]p,结合上式,故得到A[b?]A(p)=A[b?]pA[|b?|]A(p)=A[|b?|]p

    同理也可以得到A[¬b?]A(p)=A[¬b?]pA[|\neg b?|]A(p)=A[|\neg b?|]p

\square 证毕。