Newtonian Program Analysis: Solving Sharir and Pnuelis Equations - - PowerPoint PPT Presentation

newtonian program analysis solving sharir and pnueli s
SMART_READER_LITE
LIVE PREVIEW

Newtonian Program Analysis: Solving Sharir and Pnuelis Equations - - PowerPoint PPT Presentation

Newtonian Program Analysis: Solving Sharir and Pnuelis Equations Javier Esparza Technische Universit at M unchen Joint work with Stefan Kiefer and Michael Luttenberger From programs to equations: Intraprocedural x > 0 x = 0 x x


slide-1
SLIDE 1

Newtonian Program Analysis: Solving Sharir and Pnueli’s Equations

Javier Esparza

Technische Universit¨ at M¨ unchen

Joint work with Stefan Kiefer and Michael Luttenberger

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4

From programs to equations: Intraprocedural

x < 10 x > 0 x ≥ 10 x = 0 x ← x + 1

slide-5
SLIDE 5

From programs to equations: Intraprocedural

X d Y Z e a b c One-step relations

c = {(x, x + 1) | x ≥ 0}

a, . . . , e ⊆ (I

N × I N)

X = a · Y + b Y

= c · Z

Z

= d · Y + e

Big-step relations X, Y, Z ⊆ I

N × I N

slide-6
SLIDE 6

From programs to equations: Intraprocedural

X d Y Z e a b c One-step relations

c = {(x, x + 1) | x ≥ 0}

a, . . . , e ⊆ (I

N × I N)

X = a · Y + b Y

= c · Z

Z

= d · Y + e

Big-step relation X ⊆ I

N × I N

slide-7
SLIDE 7

From programs to equations: Intraprocedural

X d Y e a b c One-step relations

c = {(x, x + 1) | x ≥ 0}

a, . . . , e ⊆ (I

N × I N)

X = a · Y + b Y

= c · Z

Z

= d · Y + e

Big-step relations X, Y, Z ⊆ I

N × I N

Z

slide-8
SLIDE 8

From programs to equations: Intraprocedural

X d Y e a b c One-step relations

c = {(x, x + 1) | x ≥ 0}

a, . . . , e ⊆ (I

N × I N)

X = a · Y + b Y

= c · Z

Z

= d · Y + e

Big-step relations X, Y, Z ⊆ I

N × I N

Z

slide-9
SLIDE 9

From programs to equations: Intraprocedural

Program → system X = f(X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2I

N →

abstract domain D transformer f → abstract transformer f # Sufficient condition for existence of least solution: (D, +, ·) is a (ω-continuous) semiring

slide-10
SLIDE 10

From programs to equations: Intraprocedural

Program → system X = f(X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2I

N →

abstract domain D transformer f → abstract transformer f # Sufficient condition for existence of least solution: (D, +, ·) is a (ω-continuous) semiring

slide-11
SLIDE 11

From programs to equations: Intraprocedural

Program → system X = f(X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2I

N →

abstract domain D transformer f → abstract transformer f # Sufficient condition for existence of least solution: (D, +, ·) is a (ω-continuous) semiring

slide-12
SLIDE 12

From programs to equations: Intraprocedural

Program → system X = f(X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2I

N →

abstract domain D transformer f → abstract transformer f # Sufficient condition for existence of least solution: (D, +, ·) is a (ω-continuous) semiring

slide-13
SLIDE 13

Quantitative program analysis: Expected time

X

0.6

Y

0.4 0.7 0.3 1

Z X = 0.7 · Y + 1 Y

= Z + 1

Z

= 0.6 · Y + 1

slide-14
SLIDE 14

From programs to equations: Interprocedural

x < 10 x > 0 x ≥ 10 x = 0 call Q

P Q

x ← x ∗ 2 call Q call P x ≥ 3 x < 3

slide-15
SLIDE 15

From programs to equations: Interprocedural

c d call Q a

P

b call Q

Q

e f g call P P0 P1 P2 Q0 Q1 Q2 Q3 P0 = a · P1 + b P1 = ?? · P2 P2 = c · P1 + d Q0 = e · Q1 + f · Q2 Q1 = ?? · Q3 Q2 = ?? · Q3 Q3 = g

slide-16
SLIDE 16

From programs to equations: Interprocedural

c d call Q a

P

b call Q

Q

e f g call P P1 P2 P0 Q3 Q2 Q1 Q0 P0 = a · P1 + b P2 = c · P1 + d Q0 = e · Q1 + f · Q2 Q3 = g Q1 = ?? · Q3 Q2 = ?? · Q3 P1 = ?? · P2

slide-17
SLIDE 17

Sharir and Pnueli’s functional approach

c d call Q a

P

b call Q

Q

e f g call P P1 P2 P0 Q3 Q2 Q1 Q0 P0 = a · P1 + b P2 = c · P1 + d Q0 = e · Q1 + f · Q2 Q3 = g Q1 = ?? · Q3 Q2 = ?? · Q3 P1 = Q0 · P2

Q0

slide-18
SLIDE 18

Sharir and Pnueli’s functional approach

c d call Q a

P

b call Q

Q

e f g call P P1 P2 P0 Q3 Q2 Q1 Q0 P0 = a · P1 + b P2 = c · P1 + d Q0 = e · Q1 + f · Q2 Q3 = g Q1 = ?? · Q3 Q2 = ?? · Q3 P1 = Q0 · P2

Q0 Q0

slide-19
SLIDE 19

Sharir and Pnueli’s functional approach

c d call Q a

P

b call Q

Q

e f g call P P1 P2 P0 Q3 Q2 Q1 Q0 P0 = a · P1 + b P2 = c · P1 + d Q0 = e · Q1 + f · Q2 Q3 = g Q1 = ?? · Q3 Q2 = ?? · Q3

Q0

P1 = Q0 · P2

Q0 P0

slide-20
SLIDE 20

Sharir and Pnueli’s interprocedural equations

Program → system X = f(X) of polynomial, non-linear fixed-point equations Least solution non-computable in general Program analysis: domain 2I

N →

abstract domain D transformer f → abstract transformer f # Sufficient condition for existence of least solution: (D, +, ·) is a (ω-continuous) semiring

slide-21
SLIDE 21

Sharir and Pnueli’s interprocedural equations

Program → system X = f(X) of polynomial, non-linear fixed-point equations Least solution non-computable in general Program analysis: domain 2I

N →

abstract domain D transformer f → abstract transformer f # Sufficient condition for existence of least solution: (D, +, ·) is a (ω-continuous) semiring

slide-22
SLIDE 22

Solving the equations: Kleene iteration

Theorem [Kleene]: The least solution µf of X = f(X) is the supremum of {ki}i≥0 , where k0 = f(0) ki+1 = f(ki) Basic algorithm: compute k0, k1, k2, . . . until either ki = ki+1, which implies ki = µf, or the approximation is considered adequate.

slide-23
SLIDE 23

Kleene iteration is slow

Set domains: Kleene iteration never terminates for X = f(X) if least solution µf is an infinite set.

  • X = a · X + b

µf = a∗b

  • Kleene approximants are finite sets: ki = (ǫ + a + . . . + ai)b

Probabilistic interpretation: convergence can be very slow for polynomial equations [EY STACS05].

  • X = 1

2 X2 + 1 2 µf = 1 = 0.99999 . . .

  • “Logarithmic convergence”: k iterations to get log k bits of accuracy.

kn ≤ 1 − 1 n + 1 k2000 = 0.9990

slide-24
SLIDE 24

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-25
SLIDE 25

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-26
SLIDE 26

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-27
SLIDE 27

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-28
SLIDE 28

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-29
SLIDE 29

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-30
SLIDE 30

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-31
SLIDE 31

Kleene Iteration for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-32
SLIDE 32

Newton’s Method for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-33
SLIDE 33

Newton’s Method for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-34
SLIDE 34

Newton’s Method for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-35
SLIDE 35

Newton’s Method for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-36
SLIDE 36

Newton’s Method for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-37
SLIDE 37

Newton’s Method for X = f(X) (univariate case)

0.2 0.2 0.4 0.4 0.6 0.6 0.8 0.8 1 1 1.2 1.2

µf f(X)

slide-38
SLIDE 38

Kleene vs. Newton

Program analysis:

  • Kleene iteration is applicable to arbitrary ω-continuous semirings
  • . . . but converges slowly.

Numerical mathematics:

  • Newton’s Method converges fast
  • . . . but can only be applied to the real field

Can Newton’s method be generalized to arbitrary ω-continuous semirings?

slide-39
SLIDE 39

Kleene vs. Newton

Program analysis:

  • Kleene iteration is applicable to arbitrary ω-continuous semirings
  • . . . but converges slowly.

Numerical mathematics:

  • Newton’s Method converges fast
  • . . . but can only be applied to the real field

Can Newton’s method be generalized to arbitrary ω-continuous semirings?

slide-40
SLIDE 40

Mathematical formulation of Newton’s Method

Elementary analysis yields for the i-th Newton iterant νi: ν0 = 0 νi+1 = νi + ∆i where ∆i least solution of X = Df νi(X) + f(νi) − νi Df νi(X) differential of f(X) at the point νi

slide-41
SLIDE 41

Generalizing Newton’s method

Key point: generalize X = Df ν(X) + f(ν) − ν to arbitrary ω-continuous semirings In an arbitrary ω-continuous semiring

  • neither the differential Df ν(X), nor
  • the difference f(ν) − ν

are defined.

slide-42
SLIDE 42

Overcoming the obstacles

(1) Use the algebraic definition of differential (recall that we only have polynomial functions!) Df(X) =

            

if f(X) = c X if f(X) = X Dg(X) + Dh(X) if f(X) = g(X) + h(X) Dg(X) · h(X) + g(X) · Dh(X) if f(X) = g(X) · h(X) (2) Replace f(νi) − νi by any δi such that f(νi) = νi + δi Define ∆i as the least solution of X = Df νi(X) + δi

slide-43
SLIDE 43

Idempotent and commutative semirings

Theorem [Hopkins-Kozen LICS ’99]: The least fixed point of a system X = f(X) of n equations over an idempotent and commutative ω-continuous semiring is reached by the sequence ν0 = f(0) νi+1 = J(νi)∗ · f(νi) after at most O(3n) iterations. Theorem: This is exactly Newton’s sequence. Moreover, the fixed point is reached after at most n iterations.

slide-44
SLIDE 44

Idempotent and commutative semirings

Theorem [Hopkins-Kozen LICS ’99]: The least fixed point of a system X = f(X) of n equations over an idempotent and commutative ω-continuous semiring is reached by the sequence ν0 = f(0) νi+1 = J(νi)∗ · f(νi) after at most O(3n) iterations. Theorem: This is exactly Newton’s sequence. Moreover, the fixed point is reached after at most n iterations.

slide-45
SLIDE 45

Two (quick) examples of application

slide-46
SLIDE 46

May-Alias Analysis

listify(): transforms a binary tree of pointers into a list of pointers by reading the tree in preorder. void listifyL() { void listify() { T.move left(); L.push back(T→get data()); listify(); if( T.is leaf() == false ) { T.move up(); listifyL(); listifyR();

} } }

slide-47
SLIDE 47

May-Alias Analysis

slide-48
SLIDE 48

May-Alias Analysis

slide-49
SLIDE 49

May-Alias Analysis

Which data access paths of tree and list may point to the same element ? Access path of the tree: word w1 ∈ {left, right}∗ Access path of the list: word w2 ∈ {next}∗ May-alias information: set of pairs (w1, w2) such that w1, w2 may point to the same cell Commutative abstraction: (left right left, next next) → (3, 1, 2)

slide-50
SLIDE 50

May-Alias Analysis

Kleene iteration does not terminate. Newton’s method terminates after one iteration and provides the following information:

  • Data access paths with 0 right’s and ℓ left’s may only be aliased to

the ℓ-th element of the list.

  • Data access paths with r right’s and ℓ left’s may only be aliased to

the (2r + ℓ)-th element of the list, or to larger elements of the same parity.

slide-51
SLIDE 51

Lazy evaluation of And-Or trees

Nodes are only constructed and evaluated (to 0 or 1) if needed. (e.g., if left subtree of And-node evaluates to 1, right subtree is not constructed) function And(node) if node.leaf() then return node.value() else v := Or(node.left) if v = 0 then return 0 else return Or(node.right) function Or(node) if node.leaf() then return node.value() else v := And(node.left) if v = 1 then return 1 else return And(node.right)

slide-52
SLIDE 52

Assume the probabilities that node.leaf() returns true and node.value() returns 1 are both 1/2. We perform an analysis to compute the average runtime.

slide-53
SLIDE 53

Kleene vs. Newton

Neither Kleene nor Newton terminate, but Newton converges faster: i k(i) And 0 ν(i) And 0 k(i) And 1 ν(i) And 1 2.000 2.000 2.000 2.000 1 2.538 3.588 2.333 3.383 2 2.913 5.784 3.012 5.906 3 3.429 6.975 3.381 7.194 4 3.793 7.067 3.904 7.295

slide-54
SLIDE 54

Messages of this talk

The theory of solving “program analysis equations” is not be as well understood as we thought. We can learn from numerical mathematics and contribute to it. Go for unified theory of qualitative and quantitative program analysis.

slide-55
SLIDE 55

Commenting the works . . .

slide-56
SLIDE 56

. . . of the giants

slide-57
SLIDE 57

And yet . . .

The glosses of Saint Emilianus, written around 1000 AC. Oldest writing in (a form of) Spanish,

  • ne of the most spoken languages

in the world.

slide-58
SLIDE 58

Amir Pnueli, 1941−2009 Shimon Even, 1935−2004