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 ) → n th 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 → CF quo ( n , quo [ 0 ]) quo := quo + 1 ; → quo [ n ] = quo [ 0 ] + n quo [ n + 1 ] = quo [ n ] + 1 quo := quo + 1 ; rem [ n + 1 ] = rem [ n ] − y → CF rem ( 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] . . .
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 ) → n th 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 → CF quo ( n , quo [ 0 ]) quo := quo + 1 ; → quo [ n ] = quo [ 0 ] + n quo [ n + 1 ] = quo [ n ] + 1 quo := quo + 1 ; rem [ n + 1 ] = rem [ n ] − y → CF rem ( 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] . . .
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 n ≥ 0 � rem [ n + 1 ] terms of n th iteration → recurrence relations = rem [ n ] − y of variables; quo [ n + 1 ] = quo [ n ] + 1 2. Solve recurrence relations → closed forms of � rem [ n ] = rem [ 0 ] − n ∗ y variables: functions of iteration counter n quo [ n ] = quo [ 0 ] + n ↑ methods from symbolic summation; 3. Eliminate n and (optionally) initial value rem = rem [ 0 ] − ( quo − quo [ 0 ]) ∗ y substitution; 4. Result: set of invariants rem = x − quo ∗ y → Poly Invariant Result: Polynomial ideal → Finite basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q . Result: Polynomial ideal → Gr¨ obner basis
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 n ≥ 0 � rem [ n + 1 ] terms of n th iteration → recurrence relations = rem [ n ] − y of variables; quo [ n + 1 ] = quo [ n ] + 1 2. Solve recurrence relations → closed forms of � rem [ n ] = rem [ 0 ] − n ∗ y variables: functions of iteration counter n quo [ n ] = quo [ 0 ] + n ↑ methods from symbolic summation; 3. Eliminate n and (optionally) initial value rem = rem [ 0 ] − ( quo − quo [ 0 ]) ∗ y substitution; 4. Result: set of invariants rem = x − quo ∗ y → Poly Invariant Result: Polynomial ideal → Finite basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q . Result: Polynomial ideal → Gr¨ obner basis
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 n ≥ 0 � rem [ n + 1 ] terms of n th iteration → recurrence relations = rem [ n ] − y of variables; quo [ n + 1 ] = quo [ n ] + 1 2. Solve recurrence relations → closed forms of � rem [ n ] = rem [ 0 ] − n ∗ y variables: functions of iteration counter n quo [ n ] = quo [ 0 ] + n ↑ methods from symbolic summation; 3. Eliminate n and (optionally) initial value rem = rem [ 0 ] − ( quo − quo [ 0 ]) ∗ y substitution; 4. Result: set of invariants rem = x − quo ∗ y → Poly Invariant Result: Polynomial ideal → Finite basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q . Result: Polynomial ideal → Gr¨ obner basis
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 n ≥ 0 � rem [ n + 1 ] terms of n th iteration → recurrence relations = rem [ n ] − y of variables; quo [ n + 1 ] = quo [ n ] + 1 2. Solve recurrence relations → closed forms of � rem [ n ] = rem [ 0 ] − n ∗ y variables: functions of iteration counter n quo [ n ] = quo [ 0 ] + n ↑ methods from symbolic summation; 3. Eliminate n and (optionally) initial value rem = rem [ 0 ] − ( quo − quo [ 0 ]) ∗ y substitution; 4. Result: set of invariants rem = x − quo ∗ y → Poly Invariant Result: Polynomial ideal → Finite basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q . Result: Polynomial ideal → Gr¨ obner basis
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 n ≥ 0 � rem [ n + 1 ] terms of n th iteration → recurrence relations = rem [ n ] − y of variables; quo [ n + 1 ] = quo [ n ] + 1 2. Solve recurrence relations → closed forms of � rem [ n ] = rem [ 0 ] − n ∗ y variables: functions of iteration counter n quo [ n ] = quo [ 0 ] + n ↑ methods from symbolic summation; 3. Eliminate n and (optionally) initial value rem = rem [ 0 ] − ( quo − quo [ 0 ]) ∗ y substitution; 4. Result: set of invariants rem = x − quo ∗ y → Poly Invariant Result: Polynomial ideal → Finite basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q . Result: Polynomial ideal → Gr¨ obner basis
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 n ≥ 0 � rem [ n + 1 ] terms of n th iteration → recurrence relations = rem [ n ] − y of variables; quo [ n + 1 ] = quo [ n ] + 1 2. Solve recurrence relations → closed forms of � rem [ n ] = rem [ 0 ] − n ∗ y variables: functions of iteration counter n quo [ n ] = quo [ 0 ] + n ↑ methods from symbolic summation; 3. Eliminate n and (optionally) initial value rem = rem [ 0 ] − ( quo − quo [ 0 ]) ∗ y substitution; 4. Result: set of invariants rem = x − quo ∗ y → Poly Invariant Result: Polynomial ideal → Finite basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q . Result: Polynomial ideal → Gr¨ obner basis
Overview of Our Method Specification Loop Polynomial Invariant Polynomial Invariant Gr¨ obner basis Symbolic Summation (C-finite) Verification Conditions Proving
Overview of the Method x := 1 ; y := 0 ; while [ . . . , x := 2 ∗ x ; y := 1 2 ∗ y + 1 ] n ≥ 0 , a = 2 n , b = 2 − n 1. Express state from ( n + 1 ) th iteration in � x [ n + 1 ] = 2 ∗ x [ n ] terms of n th iteration → recurrence relations 1 y [ n + 1 ] = 2 ∗ y [ n ] + 1 of variables; � x [ n ] 2. Solve recurrence relations → closed forms of 2 n ∗ x [ 0 ] = variables: functions of iteration counter n 1 2 2 n ∗ y [ 0 ] − y [ n ] = 2 n + 2 ↑ methods from symbolic summation; a ∗ x [ 0 ] x = 3. Identify polynomial/algebraic dependencies b ∗ y [ 0 ] − 2 ∗ b + 2 y = among exponentials in n ; a ∗ b − 1 0 = 4. Eliminate n and variables standing for x ∗ y − 2 ∗ x + 2 = 0 algebraically related exponentials in n → elimination by Gr¨ obner bases; 5. Result: Polynomial ideal → Gr¨ obner basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q .
Overview of the Method x := 1 ; y := 0 ; while [ . . . , x := 2 ∗ x ; y := 1 2 ∗ y + 1 ] n ≥ 0 , a = 2 n , b = 2 − n 1. Express state from ( n + 1 ) th iteration in � x [ n + 1 ] = 2 ∗ x [ n ] terms of n th iteration → recurrence relations 1 y [ n + 1 ] = 2 ∗ y [ n ] + 1 of variables; � x [ n ] 2. Solve recurrence relations → closed forms of 2 n ∗ x [ 0 ] = variables: functions of iteration counter n 1 2 2 n ∗ y [ 0 ] − y [ n ] = 2 n + 2 ↑ methods from symbolic summation; a ∗ x [ 0 ] x = 3. Identify polynomial/algebraic dependencies b ∗ y [ 0 ] − 2 ∗ b + 2 y = among exponentials in n ; a ∗ b − 1 0 = 4. Eliminate n and variables standing for x ∗ y − 2 ∗ x + 2 = 0 algebraically related exponentials in n → elimination by Gr¨ obner bases; 5. Result: Polynomial ideal → Gr¨ obner basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q .
Overview of the Method x := 1 ; y := 0 ; while [ . . . , x := 2 ∗ x ; y := 1 2 ∗ y + 1 ] n ≥ 0 , a = 2 n , b = 2 − n 1. Express state from ( n + 1 ) th iteration in � x [ n + 1 ] = 2 ∗ x [ n ] terms of n th iteration → recurrence relations 1 y [ n + 1 ] = 2 ∗ y [ n ] + 1 of variables; � x [ n ] 2. Solve recurrence relations → closed forms of 2 n ∗ x [ 0 ] = variables: functions of iteration counter n 1 2 2 n ∗ y [ 0 ] − y [ n ] = 2 n + 2 ↑ methods from symbolic summation; a ∗ x [ 0 ] x = 3. Identify polynomial/algebraic dependencies b ∗ y [ 0 ] − 2 ∗ b + 2 y = among exponentials in n ; a ∗ b − 1 0 = 4. Eliminate n and variables standing for x ∗ y − 2 ∗ x + 2 = 0 algebraically related exponentials in n → elimination by Gr¨ obner bases; 5. Result: Polynomial ideal → Gr¨ obner basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q .
Overview of the Method x := 1 ; y := 0 ; while [ . . . , x := 2 ∗ x ; y := 1 2 ∗ y + 1 ] n ≥ 0 , a = 2 n , b = 2 − n 1. Express state from ( n + 1 ) th iteration in � x [ n + 1 ] = 2 ∗ x [ n ] terms of n th iteration → recurrence relations 1 y [ n + 1 ] = 2 ∗ y [ n ] + 1 of variables; � x [ n ] 2. Solve recurrence relations → closed forms of 2 n ∗ x [ 0 ] = variables: functions of iteration counter n 1 2 2 n ∗ y [ 0 ] − y [ n ] = 2 n + 2 ↑ methods from symbolic summation; a ∗ x [ 0 ] x = 3. Identify polynomial/algebraic dependencies b ∗ y [ 0 ] − 2 ∗ b + 2 y = among exponentials in n ; a ∗ b − 1 0 = 4. Eliminate n and variables standing for x ∗ y − 2 ∗ x + 2 = 0 algebraically related exponentials in n → elimination by Gr¨ obner bases; 5. Result: Polynomial ideal → Gr¨ obner basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q .
Overview of the Method x := 1 ; y := 0 ; while [ . . . , x := 2 ∗ x ; y := 1 2 ∗ y + 1 ] n ≥ 0 , a = 2 n , b = 2 − n 1. Express state from ( n + 1 ) th iteration in � x [ n + 1 ] = 2 ∗ x [ n ] terms of n th iteration → recurrence relations 1 y [ n + 1 ] = 2 ∗ y [ n ] + 1 of variables; � x [ n ] 2. Solve recurrence relations → closed forms of 2 n ∗ x [ 0 ] = variables: functions of iteration counter n 1 2 2 n ∗ y [ 0 ] − y [ n ] = 2 n + 2 ↑ methods from symbolic summation; a ∗ x [ 0 ] x = 3. Identify polynomial/algebraic dependencies b ∗ y [ 0 ] − 2 ∗ b + 2 y = among exponentials in n ; a ∗ b − 1 0 = 4. Eliminate n and variables standing for x ∗ y − 2 ∗ x + 2 = 0 algebraically related exponentials in n → elimination by Gr¨ obner bases; 5. Result: Polynomial ideal → Gr¨ obner basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q .
Overview of the Method x := 1 ; y := 0 ; while [ . . . , x := 2 ∗ x ; y := 1 2 ∗ y + 1 ] n ≥ 0 , a = 2 n , b = 2 − n 1. Express state from ( n + 1 ) th iteration in � x [ n + 1 ] = 2 ∗ x [ n ] terms of n th iteration → recurrence relations 1 y [ n + 1 ] = 2 ∗ y [ n ] + 1 of variables; � x [ n ] 2. Solve recurrence relations → closed forms of 2 n ∗ x [ 0 ] = variables: functions of iteration counter n 1 2 2 n ∗ y [ 0 ] − y [ n ] = 2 n + 2 ↑ methods from symbolic summation; a ∗ x [ 0 ] x = 3. Identify polynomial/algebraic dependencies b ∗ y [ 0 ] − 2 ∗ b + 2 y = among exponentials in n ; a ∗ b − 1 0 = 4. Eliminate n and variables standing for x ∗ y − 2 ∗ x + 2 = 0 algebraically related exponentials in n → elimination by Gr¨ obner bases; 5. Result: Polynomial ideal → Gr¨ obner basis Result: p 1 = 0 , p 2 = 0 → p 1 + p 2 = 0 , p 1 · q = 0 , ∀ q .
Overview of Our Method Loop body System of recurrence equations System of closed forms Invariant equalities
Overview of Our Method Loop body System of recurrence equations Symb.Summ. System of closed forms GB Invariant equalities
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 = X 0 } S ∗ { p ( X ) = 0 }
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 = X 0 } S ∗ { p ( X ) = 0 }
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 = X 0 } S ∗ { p ( X ) = 0 }
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 = X 0 } S ∗ { p ( X ) = 0 }
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 ∗ ◮ A utomated L oop I nvariant G eneration by A lgebraic T echniques O ver the R ationals: polynomial invariant generation by symbolic summation and polynomial algebra algorithms ← P-solvable loops; ← { p ( X ) = 0 ∧ X = X 0 } S ∗ { p ( X ) = 0 } ◮ Implementation: ALIGATOR → programs working on numbers. http://mtc.epfl.ch/software-tools/Aligator
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
C-finite Recurrences x [ n ] in a Field K → linear recurrences with constant coefficients: x [ n + r ] = a 0 x [ n ] + . . . + a r − 1 x [ n + r − 1 ] , where ◮ r ∈ N is the recurrence order ; ◮ a 0 , . . . , a r − 1 ∈ K , with a 0 � = 0.
C-finite Recurrences x [ n ] in a Field K → linear recurrences with constant coefficients: x [ n + r ] = a 0 x [ n ] + . . . + a r − 1 x [ 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
C-finite Recurrences x [ n ] in a Field K → linear recurrences with constant coefficients: x [ n + r ] = a 0 x [ n ] + . . . + a r − 1 x [ n + r − 1 ] , C HARACTERISTIC POLYNOMIAL c ( y ) of x[n] is: c ( y ) = y r − a 0 − a 1 y − · · · − a r − 1 y r − 1 → distinct roots: θ 1 , . . . , θ s ∈ ¯ K with multiplicity e i ≥ 1. → CLOSED FORM OF x [ n ] : Linear combination of: θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e 1 + 1 ) θ n 1 , 1 , 1 , . . . . . . 1 θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e 2 + 1 ) θ n 2 , 2 , . . . . . . 2 2 . . . . . . . . . . . . . . . . . . θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e s + 1 ) θ n s , s , . . . . . . s s By regrouping: x [ n ] = q ( n , θ n 1 , · · · , θ n s )
C-finite Recurrences x [ n ] in a Field K → linear recurrences with constant coefficients: x [ n + r ] = a 0 x [ n ] + . . . + a r − 1 x [ n + r − 1 ] , C HARACTERISTIC POLYNOMIAL c ( y ) of x[n] is: c ( y ) = y r − a 0 − a 1 y − · · · − a r − 1 y r − 1 → distinct roots: θ 1 , . . . , θ s ∈ ¯ K with multiplicity e i ≥ 1. → CLOSED FORM OF x [ n ] : Linear combination of: θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e 1 + 1 ) θ n 1 , 1 , 1 , . . . . . . 1 θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e 2 + 1 ) θ n 2 , 2 , . . . . . . 2 2 . . . . . . . . . . . . . . . . . . θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e s + 1 ) θ n s , s , . . . . . . s s By regrouping: x [ n ] = q ( n , θ n 1 , · · · , θ n s )
C-finite Recurrences x [ n ] in a Field K → linear recurrences with constant coefficients: x [ n + r ] = a 0 x [ n ] + . . . + a r − 1 x [ n + r − 1 ] , C HARACTERISTIC POLYNOMIAL c ( y ) of x[n] is: c ( y ) = y r − a 0 − a 1 y − · · · − a r − 1 y r − 1 → distinct roots: θ 1 , . . . , θ s ∈ ¯ K with multiplicity e i ≥ 1. → CLOSED FORM OF x [ n ] : Linear combination of: θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e 1 + 1 ) θ n 1 , 1 , 1 , . . . . . . 1 θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e 2 + 1 ) θ n 2 , 2 , . . . . . . 2 2 . . . . . . . . . . . . . . . . . . θ n n θ n n ( n − 1 ) θ n n ( n − 1 ) · · · ( n − e s + 1 ) θ n s , s , . . . . . . s s By regrouping: x [ n ] = q ( n , θ n 1 , · · · , θ n s )
C-finite Recurrences x [ n ] in a Field K Example x [ n + 2 ] = 3 x [ n + 1 ] − 2 x [ n ] Given with x [ 0 ] = 0 , x [ 1 ] = 1. 1. Characteristic polynomial: y 2 − 3 y + 2 = 0 → Roots: θ 1 = 1 , θ 2 = 2 with e 1 = e 2 = 1 2. Closed form of x [ n ] : x [ n ] = α 1 n + β 2 n � 0 = x [ 0 ] = α + β → α = − 1 , β = 1 1 = x [ 1 ] = α + 2 β 3. Closed form of x [ n ] : x [ n ] = 2 n − 1
C-finite Recurrences x [ n ] in a Field K Example x [ n + 2 ] = 3 x [ n + 1 ] − 2 x [ n ] Given with x [ 0 ] = 0 , x [ 1 ] = 1. 1. Characteristic polynomial: y 2 − 3 y + 2 = 0 → Roots: θ 1 = 1 , θ 2 = 2 with e 1 = e 2 = 1 2. Closed form of x [ n ] : x [ n ] = α 1 n + β 2 n � 0 = x [ 0 ] = α + β → α = − 1 , β = 1 1 = x [ 1 ] = α + 2 β 3. Closed form of x [ n ] : x [ n ] = 2 n − 1
C-finite Recurrences x [ n ] in a Field K Example x [ n + 2 ] = 3 x [ n + 1 ] − 2 x [ n ] Given with x [ 0 ] = 0 , x [ 1 ] = 1. 1. Characteristic polynomial: y 2 − 3 y + 2 = 0 → Roots: θ 1 = 1 , θ 2 = 2 with e 1 = e 2 = 1 2. Closed form of x [ n ] : x [ n ] = α 1 n + β 2 n � 0 = x [ 0 ] = α + β → α = − 1 , β = 1 1 = x [ 1 ] = α + 2 β 3. Closed form of x [ n ] : x [ n ] = 2 n − 1
C-finite Recurrences x [ n ] in a Field K Example x [ n + 2 ] = 3 x [ n + 1 ] − 2 x [ n ] Given with x [ 0 ] = 0 , x [ 1 ] = 1. 1. Characteristic polynomial: y 2 − 3 y + 2 = 0 → Roots: θ 1 = 1 , θ 2 = 2 with e 1 = e 2 = 1 2. Closed form of x [ n ] : x [ n ] = α 1 n + β 2 n � 0 = x [ 0 ] = α + β → α = − 1 , β = 1 1 = x [ 1 ] = α + 2 β 3. Closed form of x [ n ] : x [ n ] = 2 n − 1
C-finite Recurrences x [ n ] in a Field K Example x [ n + 2 ] = 3 x [ n + 1 ] − 2 x [ n ] Given with x [ 0 ] = 0 , x [ 1 ] = 1. 1. Characteristic polynomial: y 2 − 3 y + 2 = 0 → Roots: θ 1 = 1 , θ 2 = 2 with e 1 = e 2 = 1 2. Closed form of x [ n ] : x [ n ] = α 1 n + β 2 n � 0 = x [ 0 ] = α + β → α = − 1 , β = 1 1 = x [ 1 ] = α + 2 β 3. Closed form of x [ n ] : x [ n ] = 2 n − 1
C-finite Recurrences x [ n ] in a Field K Example x [ n + 2 ] = 3 x [ n + 1 ] − 2 x [ n ] Given with x [ 0 ] = 0 , x [ 1 ] = 1. 1. Characteristic polynomial: y 2 − 3 y + 2 = 0 → Roots: θ 1 = 1 , θ 2 = 2 with e 1 = e 2 = 1 2. Closed form of x [ n ] : x [ n ] = α 1 n + β 2 n � 0 = x [ 0 ] = α + β → α = − 1 , β = 1 1 = x [ 1 ] = α + 2 β 3. Closed form of x [ n ] : x [ n ] = 2 n − 1
Program Assignments and C-finite Recurrences x := α x + h − → x [ n + 1 ] = α x [ n ] + h ( n ) h ( n ) = n d 1 θ 1 + · · · + n d s θ n with s Example x [ n + 1 ] = x [ n ] + 1 → x [ n + 2 ] − 2 x [ n + 1 ] + x [ n ] = 0 x [ n + 1 ] = 2 x [ n ] + 4 → x [ n + 2 ] − 3 x [ n + 1 ] + 2 x [ n ] = 0 where P h = ( S − θ 1 ) d 1 + 1 · · · ( S − θ s ) d s + 1 ⇓ P x = P h · ( S − α ) , P x · x = 0 P h · h = 0 x [ n + r ] = a n + r − 1 x [ n + r − 1 ] + · · · + a n x [ n ] , with r ≥ 1
Program Assignments and C-finite Recurrences x := α x + h − → x [ n + 1 ] = α x [ n ] + h ( n ) h ( n ) = n d 1 θ 1 + · · · + n d s θ n with s Example x [ n + 1 ] = x [ n ] + 1 → x [ n + 2 ] − 2 x [ n + 1 ] + x [ n ] = 0 x [ n + 1 ] = 2 x [ n ] + 4 → x [ n + 2 ] − 3 x [ n + 1 ] + 2 x [ n ] = 0 where P h = ( S − θ 1 ) d 1 + 1 · · · ( S − θ s ) d s + 1 ⇓ P x = P h · ( S − α ) , P x · x = 0 P h · h = 0 x [ n + r ] = a n + r − 1 x [ n + r − 1 ] + · · · + a n x [ n ] , with r ≥ 1
Program Assignments and C-finite Recurrences x := α x + h − → x [ n + 1 ] = α x [ n ] + h ( n ) h ( n ) = n d 1 θ 1 + · · · + n d s θ n with s Example x [ n + 1 ] = x [ n ] + 1 → x [ n + 2 ] − 2 x [ n + 1 ] + x [ n ] = 0 x [ n + 1 ] = 2 x [ n ] + 4 → x [ n + 2 ] − 3 x [ n + 1 ] + 2 x [ n ] = 0 where P h = ( S − θ 1 ) d 1 + 1 · · · ( S − θ s ) d s + 1 ⇓ P x = P h · ( S − α ) , P x · x = 0 P h · h = 0 x [ n + r ] = a n + r − 1 x [ n + r − 1 ] + · · · + a n x [ n ] , with r ≥ 1
Algebraic Dependencies Among Exponential Sequences Let θ 1 , . . . , θ s ∈ ¯ s ∈ ¯ K , and their exponential sequences θ n 1 , . . . , θ n 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 and θ 2 = 1 − 5 is: 2 2 � 2 ∗ � 2 − 1 = 0 ; � � θ n θ n 1 2 ◮ There is no algebraic dependency among the exponential sequences of θ 1 = 2 and θ 2 = 3 .
Algebraic Dependencies Among Exponential Sequences Let θ 1 , . . . , θ s ∈ ¯ s ∈ ¯ K , and their exponential sequences θ n 1 , . . . , θ n 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 and θ 2 = 1 − 5 is: 2 2 � 2 ∗ � 2 − 1 = 0 ; � � θ n θ n 1 2 ◮ There is no algebraic dependency among the exponential sequences of θ 1 = 2 and θ 2 = 3 .
Algebraic Dependencies Among Exponential Sequences Let θ 1 , . . . , θ s ∈ ¯ s ∈ ¯ K , and their exponential sequences θ n 1 , . . . , θ n 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 and θ 2 = 1 − 5 is: 2 2 � 2 ∗ � 2 − 1 = 0 ; � � θ n θ n 1 2 ◮ There is no algebraic dependency among the exponential sequences of θ 1 = 2 and θ 2 = 3 .
Algebraic Dependencies Among Exponential Sequences Let θ 1 , . . . , θ s ∈ ¯ s ∈ ¯ K , and their exponential sequences θ n 1 , . . . , θ n 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 and θ 2 = 1 − 5 is: 2 2 � 2 ∗ � 2 − 1 = 0 ; � � θ n θ n 1 2 ◮ There is no algebraic dependency among the exponential sequences of θ 1 = 2 and θ 2 = 3 .
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
Invariant Generation Algorithm Loop System of recurrence equations Symb.Summ. System of closed forms GB Polynomial Invariant Ideal
Invariant Generation Algorithm P-solvable Loop System of recurrence equations Symb.Summ. System of closed forms GB Polynomial Invariant Ideal
P-solvable Loops: while . . . do S end while The closed forms of the loop variables X = { x 1 , . . . , x m } : q 1 ( n , θ n 1 , . . . , θ n x 1 [ n ] = s ) . CF ( S n , E S , X , X 0 ) : . , . q m ( n , θ n 1 , . . . , θ n x m [ n ] = s ) with algebraic dependencies A = I ( n , θ n 1 , . . . , θ n s ) . Notations: 1. n ∈ N is the loop counter and S n denotes S ; . . . ; S ; � �� � n times 2. x i [ n ] is the value of x i at iteration n . X 0 are the initial values of loop variables before S n ; 3. q 1 , . . . , q m ∈ ¯ K [ n , θ n 1 , . . . , θ n s ] ; 4. θ 1 , . . . , θ s ∈ ¯ K , E S = { θ n 1 , . . . , θ n s } .
P-solvable Loops: while . . . do S end while The closed forms of the loop variables X = { x 1 , . . . , x m } : q 1 ( n , θ n 1 , . . . , θ n x 1 [ n ] = s ) . CF ( S n , E S , X , X 0 ) : . , . q m ( n , θ n 1 , . . . , θ n x m [ n ] = s ) with algebraic dependencies A = I ( n , θ n 1 , . . . , θ n s ) . Polynomial Invariant Ideal: I ( x 1 , . . . , x m ) . GB � x i − q i ( n , θ n 1 , . . . , θ n s ) � + A ∩ K [ x 1 , . . . , x m ] I ( x 1 , . . . , x m ) = S ∗ { p ( X ) = 0 ∧ X = X 0 } { p ( X ) = 0 }
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
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 ] . . . . . .
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 ] . . . . . .
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 ] . . . . . .
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 ] . . . . . .
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 ] . . . . . .
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 ] . . . . . .
Extracting and Solving Recurrences n ≥ 0 z := 0 ; y := 1 ; x := 1 / 2 ; x [ n + 1 ] x [ n ] / 2 C − finite = while . . . do y [ n + 1 ] y [ n ] + x [ n ] C − finite = z := 2 ∗ z − 2 ∗ y − x ; z [ n ] 2 ∗ z [ n ] − 2 ∗ y [ n ] − x [ n ] C − finite = y := y + x ; x := x / 2 end while 1 x [ n ] 2 n x [ 0 ] C − finite = 1 y [ n ] C − finite y [ 0 ] + 2 x [ 0 ] − 2 n − 1 x [ 0 ] = 2 n ( z [ 0 ] − 2 y [ 0 ] − 2 x [ 0 ]) − z [ n ] C − finite = 1 2 n − 1 x [ 0 ] + 2 y [ 0 ] + 4 x [ 0 ] Alg . Dep . =
Extracting and Solving Recurrences n ≥ 0 z := 0 ; y := 1 ; x := 1 / 2 ; x [ n + 1 ] x [ n ] / 2 C − finite = while . . . do y [ n + 1 ] y [ n ] + x [ n ] C − finite = z := 2 ∗ z − 2 ∗ y − x ; z [ n ] 2 ∗ z [ n ] − 2 ∗ y [ n ] − x [ n ] C − finite = y := y + x ; x := x / 2 end while 1 x [ n ] 2 n x [ 0 ] C − finite = 1 y [ n ] C − finite y [ 0 ] + 2 x [ 0 ] − 2 n − 1 x [ 0 ] = 2 n ( z [ 0 ] − 2 y [ 0 ] − 2 x [ 0 ]) − z [ n ] C − finite = 1 2 n − 1 x [ 0 ] + 2 y [ 0 ] + 4 x [ 0 ] Alg . Dep . =
Algebraic Dependencies and Variable Elimination a = 2 n , b = 2 − n n ≥ 0, z := 0 ; y := 1 ; x := 1 / 2 ; x b ∗ x [ 0 ] C − finite while [ . . . , = y y [ 0 ] + 2 ∗ x [ 0 ] − 2 ∗ b ∗ x [ 0 ] C − finite = z := 2 ∗ z − 2 ∗ y − x ; z C − finite a ∗ ( z [ 0 ] − 2 ∗ y [ 0 ] − 2 ∗ x [ 0 ]) − = y := y + x ; 2 ∗ b ∗ x [ 0 ] + 2 ∗ y [ 0 ] + 4 ∗ x [ 0 ] x := x / 2 ] 0 Alg . Dep . a ∗ b − 1 = P-solvable Loop
Algebraic Dependencies and Variable Elimination a = 2 n , b = 2 − n n ≥ 0, z := 0 ; y := 1 ; x := 1 / 2 ; x b ∗ x [ 0 ] C − finite while [ . . . , = y y [ 0 ] + 2 ∗ x [ 0 ] − 2 ∗ b ∗ x [ 0 ] C − finite = z := 2 ∗ z − 2 ∗ y − x ; z C − finite a ∗ ( z [ 0 ] − 2 ∗ y [ 0 ] − 2 ∗ x [ 0 ]) − = y := y + x ; 2 ∗ b ∗ x [ 0 ] + 2 ∗ y [ 0 ] + 4 ∗ x [ 0 ] x := x / 2 ] 0 Alg . Dep . a ∗ b − 1 = P-solvable Loop Polynomial Invariant (GB): � � � � y 2 − y ∗ z + 2 ∗ z ∗ x [ 0 ]+ z ∗ y [ 0 ] − y [ 0 ] 2 − 2 ∗ x [ 0 ] ∗ z [ 0 ] = 0 2 x + y − 2 x [ 0 ] − y [ 0 ] = 0 ∧
Algebraic Dependencies and Variable Elimination a = 2 n , b = 2 − n n ≥ 0, z := 0 ; y := 1 ; x := 1 / 2 ; x b ∗ x [ 0 ] C − finite while [ . . . , = y y [ 0 ] + 2 ∗ x [ 0 ] − 2 ∗ b ∗ x [ 0 ] C − finite = z := 2 ∗ z − 2 ∗ y − x ; z C − finite a ∗ ( z [ 0 ] − 2 ∗ y [ 0 ] − 2 ∗ x [ 0 ]) − = y := y + x ; 2 ∗ b ∗ x [ 0 ] + 2 ∗ y [ 0 ] + 4 ∗ x [ 0 ] x := x / 2 ] 0 Alg . Dep . a ∗ b − 1 = P-solvable Loop Polynomial Invariant (GB): � � � 2 ∗ z − y ∗ z + y 2 − 1 = 0 � 2 ∗ x + y − 2 = 0 ∧
Further Examples. i := 0 ; f := 1 ; g := 1 k := 0 ; j := 1 ; m := 1 ; while i < n do while m ≤ n do t := f ; f := f + g ; g := t k := k + 1 ; j := j + 2 ; m := m + j end while end while
Further Examples. (2) Fibonacci numbers (1) Integer square root: i := 0 ; f := 1 ; g := 1 k := 0 ; j := 1 ; m := 1 ; while i < n do while m ≤ n do t := f ; f := f + g ; g := t k := k + 1 ; j := j + 2 ; m := m + j end while end while
Further Examples. (2) Fibonacci numbers (1) Integer square root: i := 0 ; f := 1 ; g := 1 k := 0 ; j := 1 ; m := 1 ; while i < n do while m ≤ n do t := f ; f := f + g ; g := t k := k + 1 ; j := j + 2 ; m := m + j end while end while Invariant: Invariant: f 4 + g 4 + 2 f ∗ g 3 − 2 f 3 ∗ g − f 2 ∗ g 2 − 1 = 0 2 k + 1 = j ∧ 4 m = ( j + 1 ) 2
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
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 S 1 else S 2 ] → if [ . . . then S 1 else S 2 ] − → S 1 | S 2 ← while [ cond , S ] → while [ . . . , S ] − → S ∗ → ( S 1 | . . . | S k ) ∗ ← while [ . . . , if [ . . . , S 1 ]; . . . ; if [ . . . , S k ]] − ◮ Automated Loop Invariant Generation by Algebraic Techniques Over the Rationals for P-solvable loops: ( S 1 | . . . | S k ) ∗ ← { p ( X ) = 0 ∧ X = X 0 } { p ( X ) = 0 } ◮ Polynomial invariant ideal represented by Gr¨ obner bases;
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 S 1 else S 2 ] → if [ . . . then S 1 else S 2 ] − → S 1 | S 2 ← while [ cond , S ] → while [ . . . , S ] − → S ∗ → ( S 1 | . . . | S k ) ∗ ← while [ . . . , if [ . . . , S 1 ]; . . . ; if [ . . . , S k ]] − ◮ Automated Loop Invariant Generation by Algebraic Techniques Over the Rationals for P-solvable loops: ( S 1 | . . . | S k ) ∗ ← { p ( X ) = 0 ∧ X = X 0 } { p ( X ) = 0 } ◮ Polynomial invariant ideal represented by Gr¨ obner bases;
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 S 1 else S 2 ] → if [ . . . then S 1 else S 2 ] − → S 1 | S 2 ← while [ cond , S ] → while [ . . . , S ] − → S ∗ → ( S 1 | . . . | S k ) ∗ ← while [ . . . , if [ . . . , S 1 ]; . . . ; if [ . . . , S k ]] − ◮ Automated Loop Invariant Generation by Algebraic Techniques Over the Rationals for P-solvable loops: ( S 1 | . . . | S k ) ∗ ← { p ( X ) = 0 ∧ X = X 0 } { p ( X ) = 0 } ◮ Polynomial invariant ideal represented by Gr¨ obner bases;
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 S 1 else S 2 ] → if [ . . . then S 1 else S 2 ] − → S 1 | S 2 ← while [ b , S ] → while [ . . . , S ] − → S ∗ ← while [ . . . , if [ . . . , S 1 ]; . . . ; if [ . . . , S k ]] − → ( S 1 | . . . | S k ) ∗ ◮ A utomated L oop I nvariant G eneration by A lgebraic T echniques O ver the R ationals for P-solvable loops: ( S 1 | . . . | S k ) ∗ ← { p ( X ) = 0 ∧ X = X 0 } { p ( X ) = 0 } ◮ Polynomial invariant ideal represented by Gr¨ obner bases; ◮ Implementation: ALIGATOR → programs working on numbers.
RECAP – P-solvable Loop S ∗ with Assignments Only Values of loop variables X = { x 1 , . . . , x m } at loop iteration n ∈ N : q 1 ( n , θ n 1 , . . . , θ n x 1 [ n ] = s ) . S n ≡ S ; . . . ; S . : , . � �� � q m ( n , θ n 1 , . . . , θ n x m [ n ] = s ) n times with algebraic dependencies: s ) = 0 , ∀ n ∈ N � � ¯ A = I ( n , θ n 1 , . . . , θ n s ) = � r | r ( n , θ n 1 , . . . , θ n K [ n , θ n 1 , . . . , θ n s ]
RECAP – P-solvable Loop S ∗ with Assignments Only Values of loop variables X = { x 1 , . . . , x m } at loop iteration n ∈ N : q 1 ( n , θ n 1 , . . . , θ n x 1 [ n ] = s ) . S n ≡ S ; . . . ; S . : , . � �� � q m ( n , θ n 1 , . . . , θ n x m [ n ] = s ) n times with algebraic dependencies: s ) = 0 , ∀ n ∈ N � � ¯ A = I ( n , θ n 1 , . . . , θ n s ) = � r | r ( n , θ n 1 , . . . , θ n K [ n , θ n 1 , . . . , θ n s ] Examples. • I ( n , 2 n , 4 n ) = � ( 2 n ) 2 − 4 n � • I ( n , 2 n , 2 − n ) = � ( 2 n ) ∗ ( 2 − n ) − 1 � • I ( n , 2 n , 3 n ) = ∅ √ √ √ n � 2 ∗ √ n � 2 − 1 � n , 1 − n ) = � � 1 + � 1 − • I ( n , 1 + 5 5 5 5 2 2 2 2
RECAP – P-solvable Loop S ∗ with Assignments Only Values of loop variables X = { x 1 , . . . , x m } at loop iteration n ∈ N : q 1 ( n , θ n 1 , . . . , θ n x 1 [ n ] = s ) . S n ≡ S ; . . . ; S . : , . � �� � q m ( n , θ n 1 , . . . , θ n x m [ n ] = s ) n times with algebraic dependencies: s ) = 0 , ∀ n ∈ N � � ¯ A = I ( n , θ n 1 , . . . , θ n s ) = � r | r ( n , θ n 1 , . . . , θ n K [ n , θ n 1 , . . . , θ n s ] Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) = � x i − q i � + A ∩ K [ x 1 , . . . , x m ] { p ( X ) = 0 ∧ X = X 0 } S ∗ { p ( X ) = 0 }
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m )
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) { p ( X ) = 0 ∧ X = X 0 } ( S 1 | . . . | S k ) ∗ { p ( X ) = 0 }
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) { p ( X ) = 0 ∧ X = X 0 } ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ { p ( X ) = 0 }
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) { p ( X ) = 0 ∧ X = X 0 } ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ { p ( X ) = 0 } First algorithmic attempt: ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ S ∗ 1 ∗ · · · ∗ S ∗ S ∗ 1 ; . . . ; S ∗ ← ��� k k � �� � � �� � � �� � ONE iteration loop sequence arbitrary MANY iterations PI 0 = � I k ⊆ I ∗ I k
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) { p ( X ) = 0 ∧ X = X 0 } ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ { p ( X ) = 0 } Idea of the algorithm: ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S ∗ 1 ∗ · · · ∗ S ∗ k ); S ∗ S ∗ 1 ∗ · · · ∗ S ∗ ← . . . ← ← i k � �� � � �� � � �� � ONE iteration arbitrary MANY iterations TWO iterations PI 0 = � I k PI 1 = � I k + 1 ⊆ . . . ⊆ ⊆ I ∗
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) { p ( X ) = 0 ∧ X = X 0 } ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ { p ( X ) = 0 } Idea of the algorithm: ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S ∗ 1 ∗ · · · ∗ S ∗ k ); S ∗ S ∗ 1 ∗ · · · ∗ S ∗ ← . . . ← ← i k � �� � � �� � � �� � ONE iteration arbitrary MANY iterations TWO iterations PI 0 = � I k PI 1 = � I k + 1 ⊆ . . . ⊆ ⊆ I ∗ Termination? Not guaranteed for arbitrary ideals!
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ P-solvable loop ( S 1 | . . . | S k ) ∗ ⇐ ⇒ P-solvable inner loops S ∗ i ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S 1 | . . . | S k ) ∗ is equivalent to ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ Polynomial Invariant Ideal: I ∗ = I ( x 1 , . . . , x m ) { p ( X ) = 0 ∧ X = X 0 } ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ { p ( X ) = 0 } Idea of the algorithm: ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S ∗ 1 ∗ · · · ∗ S ∗ k ); S ∗ S ∗ 1 ∗ · · · ∗ S ∗ ← . . . ← ← i k � �� � � �� � � �� � ONE iteration arbitrary MANY iterations TWO iterations PI 0 = � I k PI 1 = � I k + 1 ⊆ . . . ⊆ ⊆ I ∗ Termination? Always terminates!
P-solvable Loops with Conditionals ( S 1 | . . . | S k ) ∗ Program Algorithm � while . . . , l = k , L l = Perm [ 1 , . . . , k ] � I k PI = p | { p ( X ) = 0 ∧ X = X 0 } S ∗ w 1 ; . . . ; S ∗ Il = � wl { p ( X ) = 0 } � , ( w 1 , . . . , wl ) ∈ Ll if [ . . . , S 1 ]; repeat . . PI ′ = PI . k � L l ◦ S i , L l + 1 = l = l + 1 i = 1 � � I l if [ . . . , S k ] PI = p |{ p ( X ) = 0 ∧ X = X 0 } S ∗ w 1 ; . . . ; S ∗ Il = � wl ; { p ( X ) = 0 } � , ( w 1 , . . . , wl ) ∈ Ll until PI = PI ′ = I ∗ Idea of the algorithm: ( S ∗ 1 ∗ · · · ∗ S ∗ k ) ∗ ( S ∗ 1 ∗ · · · ∗ S ∗ k ); S ∗ S ∗ 1 ∗ · · · ∗ S ∗ ← . . . ← ← i k � �� � � �� � � �� � ONE iteration arbitrary MANY iterations TWO iterations PI 0 = � I k PI 1 = � I k + 1 ⊆ . . . ⊆ ⊆ I ∗ Termination? Always terminates!
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 | b := b − a ; q := q − p ; s := s − r � �� � � �� � S 1 S 2 Step 0: PI 0 = � 18 polynomials � = Step 1: PI 1 = � b − qx − sy , br − as + x , qr − ps + 1 , px + ry − a , bp − aq − y � Step 2: PI 2 = � b − qx − sy , br − as + x , qr − ps + 1 , px + ry − a , bp − aq − y � PI 1 = PI 2 = I ∗
Recommend
More recommend