APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) 1 / 26 APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) Jurriaan Hage e-mail: [email protected]homepage: http://www.cs.uu.nl/people/jur/ Department of Information and Computing Sciences, Universiteit Utrecht March 25, 2009 Center for Software Technology Jurriaan Hage
28
Embed
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) - cs.uu.nl fileDepartment of Information and Computing Sciences, Universiteit Utrecht March 25, 2009 Center for Software Technology Jurriaan
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) > Galois Connections and Galois Insertions 8 / 26
Every Connection can be made into an Insertion
How?
Remove superfluous elements from M.
Often, Galois Connections are easier to specify:
In the example we would be forced to enumerate the five caseswhich are allowed.
In the book, reduncancy removal by reduction function:ς(a) = a− {(0, odd)}.
Center for Software Technology Jurriaan Hage
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) > Galois Connections and Galois Insertions 9 / 26
Adjoints
Mα
γ
v v
a
α(c)c
γ(a)
L
An equivalent way of phrasing the demands.
Now α and γ are total functions between L and M.
Abstraction of less gives less: c v γ(a) implies α(c) v a.
Concretization of more gives more: α(c) v a implies c v γ(a).
The above restrictions define when (L, α, γ,M) is an adjoint.
Proposition 4.20: adjoints are Galois Connections and vice versa.
Center for Software Technology Jurriaan Hage
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) > Galois Connections and Galois Insertions 10 / 26
Some example abstractions
Reachability: M = Lab∗ → {⊥,>}. ⊥ describes “not reachable”,> describes “might be reachable”.
Undefined variable analysis: M = Var∗ → {⊥,>} where >describes “might get a value”, ⊥ describes “never gets a value”.
Possibly add program points to find out which variables might beused, before they get their value: M = Lab∗ → Var∗ → {⊥,>}Detection of Signs Analysis: we have seen it already
Detection of Parity Analysis: see the chapter of Nielson and Joneson the APA website.
L = Lab∗ → P(Var∗ → Z) is a relational lattice,T = Lab∗ → Var∗ → P(Z) is only suited for independentattribute analysis.
[1 7→ {[x 7→ 2, y 7→ −3], [x 7→ 0, y 7→ 0]}] is abstracted to[1 7→ [x 7→ {0, 2}, y 7→ {−3, 0}]].Abstraction is done for each program point independently.
Start by finding a Galois Connection (α′1, γ′1) from
L′ = P(Var∗ → Z) to T ′ = Var∗ → P(Z).
α′1(S) = λv . {z | ∃f ∈ S . z = f (v)}Collect for each variable v all the values it maps to.
γ′1 unfolds sets of values to sets of functions,simply by taking all combinations.
We get [1 7→ {[x 7→ 2, y 7→ −3], [x 7→ 0, y 7→ 0],[x 7→ 2, y 7→ 0], [x 7→ 0, y 7→ −3]}]
T = Lab∗ → Var∗ → P(Z) and M = Lab∗ → Var∗ → Interval.
First abstract P(Z) to Interval, then apply total function spacecombinator twice.
Abstraction from P(Z) to Interval is relatively easy:S ⊆ P(Z) abstracts to α′′2(S) = [inf ′(S), sup′(S)] whereinf ′(∅) =∞, and inf ′(S) = −∞ if S has no smallest element.
sup′ can be similarly defined.
Concretization is easier: γ′′2 (I ) = {x | x ≥ inf(I ) ∧ x ≤ sup(I )}.Applying the total function space combinator twice in successionfirst adds Var∗, then Lab∗.
L = Lab∗ → P(Var∗ → Z) to M = Lab∗ → Var∗ → Interval
we constructed two Galois Connections by handfrom P(Var∗ → Z) to Var∗ → P(Z), andfrom P(Z) to Interval.Proofs that these are Galois Connections/adjoints should be made.
Usually, easy but tedious.
The remainder of the work was done by application of generalresults:
lifting a Galois Connection between two lattices to one where acertain amount of context was added,composing Galois Connections sequentially.
Further abstraction to Lab∗ → Var∗ → P({−, 0,+}) is perfectlypossible.
Center for Software Technology Jurriaan Hage
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) > Other useful combinators 23 / 26
Direct product
Starting from the lattice P(Z) we can obtain separate GaloisConnections to M1 = P({odd, even}) and M2 = P({−, 0,+}).
Combine the two into one Galois Insertion betweenL = P(Z) and M = P({odd, even})× P({−, 0,+}).
Given that we have (L, α1, γ1,M1) and (L, α2, γ2,M2) we obtain(L, α, γ,M1 ×M2) where
α(c) = (α1(c), α2(c)) andγ(a1, a2) = γ1(a1) u γ2(a2)
Why take the meet (greatest lower bound)?
It enables us to ignore combinations (a1, a2) that cannot occur.
γ({odd}, {0}) = γ1({odd})∩γ2({0}) = {. . . ,−1, 1, . . .}∩{0} = ∅.One can prove that (L, α, γ,M1 ×M2) is an adjoint.
Verify that for all c ∈ L, (a1, a2) ∈ M1 ×M2:
α(c) v (a1, a2) iff c v γ(a1, a2)
Center for Software Technology Jurriaan Hage
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) > Other useful combinators 23 / 26
Direct product
Starting from the lattice P(Z) we can obtain separate GaloisConnections to M1 = P({odd, even}) and M2 = P({−, 0,+}).
Combine the two into one Galois Insertion betweenL = P(Z) and M = P({odd, even})× P({−, 0,+}).
Given that we have (L, α1, γ1,M1) and (L, α2, γ2,M2) we obtain(L, α, γ,M1 ×M2) where
α(c) = (α1(c), α2(c)) andγ(a1, a2) = γ1(a1) u γ2(a2)
Why take the meet (greatest lower bound)?It enables us to ignore combinations (a1, a2) that cannot occur.
γ({odd}, {0}) = γ1({odd})∩γ2({0}) = {. . . ,−1, 1, . . .}∩{0} = ∅.One can prove that (L, α, γ,M1 ×M2) is an adjoint.
Verify that for all c ∈ L, (a1, a2) ∈ M1 ×M2:
α(c) v (a1, a2) iff c v γ(a1, a2)
Center for Software Technology Jurriaan Hage
APA 2007/2008 Lecture 13 (Sec. 4.3-4.4) > Other useful combinators 24 / 26
The independent attribute method
γ1
γ2
L2 M2
L1 × L2=⇒ M1 ×M2
(γ1, γ2)
(α1, α2)α2
α1
M1L1
Example: L1 = L and M1 = M, and M2 is some abstraction of L2
which describes the state of the heap at different program points.
We can define α and γ between L1 × L2 and M1 ×M2 as follows: