Newtonian Program Analysis: Solving Sharir and Pnueli s Equations

Similar documents
Newtonian Program Analysis

Newtonian Program Analysis

On Fixed Point Equations over Commutative Semirings

Solving fixed-point equations over semirings

An Extension of Newton s Method to ω-continuous Semirings

Program Analyses using Newton s Method

Interprocedural Dataflow Analysis, Part III: Newtonian Program Analysis Via Tensor Product CS701

A CS look at stochastic branching processes

Problem. Problem Given a dictionary and a word. Which page (if any) contains the given word? 3 / 26

Introduction to Kleene Algebras

FPsolve: A Generic Solver for Fixpoint Equations over Semirings

Kleene Algebra and Arden s Theorem. Anshul Kumar Inzemamul Haque

Binary Search Trees. Motivation

An Overview of Residuated Kleene Algebras and Lattices Peter Jipsen Chapman University, California. 2. Background: Semirings and Kleene algebras

R ij = 2. Using all of these facts together, you can solve problem number 9.

Convergence Thresholds of Newton s Method for Monotone Polynomial Equations

Chapter 5 The Witness Reduction Technique

Characterizing the Equational Theory

Axioms of Kleene Algebra

CPSC 467: Cryptography and Computer Security

3.1 Introduction. Solve non-linear real equation f(x) = 0 for real root or zero x. E.g. x x 1.5 =0, tan x x =0.

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

More Asymptotic Analysis Spring 2018 Discussion 8: March 6, 2018

Compositional Recurrence Analysis Revisited

CS 395T Computational Learning Theory. Scribe: Mike Halcrow. x 4. x 2. x 6

Two Approaches to Interprocedural Data Flow Analysis

Calculus. Central role in much of modern science Physics, especially kinematics and electrodynamics Economics, engineering, medicine, chemistry, etc.

CMPUT 675: Approximation Algorithms Fall 2014

Flow grammars a flow analysis methodology

Compositional Recurrence Analysis Revisited

Chapter 1. Root Finding Methods. 1.1 Bisection method

Algorithms and Theory of Computation. Lecture 2: Big-O Notation Graph Algorithms

Bounded-width QBF is PSPACE-complete

EECS 229A Spring 2007 * * (a) By stationarity and the chain rule for entropy, we have

Algorithms and Their Complexity

Exponential and logarithm functions

Completeness of Star-Continuity

Notes for Lecture 11

Solving Monotone Polynomial Equations

arxiv: v1 [cs.fl] 2 Oct 2018

Provenance Semirings. Todd Green Grigoris Karvounarakis Val Tannen. presented by Clemens Ley

Is g one-to-one? Is g onto? Why? Solution: g is not one-to-one, since for c A, g(b) = g(c) = c. g is not onto, since a / g(a).

M17 MAT25-21 HOMEWORK 6

Notes for Lecture Notes 2

Notes on Machine Learning for and

Linear Discrimination Functions

INF2220: algorithms and data structures Series 1

30 Classification of States

1 Alphabets and Languages

A first order divided difference

Solutions or answers to Final exam in Error Control Coding, October 24, G eqv = ( 1+D, 1+D + D 2)

Algorithms 2/6/2018. Algorithms. Enough Mathematical Appetizers! Algorithm Examples. Algorithms. Algorithm Examples. Algorithm Examples

CS Communication Complexity: Applications and New Directions

Chapter 4: Computation tree logic

Notes for Lecture 25

Space-efficient scheduling of stochastically generated tasks

COMPSCI 650 Applied Information Theory Apr 5, Lecture 18. Instructor: Arya Mazumdar Scribe: Hamed Zamani, Hadi Zolfaghari, Fatemeh Rezaei

ROOT FINDING REVIEW MICHELLE FENG

Tree Adjoining Grammars

d(ν) = max{n N : ν dmn p n } N. p d(ν) (ν) = ρ.

FIXED POINT ITERATION

1 Circuit Complexity. CS 6743 Lecture 15 1 Fall Definitions

Expectation propagation for symbol detection in large-scale MIMO communications

Domain theory and denotational semantics of functional programming

1 Differentiability at a point

CS 188 Introduction to Fall 2007 Artificial Intelligence Midterm

Announcements. CompSci 102 Discrete Math for Computer Science. Chap. 3.1 Algorithms. Specifying Algorithms

Elliptic Curve Discrete Logarithm Problem

