automatic complexity analysis of simple imperative programs zachi mann

16
Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Upload: claire-gibson

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Automatic Complexity Analysis of Simple Imperative Programs

Zachi Mann

Page 2: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Consider the following “Core” Language:

• Non-deterministic branchingBounded non-deterministic loops

Variables hold only positive integer values

Page 3: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Problem Statement

• The polynomial-bound analysis problem is to find, for any given command, which output variables are bounded by a polynomial in the input variables.

• A variant: The linear-bound problem identifies linearly-bounded output values instead.

• The problem can be easily extended to identify the overall runtime upper bound.

Page 4: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

A Short Example

may grow exponentially!

output value bounded by a polynomial in it’s input ?

Page 5: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram, Jones & Kristiansen (2008)

• Sound & complete compositional analysis algorithm running in polynomial time.

• Algorithm assigns a certificate(DFR) to each command: DFR

Page 6: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram, Jones & Kristiansen (2008)• DFR left part represents the variables dependencies.

type:

DFR

Page 7: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram, Jones & Kristiansen (2008)

• Example:

• DFR right part is used to identify computations that double an input value by adding two copies of it:

DFR

Page 8: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram (2010)

• Core language is extended with the constant zero.

• The analysis problem is shown to be PSPACE-complete.

Page 9: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Back to the Example

may grow exponentially is polynomially bounded

Page 10: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram (2010)

• Problem solved by applying context sensitive analysis.– Dependence Judgments:

– Inference Rules:

– Example (assume program has 3 variables):

Page 11: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram (2010)

• Inference rules (cont.)Another example - multiplication:

Formally:

Page 12: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Ben-Amram (2010)

• The link between inference rules and DFR:– The inference rules generate the variable

dependences (arcs) within the DFR.

Page 13: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Implementation• Bottom Up– For every command the set of all true judgments are

generated.• Top Down– An abstract interpreter generates for every command

the dependence judgments according to the inference rules and the reset contexts that were computed so far from previous commands.

• Output Extension– Algorithm output is extended to include a description

of a computation path which results with each computed variable dependence.

Page 14: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Loops

A command is analysed in 3 steps:1. Consider case where loop body is skipped

Similar to analysis of the skip command.2. Consider any iterations

Least Fixed Point.3. Loop Correction

Page 15: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Performance Comparison

Page 16: Automatic Complexity Analysis of Simple Imperative Programs Zachi Mann

Related Work

• What happens if features are added/dropped from the core language? – Deterministic loops, the constant 1,

weak assignment, …• Is the analysis problem decidable? With what

run time complexity?– Some answers in paper by

Amir Ben Amram & Lars Kristiansen (2011)