main
|
Last change
on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1.8 KB
|
| Line | |
|---|
| 1 | #pragma CIVL ACSL
|
|---|
| 2 |
|
|---|
| 3 | #define EXISTS(bv,rst,pred) (!(\forall int (bv); (rst) ==> !(pred)))
|
|---|
| 4 |
|
|---|
| 5 | $input int patLen, aLen;
|
|---|
| 6 | $assume(patLen > 0 && aLen > 0);
|
|---|
| 7 | $input int pat[patLen];
|
|---|
| 8 | $input int a[aLen];
|
|---|
| 9 |
|
|---|
| 10 | int main() {
|
|---|
| 11 | int shift = 0;
|
|---|
| 12 | int i;
|
|---|
| 13 | int isRePre = -1;
|
|---|
| 14 |
|
|---|
| 15 | if(patLen > aLen+1) isRePre = 0;
|
|---|
| 16 | else {
|
|---|
| 17 | /*@ loop invariant (0 <= i && i <= patLen) && (-1 <= isRePre && isRePre <= 1);
|
|---|
| 18 | @ loop invariant 0 <= shift && shift <= 1;
|
|---|
| 19 | @ loop invariant i == aLen ==> (shift == 1 || isRePre != -1);
|
|---|
| 20 | @ loop invariant isRePre == 1 ==> (i >= aLen && shift == 0);
|
|---|
| 21 | @ loop invariant (shift == 0) ==> (\forall int t; 0 <= t && t < i ==> a[t] == pat[t]);
|
|---|
| 22 | @ loop invariant (shift == 1 && isRePre != 0) ==> EXISTS(k, (0 <= k && k < i), (
|
|---|
| 23 | @ (\forall int t; 0 <= t && t < k ==> a[t] == pat[t]) &&
|
|---|
| 24 | @ (\forall int t; k < t && t < i ==> a[t-1] == pat[t]) &&
|
|---|
| 25 | @ (a[k] != pat[k])
|
|---|
| 26 | @ ));
|
|---|
| 27 | @*/
|
|---|
| 28 | for(i=0; i<patLen && isRePre == -1; i++) {
|
|---|
| 29 | if(pat[i] != a[i-shift])
|
|---|
| 30 | if(shift == 0)
|
|---|
| 31 | shift = 1;
|
|---|
| 32 | else
|
|---|
| 33 | isRePre = 0;
|
|---|
| 34 | if(isRePre == -1 && i == aLen - 1 && shift == 0)
|
|---|
| 35 | isRePre = 1;
|
|---|
| 36 | }
|
|---|
| 37 | isRePre = isRePre == -1 ? 1 : isRePre;
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | // assertions
|
|---|
| 41 | if (patLen > aLen+1) {
|
|---|
| 42 | $assert(!isRePre);
|
|---|
| 43 | } else if (patLen == aLen+1 && isRePre) {
|
|---|
| 44 | $assert(
|
|---|
| 45 | ($exists (int k: 0 .. patLen-1)
|
|---|
| 46 | (
|
|---|
| 47 | ($forall (int i: 0 .. k-1) pat[i] == a[i]) && ($forall (int i: k+1 .. patLen-1) pat[i] == a[i-1]))));
|
|---|
| 48 | } else if (isRePre) {
|
|---|
| 49 | $assert(
|
|---|
| 50 | ($exists (int k: 0 .. patLen)
|
|---|
| 51 | (
|
|---|
| 52 | ($forall (int i: 0 .. k-1) pat[i] == a[i]) && ($forall (int i: k+1 .. patLen-1) pat[i] == a[i-1])))
|
|---|
| 53 | );
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.