Henny Sipma, November 16, 2006 Washington University at St Louis - p. 1/66 Constraint-Based Static Analysis of Programs Joint work with Michael Colon, Sriram Sankaranarayanan , Aaron Bradley and Zohar Manna Henny Sipma Stanford University Master Class Seminar at Washington University at St Louis, 2006
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 1/66
Constraint-Based Static Analysis ofPrograms
Joint work withMichael Colon, Sriram Sankaranarayanan, Aaron Bradley
and Zohar Manna
Henny SipmaStanford University
Master Class Seminar at Washington University at St Louis, 2006
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 2/66
Introduction
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 3/66
Motivation
Objective: To extract information about the program behaviorfrom the program text■ invariants■ termination■ temporal properties■ . . .
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 4/66
Trivial Example
integer i, j where i = 2 ∧ j = 0
ℓ0 : while (...) do
if (...) then
i := i + 4
else
(i, j) := (i + 2, j + 1)
i ≥ 2 , j ≥ 0 , and i − 2 j ≥ 2 are invariants.
Objective: To obtain such invariants automatically
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 5/66
Buffer Overflow Analysis
1: int *a = malloc( sizeof(int) * n);
2: int i,j,k;
3: for(i=0; i<n; ++i)
4: for(j=0;2*j<=i;++j)
5: if (a[i] <= a[2*j+1])
6: .....
7: ...
0 ≤ i < n?
0 ≤ 2 j + 1 < n?
Check bounds for each array access.
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 6/66
Division by Zero
1: double a,b,c
2: ....
3: while ( b > 0 || c >= 0 ) {
4: a = a + b/(c+b-1);
5: ....
6: }
c + b − 1 > 0
Prove every divisor non-zero.
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 7/66
Deadlock Freedom
x1 x2 x3
x5
x4
x6
x7
x8
x9
x11
x14
x10
x15
x12
x13
x17
x18
x16
x19
x20
x21
x22
x23
x24
x25
Is this Petri net deadlock free? [Zhou et al. : 1992]
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 8/66
Preliminaries: Transition Systems
integer i, j where i = 2 ∧ j = 0
l0 : while true do
i := i + 4
or
(i, j) := (i + 2, j + 1)
Transition system:⟨
L : {ℓ0}︸ ︷︷ ︸
locations
, V :{i, j}
︸ ︷︷ ︸
variables
, T : {τ1, τ2}︸ ︷︷ ︸
transitions
, Θ : (i = 2 ∧ j = 0)︸ ︷︷ ︸
initial condition
, L0 : l0︸︷︷︸
initial location
⟩
withτ1 =
⟨l0, l0, ρτ1
: (i′ = i + 4 ∧ j′ = j)⟩
τ2 =
⟨
l0, l0, ρτ2: (i′ = i + 2 ∧ j′ = j + 1)︸ ︷︷ ︸
transition relation
⟩
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 9/66
Transition System: Execution
Computation: Infinite sequence of states 〈li, xi〉
〈ℓ0, x0〉τ1−→ 〈ℓ1, x1〉
τ2−→ 〈ℓ2, x2〉 → · · ·
such that■ Initial Condition satisfied
ℓ0 = L0 ∧ Θ(x0)
■ Consecutive states 〈ℓi, xi〉 → 〈ℓi+1, xi+1〉 satisfy sometransition
τk :⟨ℓi, ℓi+1, ρτk
(xi, xi+1)⟩
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 10/66
Static Analysis: Traditional Approach
Symbolic forward simulation to obtain an overapproximation ofthe reachable state space (i.e. invariants)
ΘF1
F2
Breachable
states
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 11/66
Forward Propagation
F0 : Θ
F1 : F0 ∨(∨
τ∈T postτ(F0))
F2 : F1 ∨(∨
τ∈T postτ(F1))
...
untilFi+1 → Fi
withpostτ(ϕ) : ∃V0 · (ϕ(V0) ∧ ρτ(V0,V))
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 12/66
Problems
1. May not converge in finite timeExample:
integer i where i = 0
while true do x := x + 1
F0 : i = 0
F1 : i = 0 ∨ i = 1
F2 : i = 1 ∨ i = 1 ∨ i = 2...
We never reach: x ≥ 0
2. May not be able to detect convergence
Fn+1 → Fn
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 13/66
Common Solution
Abstract Interpretation [Cousot&Cousot,77]: perform thesymbolic simulation in an abstract domain:
Domain converges? Reference
Linear equalities yes Karr’76Müller-Olm,Seidl,’04Gulwani+Necula’03
Linear inequalities no Cousot,Halbwachs’79Intervals no Cousot,Cousot’76Octagons no Mine’01Octahedra no Clarisó,Cortadella’04TCM no SSM’04
Use widening operator to force convergence.
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 14/66
Example: Forward Propagation
integer i, j where i = 2 ∧ j = 0
l0 : while true do
i := i + 4
or
(i, j) := (i + 2, j + 1)
Abstract Domain: Linear Inequalities over Reals
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 15/66
Step 1: Iteration
η0 : ( j = 0) ∧ (i = 2)
post(η0, τ1) : ( j = 0) ∧ (i = 6)
post(η0, τ2) : ( j = 1) ∧ (i = 4)
η1 : (0 ≤ j ≤ 1) ∧ (i − 2 j ≥ 2) ∧ (i + 2 j ≤ 6)
i
j(2, 0) (6, 0)
(4, 1)
τ2
τ1
b b
b
η0
Introduction
● Motivation
● Motivation
● Overflows
● Division by Zero
● Deadlock Freedom
● Transition Systems
● Transition Systems
● Traditional Approach
● Forward Propagation
● Problems
● Common Solution
● Example
● Example - step 1
● Example - step 2
● Example - step 3
● Example - step 4
● Constraint-Based
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 16/66
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 30/66
Example:Encoding Consecution for τ1
Transition relation ρτ1: i′ = i + 4 ∧ j′ = j
λ0 − 1 ≤ 0
µ1 c1i + c2 j + d ≤ 0 ← ψ
λ1 i − i′ + 4 = 0}
ρτ1λ2 j − j′ = 0
c1i′ + c2 j′ + d ≤ 0 ← ψ′
Constraints:
(∃λ0, µ1 ≥ 0)(∃λ1, λ2)
µ1c1 + λ1 = 0 ∧ µ2c2 + λ2 = 0 ∧
−λ1 = c1 ∧ −λ2 = c2 ∧ λ0 + µ1d + 4λ1 = d
Eliminate λ0, . . . , λ2, µ1:
Sτ1: (c1 ≤ 0) ∨ (c1 = 0 ∧ c2 = 0)
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● 2. Example
● Farkas’ Lemma
● 3.Encode Initiation
● 3. Example
● 3.Encode Consecution
● 3. Example
● 3. Example
● 4. Solve the constraints
● 4. Example
● 5. Solutions
● Summary
● Pros and Cons
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 31/66
Example: Combined Constraint
The overall constraint is:
(2c1 + d ≤ 0) ← Initiation
∧
(c1 ≤ 0) ∨
(c1 = 0 ∧ c2 = 0)
← τ1 consecution
∧
(2c1 + c2 ≤ 0) ∨
(c1 = 0 ∧ c2 = 0)
← τ2 consecution
which simplifies to
2c1 + d ≤ 0 ∧ c1 ≤ 0 ∧ 2c1 + c2 ≤ 0
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● 2. Example
● Farkas’ Lemma
● 3.Encode Initiation
● 3. Example
● 3.Encode Consecution
● 3. Example
● 3. Example
● 4. Solve the constraints
● 4. Example
● 5. Solutions
● Summary
● Pros and Cons
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 32/66
4. Solve the constraints
Solve the constraint systems
SΘ ∧ Sτ1∧ . . . ∧ Sτk
for {c1, . . . , cn, d}
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● 2. Example
● Farkas’ Lemma
● 3.Encode Initiation
● 3. Example
● 3.Encode Consecution
● 3. Example
● 3. Example
● 4. Solve the constraints
● 4. Example
● 5. Solutions
● Summary
● Pros and Cons
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 33/66
Example: Solving the Constraints
The basic solutions of
2c1 + d ≤ 0 ∧ c1 ≤ 0 ∧ 2c1 + c2 ≤ 0
arec1 c2 d c1i + c2 j + d ≤ 0
0 0 −1 −1 ≤ 0
0 −1 0 − j ≤ 0
−1 2 2 −i + 2 j + 2 ≤ 0
which corresponds to the inductive invariants
j ≥ 0 and i − 2 j ≥ 2
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● 2. Example
● Farkas’ Lemma
● 3.Encode Initiation
● 3. Example
● 3.Encode Consecution
● 3. Example
● 3. Example
● 4. Solve the constraints
● 4. Example
● 5. Solutions
● Summary
● Pros and Cons
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 34/66
5. Solutions
The propertyc1x1 + . . . + cnxn + d ≤ 0
is an invariant for all solutions of {c1, . . . , cn, d}.
■ Good news: The method is complete for linear systems:The solutions of {c1, . . . , cn} represent all linear inductiveinequalities of the given shape.
■ But: Requires individual inductiveness.
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● 2. Example
● Farkas’ Lemma
● 3.Encode Initiation
● 3. Example
● 3.Encode Consecution
● 3. Example
● 3. Example
● 4. Solve the constraints
● 4. Example
● 5. Solutions
● Summary
● Pros and Cons
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 35/66
Summary
1. Fix a target property with unknown coefficients,
c1i + c2 j + d ≤ 0
2. Encode the property conditions3. Compute constraints on the unknown coefficients,
2c1 + d ≤ 0 ∧ c1 ≤ 0 ∧ 2c1 + c2 ≤ 0
4. Solve these constraints
〈c1, c2, d〉 = 〈0,−1, 0〉 〈c1, c2, d〉 = 〈−1, 2, 2〉
5. Generate the invariants
〈0,−1, 0〉 ↔ 0i − 1 j + 0 ≤ 0
〈−1, 2, 2〉 ↔ −1i + 2 j + 2 ≤ 0
Invariants: j ≥ 0 and i − 2 j ≥ 2
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● 2. Example
● Farkas’ Lemma
● 3.Encode Initiation
● 3. Example
● 3.Encode Consecution
● 3. Example
● 3. Example
● 4. Solve the constraints
● 4. Example
● 5. Solutions
● Summary
● Pros and Cons
Linear Ranking Functions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 36/66
Pros and Cons
Advantages:■ No widening necessary■ All inductive invariants are generated (or obtained as
consequences)■ System structure can be exploited to obtain linear
constraints: Petri nets
Disadvantages:■ The constraint systems Sτ1
, . . . , Sτkare nonlinear and may be
hard to solve. Tools: QEPCAD■ But: Sτ1
, . . . , Sτkare parametric linear
More efficient solution methods: factorization, polynomialroot findingTool: REDLOG [Weispfennig; Dolzmann,Sturm]
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 37/66
Computing Linear Ranking Functions
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 38/66
1. Fix type and shape
■ Type: Ranking function
■ Shape:c1x1 + c2x2 + . . . + cnxn + d
where{x1, . . . , xn} are the program variables
and{c1, . . . , cn, d} are unknown coefficients
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 39/66
2. Property Conditions
The functionδ : c1x1 + c2x2 + . . . + cnxn + d
is a ranking function of a loopΦ : 〈V : {x1, . . . , xn} ,Θ,T : {τ1, . . . , τk}〉 if
ρτ1|= δ ≥ 0
bounded...
ρτk|= δ ≥ 0
ρτ1|= δ − δ′ > 0
ranking...
ρτk|= δ − δ′ > 0
that is, if■ it is bounded from below, and■ it is decreased by each transition
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 40/66
3. Encode the conditions: Bounded
Bounded:ρτi|= δ ≥ 0
is encoded by
λτi ,1τi,11x1 + · · · + τi,1nxn + τ′
i,11x′
1+ . . . + τ′
i,1nx′n + τi,1,n+1 ≤ 0
ρτi...
.
.
.
.
.
.
.
.
.
λτi ,m τi,m1x1 + · · · + τi,mnxn + τ′i,m1
x′1+ . . . + τ′
i,mnx′n + τi,m,n+1 ≤ 0
−c1x1 − . . . − cnxn + − d ≤ 0
which produces the constraints
Bτi: ∃(λτi,1, . . . , λτi,m ≥ 0) .
∑mj=1
λτi , jτi, j1 = −c1 ∧
. . . ∧∑m
j=1λτi , j
τi, jn = −cn ∧
∑mj=1
λτi , jτ′
i, j1= 0 ∧
. . . ∧∑m
j=1λτi , j
τ′i, jn
= 0 ∧
−∑m
j=1λτi , j
τi, j,n+1 ≤ d
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 41/66
3. Encode the conditions: Ranking
Ranking:ρτi|= δ − δ′ > 0
is encoded by
λτi ,1τi,11x1 + · · · + τi,1nxn + τ′
i,11x′
1+ . . . + τ′
i,1nx′n + τi,1,n+1 ≤ 0
ρτi...
.
.
.
.
.
.
.
.
.
λτi ,m τi,m1x1 + · · · + τi,mnxn + τ′i,m1
x′1+ . . . + τ′
i,mnx′n + τi,m,n+1 ≤ 0
−c1x1 − . . . − cnxn + c1x′1+ . . . + cnx′n ǫ ≤ 0
which produces the constraints
Rτi: ∃(λτi,1, . . . , λτi,m ≥ 0) .
∑mj=1
λτi , jτi, j1 = −c1 ∧
. . . ∧∑m
j=1λτi , j
τi, jn = −cn ∧
∑mj=1
λτi , jτ′
i, j1= c1 ∧
. . . ∧∑m
j=1λτi , j
τ′i, jn
= cn ∧
−∑m
j=1λτi , j
τi, j,n+1 ≤ −ǫ
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 42/66
4. Solve the constraints
Solve the constraint systems
Bτ1∧ . . . ∧ Bτk
∧ Rτ1∧ . . . ∧ Rτk
for {c1, . . . , cn, d}
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
● 1.Fix type and shape
● 2. Property Conditions
● 3.Encode Bounded
● 3.Encode Ranking
● 4. Solve the constraints
● 5. Solutions
Nonlinear Invariants
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 43/66
5. Solutions
The functionc1x1 + c2x2 + . . . + cnxn + d
is a ranking function for all solutions of {c1, . . . , cn, d}.
■ Good news: The method is complete for linear systems:The solutions represent all linear ranking functions of thegiven (uninitialized) loop.
■ Good news:Constraints are all linear: can be solvedefficiently
■ Bad news: Most ranking functions require invariants to proveboundedness
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● Ideals
● Ideals
● Testing Ideal Membership
● Gröbner Basis Theorem
● Testing Ideal Membership
● Testing Ideal Membership
● Parametric Membership
● Parametric Membership
● 3.Encode Initiation
● 3.Encode Consecution
● 4. Solve the constraints
● 5. Solutions
● Example
● Example
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 44/66
Computing Nonlinear Invariants
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● Ideals
● Ideals
● Testing Ideal Membership
● Gröbner Basis Theorem
● Testing Ideal Membership
● Testing Ideal Membership
● Parametric Membership
● Parametric Membership
● 3.Encode Initiation
● 3.Encode Consecution
● 4. Solve the constraints
● 5. Solutions
● Example
● Example
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 45/66
1. Fix type and shape
■ Type: Invariant
■ Shape:
c1x3 + c2x2y + c3x2z + c4xy2 + c5xyz + c6xz2+
c7y3 + c8y2z + c9yz2 + c10z3 = 0
where{x, y, z} are the program variables
and{c1, . . . , c10} are unknown coefficients
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● Ideals
● Ideals
● Testing Ideal Membership
● Gröbner Basis Theorem
● Testing Ideal Membership
● Testing Ideal Membership
● Parametric Membership
● Parametric Membership
● 3.Encode Initiation
● 3.Encode Consecution
● 4. Solve the constraints
● 5. Solutions
● Example
● Example
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 46/66
2. Property Conditions
The property p = 0 with
p :c1x3 + c2x2y + c3x2z + c4xy2 + c5xyz + c6xz2+
c7y3 + c8y2z + c9yz2 + c10z3
is an invariant of transition systemΦ : 〈V : {x1, . . . , x10} ,Θ,T : {τ1, . . . , τk}〉 if
Θ |= p = 0 (initiation)p = 0 ∧ ρτ1
|= p′ = 0
(consecution)...
p = 0 ∧ ρτk|= p′ = 0
that is, if■ it is implied by the initial condition, and■ it is preserved by all transitions of the system
Introduction
Constraint-based Analysis:
Overview
Computing Linear Invariants
Linear Ranking Functions
Nonlinear Invariants
● 1. Fix type and shape
● 2. Property Conditions
● Ideals
● Ideals
● Testing Ideal Membership
● Gröbner Basis Theorem
● Testing Ideal Membership
● Testing Ideal Membership
● Parametric Membership
● Parametric Membership
● 3.Encode Initiation
● 3.Encode Consecution
● 4. Solve the constraints
● 5. Solutions
● Example
● Example
Summary
Henny Sipma, November 16, 2006 Washington University at St Louis - p. 47/66
Linear Equalities vs Nonlinear Equalities
Computing Consequences for Polynomial Equalities
Linear Equalities Polynomial Equalitiesλ1 e1 = 0...