Review. Abstract Interpretation. Part II. Lecture 19. Notes (Cont.) Review: Calculating the LFP

Similar documents
Programming Language Features (cont.) CMSC 330: Organization of Programming Languages. Parameter Passing in OCaml. Call-by-Value

Chapter 7: Functional Programming Languages

1 if 1 x 0 1 if 0 x 1

Regression Verification: Status Report

Creating, Solving, and Graphing Systems of Linear Equations and Linear Inequalities

MAT12X Intermediate Algebra

Review; questions Discussion of Semester Project Arbitrary interprocedural control flow Assign (see Schedule for links)

Cartesian Products and Relations

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Observational Program Calculi and the Correctness of Translations

Address Taken FIAlias, which is equivalent to Steensgaard. CS553 Lecture Alias Analysis II 2

The Clean programming language. Group 25, Jingui Li, Daren Tuzi

Cassandra. References:

MA107 Precalculus Algebra Exam 2 Review Solutions

recursion, O(n), linked lists 6/14

Dynamic Programming. Lecture Overview Introduction

Collinear Points in Permutations

5 Numerical Differentiation

f(x) = g(x), if x A h(x), if x B.

MATH 425, PRACTICE FINAL EXAM SOLUTIONS.

Answer Key for California State Standards: Algebra I

INTRUSION PREVENTION AND EXPERT SYSTEMS

Graphing calculators Transparencies (optional)

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Limits and Continuity

Polynomial and Rational Functions

Static Taint-Analysis on Binary Executables

Data Structures and Algorithms

Algorithms are the threads that tie together most of the subfields of computer science.

Basic Concepts of Set Theory, Functions and Relations

Fixed-Point Logics and Computation

The Epsilon-Delta Limit Definition:

1 Review of Newton Polynomials

Algebra I Vocabulary Cards

Summary Last Lecture. Automated Reasoning. Outline of the Lecture. Definition sequent calculus. Theorem (Normalisation and Strong Normalisation)

Practice with Proofs

Software Analysis (POPA Sec , 2.5.4, 2.5.6)

ML for the Working Programmer

A Static Analyzer for Large Safety-Critical Software. Considered Programs and Semantics. Automatic Program Verification by Abstract Interpretation

Deterministic Discrete Modeling

facultad de informática universidad politécnica de madrid

Integration. Topic: Trapezoidal Rule. Major: General Engineering. Author: Autar Kaw, Charlie Barker.

Describing, manipulating and pricing financial contracts: The MLFi language

Functional Programming. Functional Programming Languages. Chapter 14. Introduction

Algebra Unpacked Content For the new Common Core standards that will be effective in all North Carolina schools in the school year.

03 - Lexical Analysis

12.6 Logarithmic and Exponential Equations PREPARING FOR THIS SECTION Before getting started, review the following:

Second Order Linear Nonhomogeneous Differential Equations; Method of Undetermined Coefficients. y + p(t) y + q(t) y = g(t), g(t) 0.

Making Dynamic Memory Allocation Static To Support WCET Analyses

Lecture 11: Tail Recursion; Continuations

FIRST YEAR CALCULUS. Chapter 7 CONTINUITY. It is a parabola, and we can draw this parabola without lifting our pencil from the paper.

MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.436J/15.085J Fall 2008 Lecture 5 9/17/2008 RANDOM VARIABLES

11 Multivariate Polynomials

f(x) = a x, h(5) = ( 1) 5 1 = 2 2 1

is identically equal to x 2 +3x +2

In mathematics, it is often important to get a handle on the error term of an approximation. For instance, people will write

Functional programming languages

Applications of obfuscation to software and hardware systems

Understanding Basic Calculus

10.2 Series and Convergence

3.1 Solving Systems Using Tables and Graphs

Andrew Pitts chapter for D. Sangorgi and J. Rutten (eds), Advanced Topics in Bisimulation and Coinduction, Cambridge Tracts in Theoretical Computer

HECTOR a software model checker with cooperating analysis plugins. Nathaniel Charlton and Michael Huth Imperial College London

Lecture 1. Basic Concepts of Set Theory, Functions and Relations

Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.

This unit will lay the groundwork for later units where the students will extend this knowledge to quadratic and exponential functions.

Numerical Methods for Option Pricing

Operation Count; Numerical Linear Algebra

Relational Calculus. Module 3, Lecture 2. Database Management Systems, R. Ramakrishnan 1

Tennessee Department of Education

Probabilità e Nondeterminismo nella teoria dei domini

Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007

Pearson Algebra 1 Common Core 2015

