automatic complexity analysis of simple imperative programs zachi mann
TRANSCRIPT
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
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.
A Short Example
may grow exponentially!
output value bounded by a polynomial in it’s input ?
Ben-Amram, Jones & Kristiansen (2008)
• Sound & complete compositional analysis algorithm running in polynomial time.
• Algorithm assigns a certificate(DFR) to each command: DFR
Ben-Amram, Jones & Kristiansen (2008)• DFR left part represents the variables dependencies.
type:
DFR
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
Ben-Amram (2010)
• Core language is extended with the constant zero.
• The analysis problem is shown to be PSPACE-complete.
Back to the Example
may grow exponentially is polynomially bounded
Ben-Amram (2010)
• Problem solved by applying context sensitive analysis.– Dependence Judgments:
– Inference Rules:
– Example (assume program has 3 variables):
Ben-Amram (2010)
• Inference rules (cont.)Another example - multiplication:
Formally:
Ben-Amram (2010)
• The link between inference rules and DFR:– The inference rules generate the variable
dependences (arcs) within the DFR.
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.
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
Performance Comparison
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)