Symbolic Computation and Theorem Proving in Program Analysis Laura - - PowerPoint PPT Presentation

symbolic computation and theorem proving in program
SMART_READER_LITE
LIVE PREVIEW

Symbolic Computation and Theorem Proving in Program Analysis Laura - - PowerPoint PPT Presentation

Symbolic Computation and Theorem Proving in Program Analysis Laura Kov acs Chalmers Outline Part 1: Weakest Precondition for Program Analysis and Verification Part 2: Polynomial Invariant Generation (TACAS08, LPAR10) Part 3:


slide-1
SLIDE 1

Symbolic Computation and Theorem Proving in Program Analysis

Laura Kov´ acs

Chalmers

slide-2
SLIDE 2

Outline

Part 1: Weakest Precondition for Program Analysis and Verification Part 2: Polynomial Invariant Generation (TACAS’08, LPAR’10) Part 3: Quantified Invariant Generation (FASE’09, MICAI’11) Part 4: Invariants, Interpolants and Symbol Elimination

(CADE’09, POPL ’12, APLAS’12)

slide-3
SLIDE 3

Specification Program Weakest Precondition Verification Conditions Proving

slide-4
SLIDE 4

Specification Program Loop Assertions Verification Conditions Proving Proving

slide-5
SLIDE 5

Specification Program Loop Assertions Verification Conditions Proving

Computer Algebra Theorem Proving

Proving

slide-6
SLIDE 6

Assertion Synthesis — Example: Array Partition

Program Loop Assertions

Polynomial Equalities and Inequalities, Quantified FO properties

a := 0; b := 0; c := 0; while (a < N) do if A[a] ≥ 0 then B[b] := A[a]; b := b + 1 else C[c] := A[a]; c := c + 1; a := a + 1; end while a = b + c a ≥ 0 ∧ b ≥ 0 ∧ c ≥ 0 a ≤ N ∨ N ≤ 0 (∀p)(p ≥ b = ⇒ B[p] = B0[p]) (∀p)(0 ≤ p < b = ⇒ B[p] ≥ 0 ∧ (∃i)(0 ≤ i < a ∧ A[a] = B[p]))

slide-7
SLIDE 7

Assertion Synthesis — Example: Array Partition

Program Loop Assertions

Polynomial Equalities and Inequalities, Quantified FO properties

a := 0; b := 0; c := 0; while (a < N) do if A[a] ≥ 0 then B[b] := A[a]; b := b + 1 else C[c] := A[a]; c := c + 1; a := a + 1; end while a = b + c a ≥ 0 ∧ b ≥ 0 ∧ c ≥ 0 a ≤ N ∨ N ≤ 0 (∀p)(p ≥ b = ⇒ B[p] = B0[p]) (∀p)(0 ≤ p < b = ⇒ B[p] ≥ 0 ∧ (∃i)(0 ≤ i < a ∧ A[a] = B[p]))

slide-8
SLIDE 8

Our Approach

Loop Assertions

slide-9
SLIDE 9

Our Approach

Loop Assertions Loop Properties

Extend language with extra symbols: loop cnt, array update predicates

slide-10
SLIDE 10

Our Approach:

SYMBOL ELIMINATION

Loop Assertions Loop Properties

Extend language with extra symbols: loop cnt, array update predicates Eliminate symbols

slide-11
SLIDE 11

Our Approach:

SYMBOL ELIMINATION

Loop Assertions Loop Properties

Extend language with extra symbols: loop cnt, array update predicates Eliminate symbols

Recurrence Solving Monotonicity Properties of Scalars Array Update Properties Gr¨

  • bner Basis

Consequence Finding

slide-12
SLIDE 12

Part 2: Polynomial Invariant Generation

Symbol Elimination by Gr¨

  • bner Basis Computation
slide-13
SLIDE 13

Outline

Overview of the Method Algebraic Techniques for Invariant Generation Polynomial Invariants for Loops with Assignments Only Polynomial Invariants for Loops with Conditionals Examples Conclusions

slide-14
SLIDE 14

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-15
SLIDE 15

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-16
SLIDE 16

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-17
SLIDE 17

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] quo[n + 1] depends algebraically upon quo[n]. System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-18
SLIDE 18

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] quo[n + 1] depends algebraically upon quo[n]. System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-19
SLIDE 19

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] rem[n+1] depends algebraically upon rem[n+1]. rem[n+1] depends algebraically upon rem[n + 1]. System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-20
SLIDE 20

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] rem[n+1] depends algebraically upon rem[n+1]. rem[n+1] depends algebraically upon rem[n + 1]. System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-21
SLIDE 21

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-22
SLIDE 22

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-23
SLIDE 23

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-24
SLIDE 24

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while Introduce LOOP COUNTER n (n ≥ 0) → nth iteration of the loop quo → quo[n] rem → rem[n] System of Recurrences System of Closed Forms Loop body quo[n + 1] = quo[n] + 1 → CFquo(n, quo[0]) quo := quo + 1; quo[n + 1] =quo[n] + 1 → quo[n] = quo[0] + n quo := quo + 1; rem[n + 1] = rem[n] − y → CFrem(n, rem[0]) rem := rem − y; rem[n + 1] =rem[n] − y → rem[n] = rem[0] − n ∗ y rem := rem − y; quo[0] quo[1] quo[2] . . . quo[n-1] quo[n] . . . rem[0] rem[1] rem[2] . . . rem[n-1] rem[n] . . .

slide-25
SLIDE 25

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Eliminate n and (optionally) initial value

substitution;

  • 4. Result: set of invariants

Result: Polynomial ideal → Finite basis Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

Result: Polynomial ideal → Gr¨

  • bner basis

n ≥ 0

rem[n + 1] = rem[n] − y quo[n + 1] = quo[n] + 1 rem[n] = rem[0] − n ∗ y quo[n] = quo[0] + n rem = rem[0] − (quo − quo[0]) ∗ y rem = x − quo ∗ y → Poly Invariant

slide-26
SLIDE 26

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Eliminate n and (optionally) initial value

substitution;

  • 4. Result: set of invariants

Result: Polynomial ideal → Finite basis Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

Result: Polynomial ideal → Gr¨

  • bner basis

n ≥ 0

rem[n + 1] = rem[n] − y quo[n + 1] = quo[n] + 1 rem[n] = rem[0] − n ∗ y quo[n] = quo[0] + n rem = rem[0] − (quo − quo[0]) ∗ y rem = x − quo ∗ y → Poly Invariant

slide-27
SLIDE 27

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Eliminate n and (optionally) initial value

substitution;

  • 4. Result: set of invariants

Result: Polynomial ideal → Finite basis Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

Result: Polynomial ideal → Gr¨

  • bner basis

n ≥ 0

rem[n + 1] = rem[n] − y quo[n + 1] = quo[n] + 1 rem[n] = rem[0] − n ∗ y quo[n] = quo[0] + n rem = rem[0] − (quo − quo[0]) ∗ y rem = x − quo ∗ y → Poly Invariant

slide-28
SLIDE 28

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Eliminate n and (optionally) initial value

substitution;

  • 4. Result: set of invariants

Result: Polynomial ideal → Finite basis Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

Result: Polynomial ideal → Gr¨

  • bner basis

n ≥ 0

rem[n + 1] = rem[n] − y quo[n + 1] = quo[n] + 1 rem[n] = rem[0] − n ∗ y quo[n] = quo[0] + n rem = rem[0] − (quo − quo[0]) ∗ y rem = x − quo ∗ y → Poly Invariant

slide-29
SLIDE 29

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Eliminate n and (optionally) initial value

substitution;

  • 4. Result: set of invariants

Result: Polynomial ideal → Finite basis Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

Result: Polynomial ideal → Gr¨

  • bner basis

n ≥ 0

rem[n + 1] = rem[n] − y quo[n + 1] = quo[n] + 1 rem[n] = rem[0] − n ∗ y quo[n] = quo[0] + n rem = rem[0] − (quo − quo[0]) ∗ y rem = x − quo ∗ y → Poly Invariant

slide-30
SLIDE 30

Overview of Our Method - Division Example

quo := 0; rem := x;

while y ≤ rem do

rem := rem − y; quo := quo + 1

end while

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Eliminate n and (optionally) initial value

substitution;

  • 4. Result: set of invariants

Result: Polynomial ideal → Finite basis Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

Result: Polynomial ideal → Gr¨

  • bner basis

n ≥ 0

rem[n + 1] = rem[n] − y quo[n + 1] = quo[n] + 1 rem[n] = rem[0] − n ∗ y quo[n] = quo[0] + n rem = rem[0] − (quo − quo[0]) ∗ y rem = x − quo ∗ y → Poly Invariant

slide-31
SLIDE 31

Overview of Our Method

Specification Loop Polynomial Invariant Verification Conditions Proving Polynomial Invariant

Symbolic Summation (C-finite) Gr¨

  • bner basis
slide-32
SLIDE 32

Overview of the Method

x := 1; y := 0;

while[. . . , x := 2 ∗ x; y := 1

2 ∗ y + 1]

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Identify polynomial/algebraic dependencies

among exponentials in n;

  • 4. Eliminate n and variables standing for

algebraically related exponentials in n → elimination by Gr¨

  • bner bases;
  • 5. Result: Polynomial ideal→ Gr¨
  • bner basis

Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

n ≥ 0, a = 2n, b = 2−n

x[n + 1] = 2 ∗ x[n] y[n + 1] =

1 2 ∗ y[n] + 1

x[n] = 2n ∗ x[0] y[n] =

1 2n ∗ y[0] − 2 2n + 2

   x = a ∗ x[0] y = b ∗ y[0] − 2 ∗ b + 2 = a ∗ b − 1 x ∗ y − 2 ∗ x + 2 = 0

slide-33
SLIDE 33

Overview of the Method

x := 1; y := 0;

while[. . . , x := 2 ∗ x; y := 1

2 ∗ y + 1]

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Identify polynomial/algebraic dependencies

among exponentials in n;

  • 4. Eliminate n and variables standing for

algebraically related exponentials in n → elimination by Gr¨

  • bner bases;
  • 5. Result: Polynomial ideal→ Gr¨
  • bner basis

Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

n ≥ 0, a = 2n, b = 2−n

x[n + 1] = 2 ∗ x[n] y[n + 1] =

1 2 ∗ y[n] + 1

x[n] = 2n ∗ x[0] y[n] =

1 2n ∗ y[0] − 2 2n + 2

   x = a ∗ x[0] y = b ∗ y[0] − 2 ∗ b + 2 = a ∗ b − 1 x ∗ y − 2 ∗ x + 2 = 0

slide-34
SLIDE 34

Overview of the Method

x := 1; y := 0;

while[. . . , x := 2 ∗ x; y := 1

2 ∗ y + 1]

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Identify polynomial/algebraic dependencies

among exponentials in n;

  • 4. Eliminate n and variables standing for

algebraically related exponentials in n → elimination by Gr¨

  • bner bases;
  • 5. Result: Polynomial ideal→ Gr¨
  • bner basis

Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

n ≥ 0, a = 2n, b = 2−n

x[n + 1] = 2 ∗ x[n] y[n + 1] =

1 2 ∗ y[n] + 1

x[n] = 2n ∗ x[0] y[n] =

1 2n ∗ y[0] − 2 2n + 2

   x = a ∗ x[0] y = b ∗ y[0] − 2 ∗ b + 2 = a ∗ b − 1 x ∗ y − 2 ∗ x + 2 = 0

slide-35
SLIDE 35

Overview of the Method

x := 1; y := 0;

while[. . . , x := 2 ∗ x; y := 1

2 ∗ y + 1]

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Identify polynomial/algebraic dependencies

among exponentials in n;

  • 4. Eliminate n and variables standing for

algebraically related exponentials in n → elimination by Gr¨

  • bner bases;
  • 5. Result: Polynomial ideal→ Gr¨
  • bner basis

Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

n ≥ 0, a = 2n, b = 2−n

x[n + 1] = 2 ∗ x[n] y[n + 1] =

1 2 ∗ y[n] + 1

x[n] = 2n ∗ x[0] y[n] =

1 2n ∗ y[0] − 2 2n + 2

   x = a ∗ x[0] y = b ∗ y[0] − 2 ∗ b + 2 = a ∗ b − 1 x ∗ y − 2 ∗ x + 2 = 0

slide-36
SLIDE 36

Overview of the Method

x := 1; y := 0;

while[. . . , x := 2 ∗ x; y := 1

2 ∗ y + 1]

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Identify polynomial/algebraic dependencies

among exponentials in n;

  • 4. Eliminate n and variables standing for

algebraically related exponentials in n → elimination by Gr¨

  • bner bases;
  • 5. Result: Polynomial ideal→ Gr¨
  • bner basis

Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

n ≥ 0, a = 2n, b = 2−n

x[n + 1] = 2 ∗ x[n] y[n + 1] =

1 2 ∗ y[n] + 1

x[n] = 2n ∗ x[0] y[n] =

1 2n ∗ y[0] − 2 2n + 2

   x = a ∗ x[0] y = b ∗ y[0] − 2 ∗ b + 2 = a ∗ b − 1 x ∗ y − 2 ∗ x + 2 = 0

slide-37
SLIDE 37

Overview of the Method

x := 1; y := 0;

while[. . . , x := 2 ∗ x; y := 1

2 ∗ y + 1]

  • 1. Express state from (n + 1)th iteration in

terms of nth iteration → recurrence relations

  • f variables;
  • 2. Solve recurrence relations → closed forms of

variables: functions of iteration counter n ↑ methods from symbolic summation;

  • 3. Identify polynomial/algebraic dependencies

among exponentials in n;

  • 4. Eliminate n and variables standing for

algebraically related exponentials in n → elimination by Gr¨

  • bner bases;
  • 5. Result: Polynomial ideal→ Gr¨
  • bner basis

Result: p1 = 0, p2 = 0 → p1 + p2 = 0,

p1 · q = 0, ∀q.

n ≥ 0, a = 2n, b = 2−n

x[n + 1] = 2 ∗ x[n] y[n + 1] =

1 2 ∗ y[n] + 1

x[n] = 2n ∗ x[0] y[n] =

1 2n ∗ y[0] − 2 2n + 2

   x = a ∗ x[0] y = b ∗ y[0] − 2 ∗ b + 2 = a ∗ b − 1 x ∗ y − 2 ∗ x + 2 = 0

slide-38
SLIDE 38

Overview of Our Method

Loop body System of recurrence equations System of closed forms Invariant equalities

slide-39
SLIDE 39

Overview of Our Method

Loop body System of recurrence equations System of closed forms Invariant equalities

Symb.Summ. GB

slide-40
SLIDE 40