Definition 8.1 Two inequalities are equivalent if they have the same solution set. Add or Subtract the same value on both sides of the inequality.

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

Vector and Matrix Norms

Test Case Design Techniques

parent ROADMAP MATHEMATICS SUPPORTING YOUR CHILD IN HIGH SCHOOL

1 Definition of a Turing machine

Random vs. Structure-Based Testing of Answer-Set Programs: An Experimental Comparison

Sequential Data Structures

Near Optimal Solutions

Why Study NP- hardness. NP Hardness/Completeness Overview. P and NP. Scaling 9/3/13. Ron Parr CPS 570. NP hardness is not an AI topic

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

o-minimality and Uniformity in n 1 Graphs

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

3.2 LOGARITHMIC FUNCTIONS AND THEIR GRAPHS. Copyright Cengage Learning. All rights reserved.

Chapter 2: Linear Equations and Inequalities Lecture notes Math 1010

DATA QUALITY DATA BASE QUALITY INFORMATION SYSTEM QUALITY

1 Lecture: Integration of rational functions by decomposition

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

Section 4.1 Rules of Exponents

IF The customer should receive priority service THEN Call within 4 hours PCAI 16.4

Explain how Employee Performance is Measured and Managed

Module 1, Lesson 3 Temperature vs. resistance characteristics of a thermistor. Teacher. 45 minutes

What is Linear Programming?

The Method of Partial Fractions Math 121 Calculus II Spring 2015

Math 120 Final Exam Practice Problems, Form: A

DRAFT. Algebra 1 EOC Item Specifications

Notes on metric spaces

Transcription:

Review Abstract Interpretation Part II def f(x) = if x = 0 then 1 else x f(x + -1) Abstraction: ( σ ʹ ( = + )) lfp if x 0 then 1 else x f(x -1) Simplified: ( λ λ + ( + )) lfp f. x. x f(x ) 1 2 Review: Calculating the LFP ( λ λ + ( + )) lfp f. x. x f(x ) f 0 = f 1 = + + + + f 2 = T T + T f 3 = T T T T Notes (Cont.) Lesson: The fixed point is being computed in the domain (A A) A A The fixed point is not being computed in A A Make sure you check the domain of the fixed point operator. 3 4 Strictness Analysis Overview In lazy functional languages, it may be desirable to change call-by-need (lazy evaluation) to call-by-value. Strictness Analysis CBN requires building thunks (closures) to capture the lexical environment of unevaluated expressions. CBV evaluates its argument immediately, which is wasteful (or even wrong) if the argument is never evaluated under CBN. 5 6 1!

Correctness Substituting CBV for CBN is always correct if we somehow know that a function evaluates its argument(s). A function f is strict if f ( ) = Observation: if f is strict, then it is correct to pass arguments to f by value. Outline Deciding whether a function is strict is undecidable. Mycroft s idea: Use abstract interpretation. Correctness condition: If f is non-strict, we must report that it is non-strict. 7 8 The Abstract Domain Concretization/Abstraction Continue working with the same language (1 recursive function of 1 variable). New abstract domain 2: 1 0 The concretization/abstraction functions say 0 means the computation definitely diverges 1 means nothing is known about the computation D is the concrete domain γ(0) = { } α( { }) = 0 γ(1) = D α( S) = 1 if S { } 9 10 Abstract Semantics Abstract Semantics (Cont.) Next step is to define an abstract semantics Transform f:int Int to f:2 2 Transform values v:int To test strictness check if to v:2 f(0) = 0 An a stands for an abstract value (0 or 1). Treat 0,1 as false, true respectively. σ ʹ x ( g)( a) = a σ ʹ i ( g)( a) = 1 σʹ e( g)( a) = σʹ e( g)( a) σʹ e ( )( ) ( )( ) ( )( ) 1 e g a = σʹ 2 e g a σʹ 1 e g a 2 σ' ( g)( a) = g( σʹ ( g)( a)) f ( e) e 11 12 2!

