main
| Line | |
|---|
| 1 | /* assoc.cvl: adds the elements of an array in two different
|
|---|
| 2 | * orders, and checks the results agree. This relies on the
|
|---|
| 3 | * use of real arithmetic, as opposed to floating-point
|
|---|
| 4 | * arithmetic.
|
|---|
| 5 | *
|
|---|
| 6 | * Should be run at commandline specifying an upper bound on
|
|---|
| 7 | * the length of the array. Example:
|
|---|
| 8 | * civl verify -inputB=100 assoc.cvl
|
|---|
| 9 | */
|
|---|
| 10 | $input int B = 10;
|
|---|
| 11 | $input int n;
|
|---|
| 12 | $assume(0<n && n<B);
|
|---|
| 13 | $input double a[n];
|
|---|
| 14 |
|
|---|
| 15 | void main() {
|
|---|
| 16 | double s0 = 0.0;
|
|---|
| 17 | double s1 = 0.0;
|
|---|
| 18 |
|
|---|
| 19 | for (int i = 0; i < n; i++) {
|
|---|
| 20 | s0 += a[i];
|
|---|
| 21 | s1 += a[n-1-i];
|
|---|
| 22 | }
|
|---|
| 23 | $assert(s0 == s1);
|
|---|
| 24 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.