main
test-branch
|
Last change
on this file since 1aaefd4 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.3 KB
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 | int allZero(int * A, int len) {
|
|---|
| 4 | /* Note in theory one must assert here that A + (0..len-1) are valid pointers.
|
|---|
| 5 | There is no good way in CIVL-C to express it currently.
|
|---|
| 6 | */
|
|---|
| 7 | $assert($true);
|
|---|
| 8 |
|
|---|
| 9 | int ret;
|
|---|
| 10 | $havoc(&ret); // assigning ret a fresh symbolic constant
|
|---|
| 11 | $assume(ret == 0 || ret == 1);
|
|---|
| 12 | $assume(ret == 1 => $forall (int i: 0 .. (len-1)) A[i] == 0);
|
|---|
| 13 | $assume(ret == 0 => $exists (int i: 0 .. (len-1)) A[i] != 0);
|
|---|
| 14 | return ret;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 | int allZeroImpl(int * A, int len) {
|
|---|
| 19 | int ret = 1;
|
|---|
| 20 |
|
|---|
| 21 | for (int i = 0; i < len; i++) {
|
|---|
| 22 | if (A[i] != 0) {
|
|---|
| 23 | ret = 0;
|
|---|
| 24 | // return ret // I comment out this early return to enlarge the state space of this function
|
|---|
| 25 | // for a model checker
|
|---|
| 26 | }
|
|---|
| 27 | }
|
|---|
| 28 | return ret;
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | #define N 10
|
|---|
| 32 | $input int A[N];
|
|---|
| 33 |
|
|---|
| 34 | int main() {
|
|---|
| 35 | int ret;
|
|---|
| 36 |
|
|---|
| 37 | /* These two calls deliver the same functionality for the assertion
|
|---|
| 38 | below. The first call is much faster when N is large. But one
|
|---|
| 39 | has to prove that allZero is an abstraction of allZeroImpl.
|
|---|
| 40 |
|
|---|
| 41 | A separate proof can be done with smaller scopes or using loop
|
|---|
| 42 | invariants. In either case, it can overcome the state explosion
|
|---|
| 43 | problem brought by nondeterminism when N is very large.
|
|---|
| 44 | */
|
|---|
| 45 | ret = allZero(A, N);
|
|---|
| 46 | //ret = allZeroImpl(A, N);
|
|---|
| 47 |
|
|---|
| 48 | $assert(ret == 1 => $forall (int i: 0 .. N-1) A[i] == 0);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.