The Rest of the Rules An Example σʹ e1 ( g)( a) = σʹ e ( g)( a) σʹ ( )( ) 1 e g a 2 + e2 σʹ ( g)( a) = σʹ ( g)( a) σʹ ( g)( a) e1/ e2 = e if e1 2 then e3 else e4 def f e1 e2 ( ) σʹ ( g)( a) = σʹ ( g)( a) σʹ ( g)( a) σʹ ( g)( a) σʹ ( g)( a) σ = e e1 e2 e3 e4 = lfp σʹ e def f(x) = if x = 0 then 1 else x f(x + -1) ( σ ʹ ( = + )) lfp if x 0 then 1 else x f(x -1) ( ) lfp λf. λx.x = λaa. ( λaa. ) 0 = 0 The function is strict in x. 13 14 Calculating the LFP Another Example ( λ λ ( )) lfp f. x.x 1 1 (x f(x 1)) f 0 = 0 0 f 1 = f 2 = Generalize to recursive functions of two variables. def f(x,y) = if x = 0 then 0 else f(x + -1,f(x,y)) ( σ ( )) lfp ʹ if x = 0 then 0 else f(x + -1,f(x,y)) = lfp( λf. λ(x, y). x 1 (1...)) = λ(x,y). x 15 16 Example (Cont.) Summary of Strictness Analysis For multi-argument functions, check each argument combination of the form (1,,1,0,1,,1). ( λ ) ( λ ) (x, y). x (0,1) = 0 (x, y). x (1,0) = 1 X can be passed by value. Unsafe to pass Y by value. Mycroft s technique is sound and practical. Widely implemented for lazy functional languages. Makes modest improvement in performance (a few %). The theory of abstract interpretation is critical here. Mycroft s technique treats all values as atomic. No refinement for components of lists, tuples, etc. Many research papers take up improvements for data types, higher-order functions, etc. Most of these are very slow. 17 18 3!

Conclusions The Cousot&Cousot paper(s) generated an enormous amount of other research. Abstract interpretation as a theory and abstract interpretation as a method of constructing tools are often confused. Slogan of most researchers: Where is Abstract Interpretation Weak? Theory is completely general The part of the original paper people understand is limited Finite domains + monotonic functions Finite Lattices + Monotonic Functions = Program Analysis 19 20 Data Structures and the Heap Size of Domains Requires a finite abstraction Which may be tuned to the program More often is empty list, list of length 1, unknown length Similar comments apply to analyzing heap properties E.g., a cell has 0 references, 1 references, many references Large domains = slow analysis In practice, domains are forced to be small Chain height is the critical measure The focus in abstract interpretation is on correctness Not much insight into efficient algorithms 21 22 Higher-Order Functions Forwards vs. Backwards Makes clear how to handle higher-order functions Model as abstract, finite functions Ordering on functions is pointwise Problem: huge domains Break with the dependence on control-flow graphs The forwards vs. backwards mentality permeates much of the abstract interpretation literature But nothing in the theory says it has to be that way 23 24 4!

Background Consider the program Context Sensitivity G(x) = if * then M(0,x) else M(x,0) M(a,b) = a * b What is the rule-of-signs result for this program? 25 26 Strategy 1: Compute One Signature/Function Strategy 2: Inline M Evaluate G(T,T) Results in evaluating M(0,T) Results in evaluating M(T,0) Take upper bounds on all possible values of each argument Final information M(T,T) = T A monomorphic analysis G(x) = if * then 0 * x else x * 0 Now we have G(T) = 0 Note that inlining Separates the two uses of M Allows different information to be assigned to each use 27 28 Strategy 3: Compute Signature for M G(x) = if * then M(0,x) else M(x,0) M(a,b) = a * b Analysis of M is Discussion Monomorphic analysis is often imprecise Combines all possible arguments arising at each use of function Crucial issue is that correlations between arguments are lost E.g., M(0,T) and M(T,0) become M(T,T) Now use signature/table for M in analysis of G Same result as inlining! 29 Many advantage is that it is cheap Polynomial time 30 5!

Discussion (Cont.) Inlining maintains correlations between function arguments By analyzing every use of a function separately Using a precomputed signature for a function is similar to inlining Usually more efficient, as function is analyzed once For finite domains, just as precise But could be less precise than inlining for more complicated abstract domains Discussion (Cont.) Inlining is a poor choice in practice Exponential blowup Doesn t even work in presence of recursion Two most common strategies Reanalyze function for each distinct arguments Moral equivalent of inlining Exponential in time, not necessarily in space Compute function summaries Requires fixed points to deal with recursion 31 32 More Context Sensitivity Example Call site sensitivity is not the only kind of context sensitivity Consider the abstraction of allocation new C Class X { int val; set(v) = val <- v; return this } m(y) = return val * y Typically all values allocated at the same syntactic point share one abstract value f(y) = return (new X).set(y) 33 34 Example (Cont.) Summary Compare (new X).set(0).m(z) + (new X).set(1).m(0) Context-sensitivity is very important to accurate analysis of software To maintain correlations between program quantities f(0).m(z) + f(1).m(0) Unfortunately, solutions are generally exponential In practice, systems either avoid it or pay a large performance price to have context sensitivity 35 36 6!