Decision Procedures and Verifjcation
NAIL094 Petr Kučera
Charles University
2019/20 (11th lecture)
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 1 / 39
Decision Procedures and Verifjcation NAIL094 Petr Kuera Charles - - PowerPoint PPT Presentation
Decision Procedures and Verifjcation NAIL094 Petr Kuera Charles University 2019/20 (11th lecture) Petr Kuera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 1 / 39 Arrays Motivation 7 2019/20 (11th
Charles University
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 1 / 39
1
int a[100];
2
for(int i=0; i<100; ++i) {
3
assert((∀j ∈ )[j < i → a[j] = 0]);
4
a[i]=0;
5
assert((∀j ∈ )[j ≤ i → a[j] = 0]);
6
}
7
assert((∀j ∈ )[j ≤ 99 → a[j] = 0]);
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 3 / 39
1
int a[100];
2
for(int i=0; i<100; ++i) {
3
assert((∀j ∈ )[j < i → a[j] = 0]);
4
a[i]=0;
5
assert((∀j ∈ )[j ≤ i → a[j] = 0]);
6
}
7
assert((∀j ∈ )[j ≤ 99 → a[j] = 0]);
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 3 / 39
1
int a[100];
2
for(int i=0; i<100; ++i) {
3
assert((∀j ∈ )[j < i → a[j] = 0]);
4
a[i]=0;
5
assert((∀j ∈ )[j ≤ i → a[j] = 0]);
6
}
7
assert((∀j ∈ )[j ≤ 99 → a[j] = 0]);
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 3 / 39
1
int a[100];
2
for(int i=0; i<100; ++i) {
3
assert((∀j ∈ )[j < i → a[j] = 0]);
4
a[i]=0;
5
assert((∀j ∈ )[j ≤ i → a[j] = 0]);
6
}
7
assert((∀j ∈ )[j ≤ 99 → a[j] = 0]);
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 3 / 39
Also used to model memory in hardware
Should allow quantifjcation e.g. linear arithmetic over integers (Presburger) with quantifjcation
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 4 / 39
Also used to model memory in hardware
Should allow quantifjcation e.g. linear arithmetic over integers (Presburger) with quantifjcation
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 4 / 39
Also used to model memory in hardware
Should allow quantifjcation e.g. linear arithmetic over integers (Presburger) with quantifjcation
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 4 / 39
Also used to model memory in hardware
Should allow quantifjcation e.g. linear arithmetic over integers (Presburger) with quantifjcation
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 4 / 39
Also used to model memory in hardware
Should allow quantifjcation e.g. linear arithmetic over integers (Presburger) with quantifjcation
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 4 / 39
Also used to model memory in hardware
Should allow quantifjcation e.g. linear arithmetic over integers (Presburger) with quantifjcation
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 4 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 5 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 5 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 6 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 7 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 7 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 7 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Functional consistency captures the array consistency
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 8 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 9 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 9 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 9 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 10 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 10 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 10 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 10 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 11 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 11 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 11 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 11 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 12 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 12 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 12 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 12 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 12 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 13 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 14 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 15 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 15 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 15 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 16 / 39
Step 1 Convert ϕ to NNF Step 2 Remove write terms using write rule Step 3 Replace each existential quantifjer (∃j)[ψ(j)] with ψ(k)
Step 4 Reduce universal quantifjcation to fjnite conjunction Step 5 Replace array read terms by uninterpreted functions Step 6 Decide the resulting (quantifjer-free) formula in index and
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 17 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 18 / 39
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
inequality is not allowed in the index guard
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 19 / 39
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
inequality is not allowed in the index guard
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 19 / 39
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
inequality is not allowed in the index guard
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 19 / 39
1 a′[i] = e for the written value 2 (∀j ≠ i)[a′[j] = a[j]] for the unchanged values
inequality is not allowed in the index guard
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 19 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 20 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 21 / 39
1 Add all expressions used as an array index in
that are not quantifjed variables
2 Add all expressions used inside index guards in
that are not quantifjed variables
3 If
contains none of the above, is in order to obtain a nonempty set of index expressions
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
1 Add all expressions used as an array index in
that are not quantifjed variables
2 Add all expressions used inside index guards in
that are not quantifjed variables
3 If
contains none of the above, is in order to obtain a nonempty set of index expressions
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
1 Add all expressions used as an array index in ϕ that are not
quantifjed variables
2 Add all expressions used inside index guards in
that are not quantifjed variables
3 If
contains none of the above, is in order to obtain a nonempty set of index expressions
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
1 Add all expressions used as an array index in ϕ that are not
quantifjed variables
2 Add all expressions used inside index guards in ϕ that are not
quantifjed variables
3 If
contains none of the above, is in order to obtain a nonempty set of index expressions
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
1 Add all expressions used as an array index in ϕ that are not
quantifjed variables
2 Add all expressions used inside index guards in ϕ that are not
quantifjed variables
3 If ϕ contains none of the above, I is {0} in order to obtain a
nonempty set of index expressions
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
1 Add all expressions used as an array index in ϕ that are not
quantifjed variables
2 Add all expressions used inside index guards in ϕ that are not
quantifjed variables
3 If ϕ contains none of the above, I is {0} in order to obtain a
nonempty set of index expressions
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
1 Add all expressions used as an array index in ϕ that are not
quantifjed variables
2 Add all expressions used inside index guards in ϕ that are not
quantifjed variables
3 If ϕ contains none of the above, I is {0} in order to obtain a
nonempty set of index expressions
i∈I(ϕ)
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 22 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 23 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 23 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 23 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 23 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 24 / 39
contradiction
contradiction
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 25 / 39
contradiction
contradiction
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 25 / 39
contradiction
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 25 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 25 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 25 / 39
We need to argue only about indices and the array sizes
Useful for using as part of DPLL(T).
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 26 / 39
1
int a[10];
2
int i;
3 4
void array_sum(int *sum) {
5
*sum=0;
6
for(i=0; i<10; ++i) {
7
*sum+=a[i];
8
}
9
}
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 28 / 39
1
int a[10];
2
int i;
3 4
void array_sum(int *sum) {
5
*sum=0;
6
for(i=0; i<10; ++i) {
7
*sum+=a[i];
8
}
9
}
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 28 / 39
1
int a[10];
2
int i;
3 4
void array_sum(int *sum) {
5
*sum=0;
6
for(i=0; i<10; ++i) {
7
*sum+=a[i];
8
}
9
}
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 28 / 39
1
int a[10];
2
int i;
3 4
void array_sum(int *sum) {
5
*sum=0;
6
for(i=0; i<10; ++i) {
7
*sum+=a[i];
8
}
9
}
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 28 / 39
1
int *p, *q; // uninitialized pointer variables
2
p=new int[10]; // p points to a newly allocated array
3
q=&p[3]; // p points to the 3rd element of p
4
delete[] p; // array p is released
5
*q=2; // accessing the 3rd element of array p
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 29 / 39
1
int *p, *q; // uninitialized pointer variables
2
p=new int[10]; // p points to a newly allocated array
3
q=&p[3]; // p points to the 3rd element of p
4
delete[] p; // array p is released
5
*q=2; // accessing the 3rd element of array p
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 29 / 39
1
int *p, *q; // uninitialized pointer variables
2
p=new int[10]; // p points to a newly allocated array
3
q=&p[3]; // p points to the 3rd element of p
4
delete[] p; // array p is released
5
*q=2; // accessing the 3rd element of array p
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 29 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 30 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 30 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 30 / 39
1
int var_a, var_b, var_c;
2
struct { int x; int y; } S;
3
int array[4];
4
int *p=&var_c;
5 6
int main() {
7
*p=100; // var_c=100
8
}
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 31 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 32 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 32 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 32 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 32 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 33 / 39
pointers can be wider
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 34 / 39
treated as array types
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 35 / 39
treated as array types
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 35 / 39
treated as array types
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 35 / 39
treated as array types
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 35 / 39
treated as array types
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 35 / 39
treated as array types
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 35 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 36 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 37 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 37 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 37 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 37 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 37 / 39
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 37 / 39
1 Given a formula
in simple pointer logic
2 Compute 3 Use decision procedure for data words logic with arrays to decide
satisfjability
linear arithmetic over integers + arrays bit vectors + arrays
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 38 / 39
1 Given a formula ϕ in simple pointer logic 2 Compute ψ = ϕ 3 Use decision procedure for data words logic with arrays to decide
satisfjability ψ
linear arithmetic over integers + arrays bit vectors + arrays
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 38 / 39
1 Given a formula ϕ in simple pointer logic 2 Compute ψ = ϕ 3 Use decision procedure for data words logic with arrays to decide
satisfjability ψ
linear arithmetic over integers + arrays bit vectors + arrays
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 38 / 39
No variable has address NULL No two difgerent variables and have overlapping memory Naturally generalizes to a situation where and span more than a single data word
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 39 / 39
No variable x has address 0 &x ≠ NULL No two difgerent variables and have overlapping memory Naturally generalizes to a situation where and span more than a single data word
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 39 / 39
No variable x has address 0 &x ≠ NULL No two difgerent variables x and y have overlapping memory x ≠ y ⇒ &x ≠ &y Naturally generalizes to a situation where and span more than a single data word
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 39 / 39
No variable x has address 0 &x ≠ NULL No two difgerent variables x and y have overlapping memory x ≠ y ⇒ &x ≠ &y Naturally generalizes to a situation where x and y span more than a single data word
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 39 / 39
No variable x has address 0 &x ≠ NULL No two difgerent variables x and y have overlapping memory x ≠ y ⇒ &x ≠ &y Naturally generalizes to a situation where x and y span more than a single data word
Petr Kučera (Charles University) Decision Procedures and Verifjcation 2019/20 (11th lecture) 39 / 39