Math 262A Lecture Notes - Nechiporuk s Theorem

* 8 Groups, with Appendix containing Rings and Fields.

An Algorithm better than AO*?

Approximative Methods for Monotone Systems of min-max-polynomial Equations

Before We Start. The Pumping Lemma. Languages. Context Free Languages. Plan for today. Now our picture looks like. Any questions?

GALOIS THEORY : LECTURE 4 LEO GOLDMAKHER

Notes for Lecture 15

Time stealing: An adventure in tropical land

Exercises 1 - Solutions

2. As we shall see, we choose to write in terms of σ x because ( X ) 2 = σ 2 x.

1. Prove: A full m- ary tree with i internal vertices contains n = mi + 1 vertices.

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

Some Remarks on Minimal Clones

3. Algorithms. What matters? How fast do we solve the problem? How much computer resource do we need?

An analogy from Calculus: limits

A CHARACTERIZATION OF LOCALLY FINITE VARIETIES THAT SATISFY A NONTRIVIAL CONGRUENCE IDENTITY

Lecture 7: Quantum Fourier Transform over Z N

CHAPTER 6. Differentiation

Introduction to Temporal Logic. The purpose of temporal logics is to specify properties of dynamic systems. These can be either

CSCI 3110 Assignment 6 Solutions

Universität Augsburg

1 Computational Problems

CS 6110 Lecture 21 The Fixed-Point Theorem 8 March 2013 Lecturer: Andrew Myers. 1 Complete partial orders (CPOs) 2 Least fixed points of functions

Supplement. Algebraic Closure of a Field

MATH 4211/6211 Optimization Basics of Optimization Problems

Monoidal Categories, Bialgebras, and Automata

PAC Learning. prof. dr Arno Siebes. Algorithmic Data Analysis Group Department of Information and Computing Sciences Universiteit Utrecht

Lecture 16. Error-free variable length schemes (contd.): Shannon-Fano-Elias code, Huffman code

Research Statement Christopher Hardin

Semirings for Breakfast

The maximum-subarray problem. Given an array of integers, find a contiguous subarray with the maximum sum. Very naïve algorithm:

Transcription:

Newtonian Program Analysis: Solving Sharir and Pnueli s Equations Javier Esparza Technische Universität München Joint work with Stefan Kiefer and Michael Luttenberger

From programs to equations: Intraprocedural x > 0 x = 0 x x + 1 x < 10 x 10

From programs to equations: Intraprocedural c Y a d X b One-step relations a,..., e (IN IN) c = {(x, x + 1) x 0} Big-step relations X, Y, Z IN IN Z e X Y = a Y + b = c Z Z = d Y + e

From programs to equations: Intraprocedural c Y a d X b One-step relations a,..., e (IN IN) c = {(x, x + 1) x 0} Big-step relation X IN IN Z e X Y = a Y + b = c Z Z = d Y + e

From programs to equations: Intraprocedural c Y a d X b One-step relations a,..., e (IN IN) c = {(x, x + 1) x 0} Big-step relations X, Y, Z IN IN Z e X Y = a Y + b = c Z Z = d Y + e

From programs to equations: Intraprocedural c Y a d X b One-step relations a,..., e (IN IN) c = {(x, x + 1) x 0} Big-step relations X, Y, Z IN IN Z e X Y = a Y + b = c Z Z = d Y + e

