-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ac565b
commit 981bb5c
Showing
50 changed files
with
2,374 additions
and
2,000 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
symbolic $a:array<int>; | ||
a = $a; | ||
assume a.size() < 2; | ||
min = a[0]; | ||
i = 1; | ||
while (i < a.size()) | ||
invariant a | ||
invariant b | ||
invariant c | ||
modifies i | ||
{ | ||
if (a[i] < min) min = a[i]; | ||
i = i+1; | ||
|
||
assert d; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plateau(a: array<int>) | ||
requires forall i:int :: 0 <= i && i < a.size() - 1 ==> a[i] <= a[i+1] | ||
ensures (forall k:int :: forall l:int :: 0 <= k && k <= l && l < a.size() && a[k] == a[l] ==> (l-k) <= result) | ||
{ | ||
lg = 1; | ||
i = 1; | ||
while (i < a.size()) | ||
invariant (forall k:int :: forall l:int :: | ||
0 <= k && k <= l && l < i && a[k] == a[l] | ||
==> | ||
(l-k) <= lg) | ||
modifies lg | ||
{ | ||
if (a[i] == a[i - lg]) lg = lg+1; | ||
i = i + 1; | ||
} | ||
} | ||
|
||
symbolic $a: array<int>; | ||
a = $a; | ||
assume a.size() < 4; | ||
assume forall i:int :: 0 <= i && i < a.size()-1 ==> a[i] <= a[i+1]; | ||
x = plateau(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
plateau(a: array<int>) : int | ||
requires forall i:int :: 0 <= i && i < a.size()-1 ==> a[i] <= a[i+1] | ||
ensures (forall k:int :: forall l:int :: | ||
0 <= k && k <= l && l < a.size() && a[k] == a[l] | ||
==> | ||
(l-k) <= result) | ||
{ | ||
lg = 1; | ||
i = 1; | ||
while (i < a.size()) | ||
invariant (forall k:int :: forall l:int :: | ||
0 <= k && k <= l && l < i && a[k] == a[l] | ||
==> | ||
(l-k) <= lg) | ||
modifies lg | ||
{ | ||
if (a[i] == a[i - lg]) lg = lg+1; | ||
i = i + 1; | ||
} | ||
return lg; | ||
} | ||
|
||
symbolic $a: array<int>; | ||
a = $a; | ||
//assume a.size() < 4; | ||
assume forall i:int :: 0 <= i && i < a.size()-1 ==> a[i] <= a[i+1]; | ||
//x = plateau(a); | ||
for (i = 0; i < 4; ++i) | ||
{ | ||
havoc a; | ||
assume a.size() == i; | ||
x[i] = plateau(a); | ||
} | ||
|
||
assert x[0] <= x[1] && x[1] <= x[2] && x[2] <= x[3]; | ||
|
||
Internal error [0:0] | ||
Unknown Z3 check! [5:3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
symbolic $n: int; | ||
n = $n; | ||
sum = 0; | ||
i = 1; | ||
|
||
while (i <= n) | ||
invariant sum == (i-1)*i/2 | ||
{ | ||
sum = sum + i; | ||
i = i + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
alg12(a: array<int>) : int | ||
{ | ||
lg = 1; | ||
i = 1; | ||
while (i < a.size()) | ||
{ | ||
if (a[i] == a[i - lg]) lg = lg+1; | ||
i = i + 1; | ||
} | ||
return lg; | ||
} | ||
|
||
symbolic $a: array<int>; | ||
a = $a; | ||
assume forall i:int :: 0 <= i && i < a.size()-1 ==> a[i] <= a[i+1]; | ||
assume a.size() == 3; | ||
|
||
x = alg12(a); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
askIth(out a:array<int>, i:int) : int | ||
requires a.size() > 0 && 0 <= i && i < a.size()-1 | ||
ensures a[i] <= a[i+1] | ||
ensures result > 0 ==> result == i | ||
{ | ||
if (a[i] > a[i+1]) { | ||
temp = a[i]; | ||
a[i] = a[i+1]; | ||
a[i+1] = temp; | ||
return i; | ||
} | ||
return 0; | ||
} | ||
|
||
sorted(out a) { | ||
return forall j:int :: forall k:int :: | ||
0 <= j && j <= last && last < k && | ||
k < a.size() ==> a[j] <= a[k]; | ||
} | ||
|
||
bubbleSort(out a: array<int>) { | ||
last = a.size()-1; | ||
while (last > 0) | ||
invariant sorted(a) | ||
{ | ||
n1 = last; | ||
i = 0; | ||
while (i < n1) | ||
invariant forall j:int :: | ||
0 <= j && j < i ==> a[j] <= a[i] | ||
{ | ||
last = askIth(a, i); | ||
i = i + 1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
@symbolic $a: array<int>; | ||
a = $a; | ||
@assume forall i:int :: 0 <= i && i < a.size()-1 ==> a[i] <= a[i+1]; | ||
slp = 1; | ||
i = 1; | ||
while (i < a.size()) | ||
@invariant i <= a.size() | ||
@invariant (forall k:int :: forall l:int :: | ||
0 <= k && k <= l && l < i && a[k] == a[l] | ||
==> | ||
(l-k) <= slp) | ||
@modifies slp | ||
@modifies i | ||
{ | ||
if (a[i] == a[i - slp]) slp = slp+1; | ||
i = i + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@symbolic $a: array<int>; | ||
a = $a; | ||
@assume forall i:int :: 0 <= i && i < a.size()-1 ==> a[i] <= a[i+1]; | ||
slp = 1; | ||
i = 1; | ||
while (i < a.size()) | ||
@invariant slp <= i | ||
@invariant (forall k:int :: forall l:int :: | ||
0 <= k && k <= l && l < i && a[k] == a[l] | ||
==> | ||
(l-k) <= slp) | ||
@modifies slp, i | ||
{ | ||
if (a[i] == a[i - slp]) slp = slp+1; | ||
i = i + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,7 @@ | ||
a = { "a" |-> 5 }; | ||
|
||
{} x = a.keys() | ||
|
||
// map-uri (keys) | ||
// invariantii trebuie procesati intr-o singura executie (nu o executie pentru fiecare invariant) | ||
|
||
// apel conditional la Z3 (-pr) | ||
// dataflow -> cautare secventiala si minim in tablou | ||
// conversia structurilor si a map-urilor in Z3 | ||
|
||
// redenumit keyword-urile assert, assume, requires, ensures, symbolic, modifies -> @ | ||
// operatorul : pentru apartenenta la un tip de date: | ||
// @requires a : array<int> && x : int; -> din gramatica | ||
// @ensures result : int; -> din gramatica | ||
// type assertions | ||
// @Trusted | ||
@symbolic $a : array<int>, $i : int; | ||
a = $a; | ||
@assume a.size() == 8; | ||
a.pushFront($i); | ||
@assert a.topFront() == $i; | ||
b = $a; | ||
@assert b.topFront() == b[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
a = [1, 2, 3, 4, 5]; | ||
i = 0; | ||
minim = a[0]; | ||
// map-urile au fost rezolvate | ||
|
||
while (i < a.size()) | ||
// invariant i <= a.size() | ||
// invariant forall j : int :: 0 <= j && j < i ==> minim <= a[j] | ||
// modifies i, minim | ||
{ | ||
if (a[i] < minim) | ||
{ | ||
minim = a[i]; | ||
} | ||
i++; | ||
} | ||
|
||
// putem pune in orice ordine modifies, invariant !!!!!!!! nu se poate o lista | ||
// am formatat path condition -> de adaugat Type Constraints | ||
|
||
// functiile ce nu au ensures, nu sunt verificate | ||
// rezolvat problema cu bracket cand ambele valori sunt concrete dar array-ul are valori simbolice | ||
// rezolvat cazul cu UNKNOWN -> unkown Z3 check | ||
// tratat cazul in care nu se defineste tipul de return | ||
// tratat cazul in care avem result dar nu avem return | ||
// invariant poate fi valoare concreta booleana | ||
// invariantii sunt verificati intr-un singur thread | ||
// am adaugat optiunea -prover pentru a specifica proverul | ||
|
||
// executia simbolica a functiilor "predicat" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
Can't use return outside function scope. | ||
a |-> $a_0 | ||
[result] |-> $minim_0 | ||
minim |-> $minim_0 | ||
i |-> $i_0 | ||
j |-> $j_1 | ||
|
||
Note that the execution was symbolic. | ||
Path condition: ($i_0<=$a_0.size()) && forall $j_1 : int :: ((0<=$j_1)&&($j_1<$i_0)) ==> ($minim_0<=$a_0[$j_1]) && !($i_0<$a_0.size()) ($j_0 : int, $i_0 : int, $j_1 : int, $minim_0 : int, $a_0 : array<int>) | ||
|
||
Can't use return outside function scope. | ||
a |-> $a_0 | ||
[result] |-> $minim_0 | ||
minim |-> $minim_0 | ||
i |-> $i_0 | ||
j |-> $j_1 | ||
|
||
Note that the execution was symbolic. | ||
Path condition: ($i_0<=$a_0.size()) && forall $j_1 : int :: ((0<=$j_1)&&($j_1<$i_0)) ==> ($minim_0<=$a_0[$j_1]) && !($i_0<$a_0.size()) ($j_0 : int, $i_0 : int, $j_1 : int, $minim_0 : int, $a_0 : array<int>) | ||
|
||
Successfully verified: findMin | ||
a |-> $a | ||
slp |-> $slp_0 | ||
i |-> $i_1 | ||
|
||
Note that the execution was symbolic. | ||
Path condition: forall $j_4 : int :: ((0<=$j_4)&&($j_4<$a.size())) ==> ($[result]_0<=$a[$j_4]) && exists $j_5 : int :: ((0<=$j_5)&&($j_5<$a.size())) ==> ($[result]_0==$a[$j_5]) ($[result]_0 : int, $j_4 : int, $a : array<int>, $j_5 : int) | ||
Note that the Z3 engine was used for verification! | ||
Path condition: | ||
forall $i_0 : int :: ((0<=$i_0)&&($i_0<($a.size()-1))) ==> ($a[$i_0]<=$a[($i_0+1)]) && | ||
($slp_0<=$i_1) && | ||
forall $k_1 : int :: forall $l_1 : int :: ((((0<=$k_1)&&($k_1<=$l_1))&&($l_1<$i_1))&&($a[$k_1]==$a[$l_1])) ==> (($l_1-$k_1)<=$slp_0) && | ||
!($i_1<$a.size()) | ||
Type constraints: | ||
$slp_0 : int | ||
$i_1 : int | ||
$a : array<int> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.