Overview of the Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → (basic) non-deterministic programs;

← while cond do S end while → while . . . do S do − → S∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals: polynomial invariant generation by symbolic summation and polynomial algebra algorithms ← P-solvable loops;

← {p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

slide-41
SLIDE 41

Overview of the Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → (basic) non-deterministic programs;

← while cond do S end while → while . . . do S do − → S∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals: polynomial invariant generation by symbolic summation and polynomial algebra algorithms ← P-solvable loops;

← {p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

slide-42
SLIDE 42

Overview of the Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → (basic) non-deterministic programs;

← while cond do S end while → while . . . do S do − → S∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals: polynomial invariant generation by symbolic summation and polynomial algebra algorithms ← P-solvable loops;

← {p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

slide-43
SLIDE 43

Overview of the Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → (basic) non-deterministic programs;

← while cond do S end while → while . . . do S do − → S∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals: polynomial invariant generation by symbolic summation and polynomial algebra algorithms ← P-solvable loops;

← {p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

slide-44
SLIDE 44

Overview of the Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → (basic) non-deterministic programs;

← while cond do S end while → while . . . do S do − → S∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals: polynomial invariant generation by symbolic summation and polynomial algebra algorithms ← P-solvable loops;

← {p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

◮ Implementation: ALIGATOR → programs working on numbers.

http://mtc.epfl.ch/software-tools/Aligator

slide-45
SLIDE 45

Outline

Overview of the Method Algebraic Techniques for Invariant Generation Polynomial Invariants for Loops with Assignments Only Polynomial Invariants for Loops with Conditionals Examples Conclusions

slide-46
SLIDE 46

C-finite Recurrences x[n] in a Field K

→ linear recurrences with constant coefficients: x[n + r] = a0x[n] + . . . + ar−1x[n + r − 1], where

◮ r ∈ N is the recurrence order; ◮ a0, . . . , ar−1 ∈ K, with a0 = 0.

slide-47
SLIDE 47

C-finite Recurrences x[n] in a Field K

→ linear recurrences with constant coefficients: x[n + r] = a0x[n] + . . . + ar−1x[n + r − 1],

Examples.

◮ Fibonacci: x[n + 2] = x[n + 1] + x[n],

x[0] = 0, x[1] = 1

◮ Tribonacci: x[n + 3] = x[n + 2] + x[n + 1] + x[n],

x[0] = 0, x[1] = x[2] = 1

slide-48
SLIDE 48

C-finite Recurrences x[n] in a Field K

→ linear recurrences with constant coefficients: x[n + r] = a0x[n] + . . . + ar−1x[n + r − 1],

CHARACTERISTIC POLYNOMIAL c(y) of x[n] is:

c(y) = yr − a0 − a1y − · · · − ar−1yr−1 → distinct roots: θ1, . . . , θs ∈ ¯ K with multiplicity ei ≥ 1. → CLOSED FORM OF x[n]: Linear combination of:

       θn

1,

nθn

1,

n(n − 1)θn

1,

. . . . . . n(n − 1) · · · (n − e1 + 1)θn

1

θn

2,

nθn

2,

n(n − 1)θn

2

. . . . . . n(n − 1) · · · (n − e2 + 1)θn

2

. . . . . . . . . . . . . . . . . . θn

s,

nθn

s,

n(n − 1)θn

s

. . . . . . n(n − 1) · · · (n − es + 1)θn

s

By regrouping: x[n] = q(n, θn

1, · · · , θn s)

slide-49
SLIDE 49

C-finite Recurrences x[n] in a Field K

→ linear recurrences with constant coefficients: x[n + r] = a0x[n] + . . . + ar−1x[n + r − 1],

CHARACTERISTIC POLYNOMIAL c(y) of x[n] is:

c(y) = yr − a0 − a1y − · · · − ar−1yr−1 → distinct roots: θ1, . . . , θs ∈ ¯ K with multiplicity ei ≥ 1. → CLOSED FORM OF x[n]: Linear combination of:

       θn

1,

nθn

1,

n(n − 1)θn

1,

. . . . . . n(n − 1) · · · (n − e1 + 1)θn

1

θn

2,

nθn

2,

n(n − 1)θn

2

. . . . . . n(n − 1) · · · (n − e2 + 1)θn

2

. . . . . . . . . . . . . . . . . . θn

s,

nθn

s,

n(n − 1)θn

s

. . . . . . n(n − 1) · · · (n − es + 1)θn

s

By regrouping: x[n] = q(n, θn

1, · · · , θn s)

slide-50
SLIDE 50

C-finite Recurrences x[n] in a Field K

→ linear recurrences with constant coefficients: x[n + r] = a0x[n] + . . . + ar−1x[n + r − 1],

CHARACTERISTIC POLYNOMIAL c(y) of x[n] is:

c(y) = yr − a0 − a1y − · · · − ar−1yr−1 → distinct roots: θ1, . . . , θs ∈ ¯ K with multiplicity ei ≥ 1. → CLOSED FORM OF x[n]: Linear combination of:

       θn

1,

nθn

1,

n(n − 1)θn

1,

. . . . . . n(n − 1) · · · (n − e1 + 1)θn

1

θn

2,

nθn

2,

n(n − 1)θn

2

. . . . . . n(n − 1) · · · (n − e2 + 1)θn

2

. . . . . . . . . . . . . . . . . . θn

s,

nθn

s,

n(n − 1)θn

s

. . . . . . n(n − 1) · · · (n − es + 1)θn

s

By regrouping: x[n] = q(n, θn

1, · · · , θn s)

slide-51
SLIDE 51

C-finite Recurrences x[n] in a Field K

Example

Given x[n + 2] = 3x[n + 1] − 2x[n] with x[0] = 0, x[1] = 1.

  • 1. Characteristic polynomial:

y 2 − 3y + 2 = 0 → Roots: θ1 = 1, θ2 = 2 with e1 = e2 = 1

  • 2. Closed form of x[n]:

x[n] = α1n + β2n 0 = x[0] = α + β 1 = x[1] = α + 2β → α = −1, β = 1

  • 3. Closed form of x[n]:

x[n] = 2n − 1

slide-52
SLIDE 52

C-finite Recurrences x[n] in a Field K

Example

Given x[n + 2] = 3x[n + 1] − 2x[n] with x[0] = 0, x[1] = 1.

  • 1. Characteristic polynomial:

y 2 − 3y + 2 = 0 → Roots: θ1 = 1, θ2 = 2 with e1 = e2 = 1

  • 2. Closed form of x[n]:

x[n] = α1n + β2n 0 = x[0] = α + β 1 = x[1] = α + 2β → α = −1, β = 1

  • 3. Closed form of x[n]:

x[n] = 2n − 1

slide-53
SLIDE 53

C-finite Recurrences x[n] in a Field K

Example

Given x[n + 2] = 3x[n + 1] − 2x[n] with x[0] = 0, x[1] = 1.

  • 1. Characteristic polynomial:

y 2 − 3y + 2 = 0 → Roots: θ1 = 1, θ2 = 2 with e1 = e2 = 1

  • 2. Closed form of x[n]:

x[n] = α1n + β2n 0 = x[0] = α + β 1 = x[1] = α + 2β → α = −1, β = 1

  • 3. Closed form of x[n]:

x[n] = 2n − 1

slide-54
SLIDE 54

C-finite Recurrences x[n] in a Field K

Example

Given x[n + 2] = 3x[n + 1] − 2x[n] with x[0] = 0, x[1] = 1.

  • 1. Characteristic polynomial:

y 2 − 3y + 2 = 0 → Roots: θ1 = 1, θ2 = 2 with e1 = e2 = 1

  • 2. Closed form of x[n]:

x[n] = α1n + β2n 0 = x[0] = α + β 1 = x[1] = α + 2β → α = −1, β = 1

  • 3. Closed form of x[n]:

x[n] = 2n − 1

slide-55
SLIDE 55

C-finite Recurrences x[n] in a Field K

Example

Given x[n + 2] = 3x[n + 1] − 2x[n] with x[0] = 0, x[1] = 1.

  • 1. Characteristic polynomial:

y 2 − 3y + 2 = 0 → Roots: θ1 = 1, θ2 = 2 with e1 = e2 = 1

  • 2. Closed form of x[n]:

x[n] = α1n + β2n 0 = x[0] = α + β 1 = x[1] = α + 2β → α = −1, β = 1

  • 3. Closed form of x[n]:

x[n] = 2n − 1

slide-56
SLIDE 56

C-finite Recurrences x[n] in a Field K

Example

Given x[n + 2] = 3x[n + 1] − 2x[n] with x[0] = 0, x[1] = 1.

  • 1. Characteristic polynomial:

y 2 − 3y + 2 = 0 → Roots: θ1 = 1, θ2 = 2 with e1 = e2 = 1

  • 2. Closed form of x[n]:

x[n] = α1n + β2n 0 = x[0] = α + β 1 = x[1] = α + 2β → α = −1, β = 1

  • 3. Closed form of x[n]:

x[n] = 2n − 1

slide-57
SLIDE 57

Program Assignments and C-finite Recurrences

x := αx + h − → x[n + 1] = αx[n] + h(n)

with h(n) = nd1θ1 + · · · + ndsθn

s

Example

x[n + 1] = x[n] + 1 → x[n + 2] − 2x[n + 1] + x[n] = 0 x[n + 1] = 2x[n] + 4 → x[n + 2] − 3x[n + 1] + 2x[n] = 0 ⇓ Px = Ph · (S − α), where Ph = (S − θ1)d1+1 · · · (S − θs)ds+1 Px · x = 0 Ph · h = 0 x[n + r] = an+r−1x[n + r − 1] + · · · + anx[n],

with r ≥ 1

slide-58
SLIDE 58

Program Assignments and C-finite Recurrences

x := αx + h − → x[n + 1] = αx[n] + h(n)

with h(n) = nd1θ1 + · · · + ndsθn

s

Example

x[n + 1] = x[n] + 1 → x[n + 2] − 2x[n + 1] + x[n] = 0 x[n + 1] = 2x[n] + 4 → x[n + 2] − 3x[n + 1] + 2x[n] = 0 ⇓ Px = Ph · (S − α), where Ph = (S − θ1)d1+1 · · · (S − θs)ds+1 Px · x = 0 Ph · h = 0 x[n + r] = an+r−1x[n + r − 1] + · · · + anx[n],

with r ≥ 1

slide-59
SLIDE 59

Program Assignments and C-finite Recurrences

x := αx + h − → x[n + 1] = αx[n] + h(n)

with h(n) = nd1θ1 + · · · + ndsθn

s

Example

x[n + 1] = x[n] + 1 → x[n + 2] − 2x[n + 1] + x[n] = 0 x[n + 1] = 2x[n] + 4 → x[n + 2] − 3x[n + 1] + 2x[n] = 0 ⇓ Px = Ph · (S − α), where Ph = (S − θ1)d1+1 · · · (S − θs)ds+1 Px · x = 0 Ph · h = 0 x[n + r] = an+r−1x[n + r − 1] + · · · + anx[n],

with r ≥ 1

slide-60
SLIDE 60

Algebraic Dependencies Among Exponential Sequences

Let θ1, . . . , θs ∈ ¯ K, and their exponential sequences θn

1, . . . , θn s ∈ ¯

K. An algebraic dependency of these sequences is a polynomial p : p(θn

1, . . . , θn s) = 0,

(∀n ≥ 0). → ideal: I(θn

1, . . . , θn s) = I(n, θn 1, . . . , θn s).

Example.

◮ The algebraic dependency among the exponential sequences of θ1 = 2

and θ2 = 1

2 is:

θn

1 ∗ θn 2 − 1 = 0;

◮ The algebraic dependency among the exponential sequences of

θ1 = 1+

√ 5 2

and θ2 = 1−

√ 5 2

is:

  • θn

1

2 ∗

  • θn

2

2 − 1 = 0;

◮ There is no algebraic dependency among the exponential sequences of

θ1 = 2 and θ2 = 3.

slide-61
SLIDE 61

Algebraic Dependencies Among Exponential Sequences

Let θ1, . . . , θs ∈ ¯ K, and their exponential sequences θn

1, . . . , θn s ∈ ¯

K. An algebraic dependency of these sequences is a polynomial p : p(θn

1, . . . , θn s) = 0,

(∀n ≥ 0). → ideal: I(θn

1, . . . , θn s) = I(n, θn 1, . . . , θn s).

Example.

◮ The algebraic dependency among the exponential sequences of θ1 = 2

and θ2 = 1

2 is:

θn

1 ∗ θn 2 − 1 = 0;

◮ The algebraic dependency among the exponential sequences of

θ1 = 1+

√ 5 2

and θ2 = 1−

√ 5 2

is:

  • θn

1

2 ∗

  • θn

2

2 − 1 = 0;

◮ There is no algebraic dependency among the exponential sequences of

θ1 = 2 and θ2 = 3.

slide-62
SLIDE 62

Algebraic Dependencies Among Exponential Sequences

Let θ1, . . . , θs ∈ ¯ K, and their exponential sequences θn

1, . . . , θn s ∈ ¯

K. An algebraic dependency of these sequences is a polynomial p : p(θn

1, . . . , θn s) = 0,

(∀n ≥ 0). → ideal: I(θn

1, . . . , θn s) = I(n, θn 1, . . . , θn s).

Example.

◮ The algebraic dependency among the exponential sequences of θ1 = 2

and θ2 = 1

2 is:

θn

1 ∗ θn 2 − 1 = 0;

◮ The algebraic dependency among the exponential sequences of

θ1 = 1+

√ 5 2

and θ2 = 1−

√ 5 2

is:

  • θn

1

2 ∗

  • θn

2

2 − 1 = 0;

◮ There is no algebraic dependency among the exponential sequences of

θ1 = 2 and θ2 = 3.

slide-63
SLIDE 63

Algebraic Dependencies Among Exponential Sequences

Let θ1, . . . , θs ∈ ¯ K, and their exponential sequences θn

1, . . . , θn s ∈ ¯

K. An algebraic dependency of these sequences is a polynomial p : p(θn

1, . . . , θn s) = 0,

(∀n ≥ 0). → ideal: I(θn

1, . . . , θn s) = I(n, θn 1, . . . , θn s).

Example.

◮ The algebraic dependency among the exponential sequences of θ1 = 2

and θ2 = 1

2 is:

θn

1 ∗ θn 2 − 1 = 0;

◮ The algebraic dependency among the exponential sequences of

θ1 = 1+

√ 5 2

and θ2 = 1−

√ 5 2

is:

  • θn

1

2 ∗

  • θn

2

2 − 1 = 0;

◮ There is no algebraic dependency among the exponential sequences of

θ1 = 2 and θ2 = 3.

slide-64
SLIDE 64

Outline

Overview of the Method Algebraic Techniques for Invariant Generation Polynomial Invariants for Loops with Assignments Only Polynomial Invariants for Loops with Conditionals Examples Conclusions

slide-65
SLIDE 65

Invariant Generation Algorithm

Loop System of recurrence equations System of closed forms Polynomial Invariant Ideal

Symb.Summ. GB

slide-66
SLIDE 66

Invariant Generation Algorithm

P-solvable Loop System of recurrence equations System of closed forms Polynomial Invariant Ideal

Symb.Summ. GB

slide-67
SLIDE 67

P-solvable Loops: while . . . do S end while

The closed forms of the loop variables X = {x1, . . . , xm}: CF(Sn, ES, X, X0) :      x1[n] = q1(n, θn

1, . . . , θn s)

. . . xm[n] = qm(n, θn

1, . . . , θn s)

, with algebraic dependencies A = I(n, θn

1, . . . , θn s).

Notations:

  • 1. n ∈ N is the loop counter and Sn denotes S; . . . ; S
  • n times

;

  • 2. xi[n] is the value of xi at iteration n.

X0 are the initial values of loop variables before Sn;

  • 3. q1, . . . , qm ∈ ¯

K[n, θn

1, . . . , θn s];

  • 4. θ1, . . . , θs ∈ ¯

K, ES = {θn

1, . . . , θn s}.

slide-68
SLIDE 68

P-solvable Loops: while . . . do S end while

The closed forms of the loop variables X = {x1, . . . , xm}: CF(Sn, ES, X, X0) :      x1[n] = q1(n, θn

1, . . . , θn s)

. . . xm[n] = qm(n, θn

1, . . . , θn s)

, with algebraic dependencies A = I(n, θn

1, . . . , θn s).

Polynomial Invariant Ideal: I(x1, . . . , xm).

I(x1, . . . , xm) =

GB xi − qi(n, θn

1, . . . , θn s) + A ∩ K[x1, . . . , xm]

{p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

slide-69
SLIDE 69

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while

slide-70
SLIDE 70

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while x[n] x[n + 1] x[n + 2] . . . . . . y[n] y[n + 1] y[n + 2] . . . . . . z[n] z[n + 1] z[n + 2] . . . . . .

slide-71
SLIDE 71

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while x[n] x[n + 1] x[n + 2] . . . . . . y[n] y[n + 1] y[n + 2] . . . . . . z[n] z[n + 1] z[n + 2] . . . . . .

slide-72
SLIDE 72

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while x[n] x[n + 1] x[n + 2] . . . . . . y[n] y[n + 1] y[n + 2] . . . . . . z[n] z[n + 1] z[n + 2] . . . . . .

slide-73
SLIDE 73

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while x[n] x[n + 1] x[n + 2] . . . . . . y[n] y[n + 1] y[n + 2] . . . . . . z[n] z[n + 1] z[n + 2] . . . . . .

slide-74
SLIDE 74

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while x[n] x[n + 1] x[n + 2] . . . . . . y[n] y[n + 1] y[n + 2] . . . . . . z[n] z[n + 1] z[n + 2] . . . . . .

slide-75
SLIDE 75

Invariant Generation for Loops with Assignments Only

  • Example. [K. Zuse, 1993]

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while x[n] x[n + 1] x[n + 2] . . . . . . y[n] y[n + 1] y[n + 2] . . . . . . z[n] z[n + 1] z[n + 2] . . . . . .

slide-76
SLIDE 76

Extracting and Solving Recurrences

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while

n ≥ 0

     x[n + 1]

= C−finite

x[n]/2 y[n + 1]

= C−finite

y[n] + x[n] z[n]

= C−finite

2 ∗ z[n] − 2 ∗ y[n] − x[n]                    x[n]

= C−finite

1 2n x[0]

y[n]

= C−finite

y[0] + 2x[0] −

1 2n−1 x[0]

z[n]

= C−finite

2n(z[0] − 2y[0] − 2x[0])−

1 2n−1 x[0] + 2y[0] + 4x[0]

= Alg.Dep.

slide-77
SLIDE 77

Extracting and Solving Recurrences

z := 0; y := 1; x := 1/2; while . . . do z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 end while

n ≥ 0

     x[n + 1]

= C−finite

x[n]/2 y[n + 1]

= C−finite

y[n] + x[n] z[n]

= C−finite

2 ∗ z[n] − 2 ∗ y[n] − x[n]                    x[n]

= C−finite

1 2n x[0]

y[n]

= C−finite

y[0] + 2x[0] −

1 2n−1 x[0]

z[n]

= C−finite

2n(z[0] − 2y[0] − 2x[0])−

1 2n−1 x[0] + 2y[0] + 4x[0]

= Alg.Dep.

slide-78
SLIDE 78

Algebraic Dependencies and Variable Elimination

z := 0; y := 1; x := 1/2; while[. . . , z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 ]

n ≥ 0, a = 2n, b = 2−n

             x

= C−finite

b ∗ x[0] y

= C−finite

y[0] + 2 ∗ x[0] − 2 ∗ b ∗ x[0] z

= C−finite

a ∗ (z[0] − 2 ∗ y[0] − 2 ∗ x[0])− 2 ∗ b ∗ x[0] + 2 ∗ y[0] + 4 ∗ x[0]

= Alg.Dep.

a ∗ b − 1

P-solvable Loop

slide-79
SLIDE 79

Algebraic Dependencies and Variable Elimination

z := 0; y := 1; x := 1/2; while[. . . , z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 ]

n ≥ 0, a = 2n, b = 2−n

             x

= C−finite

b ∗ x[0] y

= C−finite

y[0] + 2 ∗ x[0] − 2 ∗ b ∗ x[0] z

= C−finite

a ∗ (z[0] − 2 ∗ y[0] − 2 ∗ x[0])− 2 ∗ b ∗ x[0] + 2 ∗ y[0] + 4 ∗ x[0]

= Alg.Dep.

a ∗ b − 1

P-solvable Loop Polynomial Invariant (GB):

  • 2x+y−2x[0]−y[0] = 0
  • y2−y∗z+2∗z∗x[0]+z∗y[0]−y[0]2−2∗x[0]∗z[0] = 0
slide-80
SLIDE 80

Algebraic Dependencies and Variable Elimination

z := 0; y := 1; x := 1/2; while[. . . , z := 2 ∗ z − 2 ∗ y − x; y := y + x; x := x/2 ]

n ≥ 0, a = 2n, b = 2−n

             x

= C−finite

b ∗ x[0] y

= C−finite

y[0] + 2 ∗ x[0] − 2 ∗ b ∗ x[0] z

= C−finite

a ∗ (z[0] − 2 ∗ y[0] − 2 ∗ x[0])− 2 ∗ b ∗ x[0] + 2 ∗ y[0] + 4 ∗ x[0]

= Alg.Dep.

a ∗ b − 1

P-solvable Loop Polynomial Invariant (GB):

  • 2 ∗ x + y − 2 = 0
  • 2 ∗ z − y ∗ z + y2 − 1 = 0
slide-81
SLIDE 81

Further Examples.

k := 0; j := 1; m := 1; while m ≤ n do k := k + 1; j := j + 2; m := m + j end while i := 0; f := 1; g := 1 while i < n do t := f; f := f + g; g := t end while

slide-82
SLIDE 82

Further Examples.

(1) Integer square root: k := 0; j := 1; m := 1; while m ≤ n do k := k + 1; j := j + 2; m := m + j end while (2) Fibonacci numbers i := 0; f := 1; g := 1 while i < n do t := f; f := f + g; g := t end while

slide-83
SLIDE 83

Further Examples.

(1) Integer square root: k := 0; j := 1; m := 1; while m ≤ n do k := k + 1; j := j + 2; m := m + j end while Invariant: 2k + 1 = j ∧ 4m = (j + 1)2 (2) Fibonacci numbers i := 0; f := 1; g := 1 while i < n do t := f; f := f + g; g := t end while Invariant: f 4+g4+2f ∗g3−2f 3∗g−f 2∗g2−1 = 0

slide-84
SLIDE 84

Outline

Overview of the Method Algebraic Techniques for Invariant Generation Polynomial Invariants for Loops with Assignments Only Polynomial Invariants for Loops with Conditionals Examples Conclusions

slide-85
SLIDE 85

Overview of Our Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → non-deterministic programs:

← if[b then S1 else S2] → if[. . . then S1 else S2] − → S1|S2 ← while[cond, S] → while[. . . , S] − → S∗ ← while[. . . , if[. . . , S1]; . . . ; if[. . . , Sk]] − → (S1| . . . |Sk)∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals for P-solvable loops:

← {p(X) = 0 ∧ X = X0} (S1| . . . |Sk)∗ {p(X) = 0}

◮ Polynomial invariant ideal represented by Gr¨

  • bner bases;
slide-86
SLIDE 86

Overview of Our Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → non-deterministic programs:

← if[b then S1 else S2] → if[. . . then S1 else S2] − → S1|S2 ← while[cond, S] → while[. . . , S] − → S∗ ← while[. . . , if[. . . , S1]; . . . ; if[. . . , Sk]] − → (S1| . . . |Sk)∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals for P-solvable loops:

← {p(X) = 0 ∧ X = X0} (S1| . . . |Sk)∗ {p(X) = 0}

◮ Polynomial invariant ideal represented by Gr¨

  • bner bases;
slide-87
SLIDE 87

Overview of Our Method - Further Considerations

◮ Loops with assignments and with conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → non-deterministic programs:

← if[b then S1 else S2] → if[. . . then S1 else S2] − → S1|S2 ← while[cond, S] → while[. . . , S] − → S∗ ← while[. . . , if[. . . , S1]; . . . ; if[. . . , Sk]] − → (S1| . . . |Sk)∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals for P-solvable loops:

← {p(X) = 0 ∧ X = X0} (S1| . . . |Sk)∗ {p(X) = 0}

◮ Polynomial invariant ideal represented by Gr¨

  • bner bases;
slide-88
SLIDE 88

Overview of Our Method - Further Considerations

◮ Loops with assignments and with/without conditional branches.

Structural constraints on assignments with polynomial rhs. ← Summation algorithms (Gosper’s, C-finite) Tests are ignored → non-deterministic programs:

← if[b then S1 else S2] → if[. . . then S1 else S2] − → S1|S2 ← while[b, S] → while[. . . , S] − → S∗ ← while[. . . , if[. . . , S1]; . . . ; if[. . . , Sk]] − → (S1| . . . |Sk)∗

◮ Automated Loop Invariant Generation by Algebraic Techniques

Over the Rationals for P-solvable loops:

← {p(X) = 0 ∧ X = X0} (S1| . . . |Sk)∗ {p(X) = 0}

◮ Polynomial invariant ideal represented by Gr¨

  • bner bases;

◮ Implementation: ALIGATOR → programs working on numbers.

slide-89
SLIDE 89

RECAP – P-solvable Loop S∗ with Assignments Only

Values of loop variables X = {x1, . . . , xm} at loop iteration n ∈ N: Sn ≡ S; . . . ; S

  • n times

:      x1[n] = q1(n, θn

1, . . . , θn s)

. . . xm[n] = qm(n, θn

1, . . . , θn s)

, with algebraic dependencies: A = I(n, θn

1, . . . , θn s) = r | r(n, θn 1, . . . , θn s) = 0, ∀n ∈ N ¯

K[n, θn

1, . . . , θn s]

slide-90
SLIDE 90

RECAP – P-solvable Loop S∗ with Assignments Only

Values of loop variables X = {x1, . . . , xm} at loop iteration n ∈ N: Sn ≡ S; . . . ; S

  • n times

:      x1[n] = q1(n, θn

1, . . . , θn s)

. . . xm[n] = qm(n, θn

1, . . . , θn s)

, with algebraic dependencies: A = I(n, θn

1, . . . , θn s) = r | r(n, θn 1, . . . , θn s) = 0, ∀n ∈ N ¯

K[n, θn

1, . . . , θn s]

Examples.

  • I(n, 2n, 4n) = (2n)2 − 4n
  • I(n, 2n, 2−n) = (2n) ∗ (2−n) − 1
  • I(n, 2n, 3n) = ∅
  • I(n, 1+

√ 5 2 n, 1− √ 5 2 n) =

1+

√ 5 2 n2 ∗

1−

√ 5 2 n2 − 1

slide-91
SLIDE 91

RECAP – P-solvable Loop S∗ with Assignments Only

Values of loop variables X = {x1, . . . , xm} at loop iteration n ∈ N: Sn ≡ S; . . . ; S

  • n times

:      x1[n] = q1(n, θn

1, . . . , θn s)

. . . xm[n] = qm(n, θn

1, . . . , θn s)

, with algebraic dependencies: A = I(n, θn

1, . . . , θn s) = r | r(n, θn 1, . . . , θn s) = 0, ∀n ∈ N ¯

K[n, θn

1, . . . , θn s]

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm) = xi − qi + A ∩ K[x1, . . . , xm]

{p(X) = 0 ∧ X = X0} S∗ {p(X) = 0}

slide-92
SLIDE 92

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

slide-93
SLIDE 93

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

{p(X) = 0 ∧ X = X0} (S1| . . . |Sk)∗ {p(X) = 0}

slide-94
SLIDE 94

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

{p(X) = 0 ∧ X = X0} (S∗

1 ∗ · · · ∗ S∗ k )∗

{p(X) = 0}

slide-95
SLIDE 95

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

{p(X) = 0 ∧ X = X0} (S∗

1 ∗ · · · ∗ S∗ k )∗

{p(X) = 0}

First algorithmic attempt:

(S∗

1 ∗ · · · ∗ S∗ k )∗

  • arbitrary MANY iterations

I∗

S∗

1 ∗ · · · ∗ S∗ k

  • ONE iteration

PI0 = Ik ← S∗

1 ; . . . ; S∗ k

  • loop sequence

Ik

slide-96
SLIDE 96

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

{p(X) = 0 ∧ X = X0} (S∗

1 ∗ · · · ∗ S∗ k )∗

{p(X) = 0}

Idea of the algorithm:

(S∗

1 ∗ · · · ∗ S∗ k )∗

  • arbitrary MANY iterations

I∗ ← ⊆ . . . . . . ← ⊆ (S∗

1 ∗ · · · ∗ S∗ k ); S∗ i

  • TWO iterations

PI1 = Ik+1 ← ⊆ S∗

1 ∗ · · · ∗ S∗ k

  • ONE iteration

PI0 = Ik

slide-97
SLIDE 97

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

{p(X) = 0 ∧ X = X0} (S∗

1 ∗ · · · ∗ S∗ k )∗

{p(X) = 0}

Idea of the algorithm:

(S∗

1 ∗ · · · ∗ S∗ k )∗

  • arbitrary MANY iterations

I∗ ← ⊆ . . . . . . ← ⊆ (S∗

1 ∗ · · · ∗ S∗ k ); S∗ i

  • TWO iterations

PI1 = Ik+1 ← ⊆ S∗

1 ∗ · · · ∗ S∗ k

  • ONE iteration

PI0 = Ik Termination? Not guaranteed for arbitrary ideals!

slide-98
SLIDE 98

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

P-solvable loop (S1| . . . |Sk)∗ ⇐ ⇒ P-solvable inner loops S∗

i

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

(S1| . . . |Sk)∗ is equivalent to (S∗

1 ∗ · · · ∗ S∗ k )∗

Polynomial Invariant Ideal: I∗ = I(x1, . . . , xm)

{p(X) = 0 ∧ X = X0} (S∗

1 ∗ · · · ∗ S∗ k )∗

{p(X) = 0}

Idea of the algorithm:

(S∗

1 ∗ · · · ∗ S∗ k )∗

  • arbitrary MANY iterations

I∗ ← ⊆ . . . . . . ← ⊆ (S∗

1 ∗ · · · ∗ S∗ k ); S∗ i

  • TWO iterations

PI1 = Ik+1 ← ⊆ S∗

1 ∗ · · · ∗ S∗ k

  • ONE iteration

PI0 = Ik Termination? Always terminates!

slide-99
SLIDE 99

P-solvable Loops with Conditionals (S1| . . . |Sk)∗

Program Algorithm while

  • . . . ,

l = k, Ll = Perm[1, . . . , k] PI =

  • Ik

Il =

  • p | {p(X) = 0 ∧ X = X0} S∗

w1 ; . . . ; S∗ wl {p(X) = 0}

  • , (w1, . . . , wl ) ∈ Ll

if[. . . , S1]; repeat . . . PI′ = PI Ll+1 =

k

  • i = 1

Ll ◦ Si, l = l + 1 if[. . . , Sk]

  • PI =
  • Il

Il =

  • p |{p(X) = 0 ∧ X = X0} S∗

w1 ; . . . ; S∗ wl ; {p(X) = 0}

  • , (w1, . . . , wl ) ∈ Ll

until PI = PI′ = I∗

Idea of the algorithm:

(S∗

1 ∗ · · · ∗ S∗ k )∗

  • arbitrary MANY iterations

I∗ ← ⊆ . . . . . . ← ⊆ (S∗

1 ∗ · · · ∗ S∗ k ); S∗ i

  • TWO iterations

PI1 = Ik+1 ← ⊆ S∗

1 ∗ · · · ∗ S∗ k

  • ONE iteration

PI0 = Ik Termination? Always terminates!

slide-100
SLIDE 100

Proof of Termination - Example

Initial values: a = x, b = y, p = 1, q = 0, r = 0, s = 1 Loop: a := a − b; p := p − q; r := r − s

  • S1

| b := b − a; q := q − p; s := s − r

  • S2

Step 0: PI0 = 18 polynomials = Step 1: PI1 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y Step 2: PI2 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y PI1 = PI2 = I∗

slide-101
SLIDE 101

Proof of Termination - Example

Initial values: a = x, b = y, p = 1, q = 0, r = 0, s = 1 Loop: a := a − b; p := p − q; r := r − s

  • S1

| b := b − a; q := q − p; s := s − r

  • S2

Step 0: PI0 = 18 polynomials =

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2

S∗

2 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 1: PI1 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y Step 2: PI2 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y PI1 = PI2 = I∗

slide-102
SLIDE 102

Proof of Termination - Example

Initial values: a = x, b = y, p = 1, q = 0, r = 0, s = 1 Loop: a := a − b; p := p − q; r := r − s

  • S1

| b := b − a; q := q − p; s := s − r

  • S2

Step 0: PI0 = 18 polynomials =

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2

S∗

2 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 1: PI1 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2 ; S∗ 1

S∗

1 ; S∗ 2 ; S∗ 2

S∗

2 ; S∗ 1 ; S∗ 2

S∗

2 ; S∗ 1 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 2: PI2 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y PI1 = PI2 = I∗

slide-103
SLIDE 103

Proof of Termination - Example

Initial values: a = x, b = y, p = 1, q = 0, r = 0, s = 1 Loop: a := a − b; p := p − q; r := r − s

  • S1

| b := b − a; q := q − p; s := s − r

  • S2

Step 0: PI0 = 18 polynomials =

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2

S∗

2 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 1: PI1 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2 ; S∗ 1

S∗

1 ; S∗ 2 ; S∗ 2

S∗

2 ; S∗ 1 ; S∗ 2

S∗

2 ; S∗ 1 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 2: PI2 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y PI1 = PI2 = I∗

slide-104
SLIDE 104

Proof of Termination - Example

Initial values: a = x, b = y, p = 1, q = 0, r = 0, s = 1 Loop: a := a − b; p := p − q; r := r − s

  • S1

| b := b − a; q := q − p; s := s − r

  • S2

Step 0: PI0 = 18 polynomials =

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2

S∗

2 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 1: PI1 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • S∗

1 ; S∗ 2 ; S∗ 1

S∗

1 ; S∗ 2 ; S∗ 2

S∗

2 ; S∗ 1 ; S∗ 2

S∗

2 ; S∗ 1 ; S∗ 1

{P(a, b, p, q, r, s) = 0} Step 2: PI2 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y PI1 = PI2 = I∗

  • P(a, b, p, q, r, s) = 0

(a, b, p, q, r, s) = (x, y, 1, 0, 0, 1)

  • (S1|S2)∗

{P(a, b, p, q, r, s) = 0}

slide-105
SLIDE 105

Proof of Termination - Example

Initial values: a = x, b = y, p = 1, q = 0, r = 0, s = 1 Loop: a := a − b; p := p − q; r := r − s

  • S1

| b := b − a; q := q − p; s := s − r

  • S2

Step 0: PI0 = 18 polynomials =

  • s − 1, b − qx − y, br − a + x, qr − p + 1, px + ry − a, bp − aq − y

p − 1, b − qx − sy, br − as + x,qr − s + 1, x + ry − a, b − aq − y, asy − ab + bx − xy

Dimension: 4 Step 1: PI1 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y Dimension: 3 Step 2: PI2 = b − qx − sy, br − as + x, qr − ps + 1, px + ry − a, bp − aq − y PI1 = PI2 = I∗ Dimension: 3

slide-106
SLIDE 106

Proof of Termination

Properties of the algorithm:

◮ I∗ ⊆ · · · ⊆ PI1 = Ik+1 ⊆ PI0 = Ik ◮ if PIn = PIn+1 then I∗ = PIn

(TERMINATION CRITERIA)

slide-107
SLIDE 107

Proof of Termination

Assume PI1 = Ik+1 PI0 = Ik. Then:

◮ Ik+1 Ik for some k-loop sequence; ◮ dim Wr′ < dim Ur for some r, r ′.

Termination Proof.

  • 1. Ik+1, Ik are prime ideals;

pq ∈ Ik = ⇒ p ∈ Ik or q ∈ Ik

  • 2. The minimal prime ideal decomposition:

Ik =

r

Ur

  • ∩ ¯

K[X] and Ik+1 =

r ′

Wr ′

  • ∩ ¯

K[X]

with

◮ Ur, Wr′ are prime ideals; ◮ Ua Ub and Wa′ Wb′ for any a = b and a′ = b′; ◮ (∀r ′)(∃r) dim Wr′ ≤ dim Ur.

  • 3. Dimension is finite. It cannot infinitely decrease.

(∃n) PIn =

  • Ik+n =
  • Ik+n+1 = PIn+1
slide-108
SLIDE 108

Proof of Termination

Assume PI1 = Ik+1 PI0 = Ik. Then:

◮ Ik+1 Ik for some k-loop sequence; ◮ dim Wr′ < dim Ur for some r, r ′.

Termination Proof.

  • 1. Ik+1, Ik are prime ideals;

pq ∈ Ik = ⇒ p ∈ Ik or q ∈ Ik

  • 2. The minimal prime ideal decomposition:

Ik =

r

Ur

  • ∩ ¯

K[X] and Ik+1 =

r ′

Wr ′

  • ∩ ¯

K[X]

with

◮ Ur, Wr′ are prime ideals; ◮ Ua Ub and Wa′ Wb′ for any a = b and a′ = b′; ◮ (∀r ′)(∃r) dim Wr′ ≤ dim Ur.

  • 3. Dimension is finite. It cannot infinitely decrease.

(∃n) PIn =

  • Ik+n =
  • Ik+n+1 = PIn+1
slide-109
SLIDE 109

Proof of Termination

Assume PI1 = Ik+1 PI0 = Ik. Then:

◮ Ik+1 Ik for some k-loop sequence; ◮ dim Wr′ < dim Ur for some r, r ′.

Termination Proof.

  • 1. Ik+1, Ik are prime ideals;

pq ∈ Ik = ⇒ p ∈ Ik or q ∈ Ik

  • 2. The minimal prime ideal decomposition:

Ik =

r

Ur

  • ∩ ¯

K[X] and Ik+1 =

r ′

Wr ′

  • ∩ ¯

K[X]

with

◮ Ur, Wr′ are prime ideals; ◮ Ua Ub and Wa′ Wb′ for any a = b and a′ = b′; ◮ (∀r ′)(∃r) dim Wr′ ≤ dim Ur.

  • 3. Dimension is finite. It cannot infinitely decrease.

(∃n) PIn =

  • Ik+n =
  • Ik+n+1 = PIn+1
slide-110
SLIDE 110

Proof of Termination

Assume PI1 = Ik+1 PI0 = Ik. Then:

◮ Ik+1 Ik for some k-loop sequence; ◮ dim Wr′ < dim Ur for some r, r ′.

Termination Proof.

  • 1. Ik+1, Ik are prime ideals;

pq ∈ Ik = ⇒ p ∈ Ik or q ∈ Ik

  • 2. The minimal prime ideal decomposition:

Ik =

r

Ur

  • ∩ ¯

K[X] and Ik+1 =

r ′

Wr ′

  • ∩ ¯

K[X]

with

◮ Ur, Wr′ are prime ideals; ◮ Ua Ub and Wa′ Wb′ for any a = b and a′ = b′; ◮ (∀r ′)(∃r) dim Wr′ ≤ dim Ur.

  • 3. Dimension is finite. It cannot infinitely decrease.

(∃n) PIn =

  • Ik+n =
  • Ik+n+1 = PIn+1
slide-111
SLIDE 111

Proof of Termination

Assume PI1 = Ik+1 PI0 = Ik. Then:

◮ Ik+1 Ik for some k-loop sequence; ◮ dim Wr′ < dim Ur for some r, r ′.

Termination Proof.

  • 1. Ik+1, Ik are prime ideals;

pq ∈ Ik = ⇒ p ∈ Ik or q ∈ Ik

  • 2. The minimal prime ideal decomposition:

Ik =

r

Ur

  • ∩ ¯

K[X] and Ik+1 =

r ′

Wr ′

  • ∩ ¯

K[X]

with

◮ Ur, Wr′ are prime ideals; ◮ Ua Ub and Wa′ Wb′ for any a = b and a′ = b′; ◮ (∀r ′)(∃r) dim Wr′ ≤ dim Ur.

  • 3. Dimension is finite. It cannot infinitely decrease.

(∃n) PIn =

  • Ik+n =
  • Ik+n+1 = PIn+1
slide-112
SLIDE 112

Outline

Overview of the Method Algebraic Techniques for Invariant Generation Polynomial Invariants for Loops with Assignments Only Polynomial Invariants for Loops with Conditionals Examples Conclusions

slide-113
SLIDE 113

Extended Euclid’s Algorithm for GCD[x, y]

Program Polynomial Invariants a := x; b := y; p := 1; r := 0; q := 0; s := 1; while[(a = b), if[a > b then a := a − b; then p := p − q; then r := r − s else b := b − a; else q := q − p; else s := s − r]] y = bp − aq x = as − br 1 = ps − qr a = px + ry b = qx + sy

slide-114
SLIDE 114

Related Work

Work Invariant Restrictions Loop Restrictions Complete MOS, 2006 yes no no* SSM, 2004 yes no no* RCK, 2007a yes no no*

tool: Inv

RCK, 2007b no yes* yes

tool: Solvable

LK, 2008/09 no yes yes

tool: Aligator

slide-115
SLIDE 115

Some Experimental Results

wrt Solvable [RCK07b] and Inv [RCK07a]

Binary Division Timing ♯ Iters ♯ Polys Aligator 0.55 s 1 1 Solvable 1.78 s 3 1 Inv 1.77 s 5 1 Euclid’s Alg. Timing ♯ Iters ♯ Polys Aligator 9.02 s 2 5 Solvable 3.05 s 5 5 Inv 4.13 s 8 1 Fermat’s Alg. Timing ♯ Iters ♯ Polys Aligator 0.24 s 1 1 Solvable 1.73 s 4 1 Inv 2.95 s 8 1 LCM-GCD Timing ♯ Iters ♯ Polys Aligator 1.23 s 2 1 Solvable 2.01 s 5 1 Inv 4.32 s 9 1 Binary Product Timing ♯ Iters ♯ Polys Aligator 0.63 s 1 1 Solvable 1.74 s 4 1 Inv 2.79 s 8 1 Square Root Timing ♯ Iters ♯ Polys Aligator 0.19 s 1 2 Solvable 1.34 s 2 2 Inv 2.17 s 6 2 Wensley’s Alg. Timing ♯ Iters ♯ Polys Aligator 0.63 s 1 3 Solvable 1.95 s 4 3 Inv 3.53 s 8 3

slide-116
SLIDE 116

Outline

Overview of the Method Algebraic Techniques for Invariant Generation Polynomial Invariants for Loops with Assignments Only Polynomial Invariants for Loops with Conditionals Examples Conclusions

slide-117
SLIDE 117

Conclusions

◮ Correct and complete algorithm: finds all polynomial invariants; ◮ Implementation: ALIGATOR

1. Solving recurrences;

  • Symbolic Summation

2. Computing algebraic dependencies; 3. Eliminating non-program variables; 4. Intersecting ideals;

  • Gr¨
  • bner basis

◮ ALIGATOR successfully tried on many examples;

Less time/iteration needed than other tools. http://mtc.epfl.ch/software-tools/Aligator/

slide-118
SLIDE 118

End of Session 2

Slides for session 2 ended here . . .