From programs to equations: Intraprocedural Program system X = f (X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2 IN abstract domain D transformer f abstract transformer f # Sufficient condition for existence of least solution: (D, +, ) is a (ω-continuous) semiring

From programs to equations: Intraprocedural Program system X = f (X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2 IN abstract domain D transformer f abstract transformer f # Sufficient condition for existence of least solution: (D, +, ) is a (ω-continuous) semiring

From programs to equations: Intraprocedural Program system X = f (X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2 IN abstract domain D transformer f abstract transformer f # Sufficient condition for existence of least solution: (D, +, ) is a (ω-continuous) semiring

From programs to equations: Intraprocedural Program system X = f (X) of linear fixed-point equations Least solution non-computable in general Program analysis: domain 2 IN abstract domain D transformer f abstract transformer f # Sufficient condition for existence of least solution: (D, +, ) is a (ω-continuous) semiring

Quantitative program analysis: Expected time X 0.7 Y X = 0.7 Y + 1 1 0.6 0.3 Y = Z + 1 Z Z = 0.6 Y + 1 0.4

From programs to equations: Interprocedural P Q x > 0 x = 0 x < 3 x 3 call Q x < 10 call Q call P x 10 x x 2

From programs to equations: Interprocedural P Q P 0 a e Q 0 f P 0 = a P 1 + b P 1 =?? P 2 P 1 Q 1 Q 2 P 2 = c P 1 + d call Q c b call Q call P Q 0 = e Q 1 + f Q 2 P 2 d g Q 3 Q 1 =?? Q 3 Q 2 =?? Q 3 Q 3 = g

From programs to equations: Interprocedural P Q P 0 = a P 1 + b P 0 Q 0 P 1 =?? P 2 a e f P 2 = c P 1 + d P 1 Q 1 Q 2 Q 0 = e Q 1 + f Q 2 call Q c b call Q call P Q 1 =?? Q 3 P 2 d g Q 3 Q 2 =?? Q 3 Q 3 = g

Sharir and Pnueli s functional approach P Q P 0 a e Q 0 f P 0 = a P 1 + b Q 0 P 1 = Q 0 P 2 P 2 = c P 1 + d P 1 Q 1 Q 2 Q 0 = e Q 1 + f Q 2 call Q c b call Q call P Q 1 =?? Q 3 P 2 d g Q 3 Q 2 =?? Q 3 Q 3 = g

Sharir and Pnueli s functional approach P Q P 0 a e Q 0 f P 0 = a P 1 + b Q 0 P 1 = Q 0 P 2 P 2 = c P 1 + d P 1 Q 1 Q 2 Q 0 = e Q 1 + f Q 2 call Q c b call Q call P Q 0 Q 1 =?? Q 3 P 2 d g Q 3 Q 2 =?? Q 3 Q 3 = g

Sharir and Pnueli s functional approach P Q P 0 a e Q 0 f P 0 = a P 1 + b Q 0 P 1 = Q 0 P 2 P 2 = c P 1 + d P 1 Q 1 Q 2 Q 0 = e Q 1 + f Q 2 call Q c b call Q call P Q 0 Q 1 =?? Q 3 P 2 d g Q 3 Q 2 =?? Q 3 Q 3 = g P 0

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 2 IN abstract domain D transformer f abstract transformer f # Sufficient condition for existence of least solution: (D, +, ) is a (ω-continuous) semiring

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 2 IN abstract domain D transformer f abstract transformer f # Sufficient condition for existence of least solution: (D, +, ) is a (ω-continuous) semiring

Solving the equations: Kleene iteration Theorem [Kleene]: The least solution µf of X = f (X) is the supremum of {k i } i 0, where k 0 = f (0) k i+1 = f (k i ) Basic algorithm: compute k 0, k 1, k 2,... until either k i = k i+1, which implies k i = µf, or the approximation is considered adequate.

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: k i = (ɛ + a +... + a i )b Probabilistic interpretation: convergence can be very slow for polynomial equations [EY STACS05]. X = 1 2 X 2 + 1 2 µf = 1 = 0.99999... Logarithmic convergence : k iterations to get log k bits of accuracy. k n 1 1 n + 1 k 2000 = 0.9990

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Kleene Iteration for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Newton s Method for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Newton s Method for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Newton s Method for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Newton s Method for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Newton s Method for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

Newton s Method for X = f (X) (univariate case) 1.2 1 µf 0.8 0.6 f (X) 0.4 0.2 0 0.2 0.4 0.6 0.8 1 1.2

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?

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?

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

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.

Overcoming the obstacles (1) Use the algebraic definition of differential (recall that we only have polynomial functions!) 0 if f (X) = c X if f (X) = X Df (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

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(3 n ) iterations. Theorem: This is exactly Newton s sequence. Moreover, the fixed point is reached after at most n iterations.

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(3 n ) iterations. Theorem: This is exactly Newton s sequence. Moreover, the fixed point is reached after at most n iterations.

Two (quick) examples of application

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(); } } }

May-Alias Analysis

May-Alias Analysis

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

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 l left s may only be aliased to the l-th element of the list. Data access paths with r right s and l left s may only be aliased to the (2r + l)-th element of the list, or to larger elements of the same parity.

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)

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.

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 0 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

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.

Commenting the works...

... of the giants

And yet... The glosses of Saint Emilianus, written around 1000 AC. Oldest writing in (a form of) Spanish, one of the most spoken languages in the world.

Shimon Even, 1935 2004 Amir Pnueli, 1941 2009