verifying array manipulating programs by tiling
play

Verifying Array Manipulating Programs by Tiling Authors: Supratik - PowerPoint PPT Presentation

Verifying Array Manipulating Programs by Tiling Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh Unadkat R Venkatesh TCS Research December 11-16, 2017 Winter School in Software Engineering Pune, India Authors: Supratik Chakraborty,


  1. Verifying Array Manipulating Programs by Tiling Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh Unadkat R Venkatesh TCS Research December 11-16, 2017 Winter School in Software Engineering Pune, India Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 1 / 31

  2. Verification by Tiling Verifying array programs with complex access patterns is challenging State-of-the-art tools choke on many such examples Solution - Inductive Compositional Reasoning ◮ Infer array access patterns in loops ◮ Tile the set of indices using the inferred patterns ◮ Slice the assertion using the tile for a single iteration of the loop ◮ Compositionally prove universally quantified assertions on arrays Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 2 / 31

  3. Motivating Example void foo(int A[], int N) { for (int i = 0; i < N; i++) { if(!(i==0 || i==N-1)) { if (A[i] < THRESH) { A[i+1] = A[i] + 1; A[i] = A[i-1]; } } else { A[i] = THRESH; } } assert(for i in 0..N-1, A[i]>=THRESH); } Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 3 / 31

  4. Motivating Example void foo(int A[], int N) { for (int i = 0; i < N; i++) { if(!(i==0 || i==N-1)) { if (A[i] < 5) { A[i+1] = A[i] + 1; A[i] = A[i-1]; } } else { A[i] = 5; } } assert(for k in 0..N-1, A[k]>=5); } Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 3 / 31

  5. Motivating Example void foo(int A[], int N) { for (int i = 0; i < N; i++) { if(!(i==0 || i==N-1)) { if (A[i] < 5) { A[i+1] = A[i] + 1; A[i] = A[i-1]; } } else { A[i] = 5; } } assert(for k in 0..N-1, A[k]>=5); } Initial array Loop Counter 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 Indices 5 9 7 1 9 2 8 1 Cell Contents ¬∀ k . a [ k ] ≥ 5 Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 3 / 31

  6. Motivating Example void foo(int A[], int N) { 0 1 2 3 4 5 6 7 for (int i = 0; i < N; i++) { if(!(i==0 || i==N-1)) { 0 1 2 3 4 5 6 7 if (A[i] < 5) { 5 9 7 7 2 2 8 1 A[i+1] = A[i] + 1; A[i] = A[i-1]; i i + 1 } } else { 0 1 2 3 4 5 6 7 A[i] = 5; 0 1 2 3 4 5 6 7 } } 5 9 7 7 7 3 8 1 assert(for k in 0..N-1, A[k]>=5); } i i + 1 Initial array 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 1 9 2 8 1 5 9 7 7 7 7 4 1 ¬∀ k . a [ k ] ≥ 5 i i + 1 Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 3 / 31

  7. Motivating Example void foo(int A[], int N) { 0 1 2 3 4 5 6 7 for (int i = 0; i < N; i++) { 0 1 2 3 4 5 6 7 if(!(i==0 || i==N-1)) { if (A[i] < 5) { 5 9 7 7 2 2 8 1 A[i+1] = A[i] + 1; A[i] = A[i-1]; a [ i + 1 ] �≥ 5 } } else { 0 1 2 3 4 5 6 7 A[i] = 5; 0 1 2 3 4 5 6 7 } } 5 9 7 7 7 3 8 1 assert(for k in 0..N-1, A[k]>=5); } a [ i + 1 ] �≥ 5 Initial array 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 1 9 2 8 1 5 9 7 7 7 7 4 1 ¬∀ k . a [ k ] ≥ 5 a [ i + 1 ] �≥ 5 Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 3 / 31

  8. Motivating Example void foo(int A[], int N) { 0 1 2 3 4 5 6 7 for (int i = 0; i < N; i++) { if(!(i==0 || i==N-1)) { 0 1 2 3 4 5 6 7 if (A[i] < 5) { 5 9 7 7 2 2 8 1 A[i+1] = A[i] + 1; A[i] = A[i-1]; i } } else { 0 1 2 3 4 5 6 7 A[i] = 5; 0 1 2 3 4 5 6 7 } } 5 9 7 7 7 3 8 1 assert(for k in 0..N-1, A[k]>=5); } i Initial array 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 1 9 2 8 1 5 9 7 7 7 7 4 1 ¬∀ k . a [ k ] ≥ 5 i Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 3 / 31

  9. Tiling Tile : LoopCounter × Indices → { tt , ff } for loop L Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 4 / 31

  10. Tiling Tile : LoopCounter × Indices → { tt , ff } for loop L Tile ( i , j ) := i ≤ j ≤ i + 1 Tile ( i , j ) := j == i Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 4 / 31

  11. Tiling Tile : LoopCounter × Indices → { tt , ff } for loop L Tile ( i , j ) := i ≤ j ≤ i + 1 Tile ( i , j ) := j == i 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 7 7 3 8 1 5 9 7 7 7 3 8 1 a [ 5 ] �≥ 5 a [ 4 ] ≥ 5 Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 4 / 31

  12. Tiling Tile : LoopCounter × Indices → { tt , ff } for loop L Tile ( i , j ) := i ≤ j ≤ i + 1 Tile ( i , j ) := j == i 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 7 7 3 8 1 5 9 7 7 7 3 8 1 a [ 5 ] �≥ 5 a [ 4 ] ≥ 5 Truth of the assertion wrt tile Truth of the assertion wrt tile changes in the next iteration doesn’t change in the future Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 4 / 31

  13. Tiling Tile : LoopCounter × Indices → { tt , ff } for loop L Tile ( i , j ) := i ≤ j ≤ i + 1 Tile ( i , j ) := j == i 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 7 7 3 8 1 5 9 7 7 7 3 8 1 a [ 5 ] �≥ 5 a [ 4 ] ≥ 5 Truth of the assertion wrt tile Truth of the assertion wrt tile changes in the next iteration doesn’t change in the future May miss update to some Doesn’t miss updates to any indices index Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 4 / 31

  14. Tiling Tile : LoopCounter × Indices → { tt , ff } for loop L Tile ( i , j ) := i ≤ j ≤ i + 1 Tile ( i , j ) := j == i 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 5 9 7 7 7 3 8 1 5 9 7 7 7 3 8 1 a [ 5 ] �≥ 5 a [ 4 ] ≥ 5 Truth of the assertion wrt tile Truth of the assertion wrt tile changes in the next iteration doesn’t change in the future May miss update to some Doesn’t miss updates to any indices index Finding the right tile is a challenge! Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 4 / 31

  15. Battery Voltage Regulator void BVR(int N, int MIN) volArray[i*4-2] = 0; { if(7 >= MIN) int i; volArray[i*4-3] = 7; int volArray[N]; else volArray[i*4-3] = 0; if(N % 4 != 0) { return; } if(5 >= MIN) volArray[i*4-4] = 5; assume(N % 4 == 0); else for(i = 1; i <= N/4; i++) volArray[i*4-4] = 0; { } if(1 >= MIN) volArray[i*4-1] = 1; for(i = 0; i < N; i++) else { volArray[i*4-1] = 0; assert(volArray[i] >= MIN || if(3 >= MIN) volArray[i] == 0); volArray[i*4-2] = 3; } else } Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 5 / 31

  16. Battery Voltage Regulator void BVR(int N, int MIN) volArray[i*4-2] = 0; { if(7 >= MIN) int i; volArray[i*4-3] = 7; int volArray[N]; else volArray[i*4-3] = 0; if(N % 4 != 0) { return; } if(5 >= MIN) volArray[i*4-4] = 5; assume(N % 4 == 0); else for(i = 1; i <= N/4; i++) volArray[i*4-4] = 0; { } if(1 >= MIN) volArray[i*4-1] = 1; for(i = 0; i < N; i++) else { volArray[i*4-1] = 0; assert(volArray[i] >= MIN || if(3 >= MIN) volArray[i] == 0); volArray[i*4-2] = 3; } else } Tile ( i , j ) := 4 ∗ i − 4 ≤ j < 4 ∗ i Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 5 / 31

  17. Array Reversal void revcopynswap(int N) for(i = 0; i < N; i++) { { int i; tmp = a[i]; int tmp; a[i] = b[i]; int a[N]; b[i] = tmp; int b[N]; } int rev_copy[N]; for(i = 0; i < N; i++) for(i = 0; i < N; i++) { { assert(b[i] == rev_copy[N-i-1]); rev_copy[N-i-1] = a[i]; } } } Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 6 / 31

  18. Array Reversal void revcopynswap(int N) for(i = 0; i < N; i++) { { int i; tmp = a[i]; int tmp; a[i] = b[i]; int a[N]; b[i] = tmp; int b[N]; } int rev_copy[N]; for(i = 0; i < N; i++) for(i = 0; i < N; i++) { { assert(b[i] == rev_copy[N-i-1]); rev_copy[N-i-1] = a[i]; } } } Loop 1 - Tile ( i , j ) := j == N − i − 1 Loop 2 - Tile ( i , j ) := j == i Authors: Supratik Chakraborty, Ashutosh Gupta, Divyesh UnadkatR Venkatesh TCS Research Verifying Array Manipulating Programs by Tiling 6 / 31

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend