source: CIVL/examples/focus/development/arrayEquals.cvl@ 397ae5f

main test-branch
Last change on this file since 397ae5f was 6d5b8a3, checked in by Alex Wilton <awilton@…>, 8 months ago

Cleaned up focus examples. Enhanced focus window performance. Fixed a pretty print bug

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5993 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[c2b37db]1/**
2 * Issue here is that focus cannot be applied across functions as usual.
3 * If we want to apply focus to a loop in a function then that function
4 * needs a function contract.
5
6 * Function contract here doesn't work for some reason (CIVL bug)
7
8 * Also the postcondition currently can't be transformed with focus
9 * so an assertion must be inserted into the function to apply focus.
10 * This could be fixed.
11 */
[01c5b2ce]12#include<assert.h>
13
14#pragma CIVL ACSL
15
16$input int N;
17$assume(N > 0);
18$input double a[N];
19$input double b[N];
20
21/*@ requires n > 0;
22 @ requires \valid(a+(0..n)) && \valid(b+(0..n));
23 @ assigns \nothing;
24 @ ensures (\result == \true) ==> (\forall int i; 0 <= i && i < n ==> a[i] == b[i]);
25 @*/
26_Bool arrayEquals(double * a, double * b, int n) {
27 _Bool equal = $true;
28
29 //@ focus F;
30 for (int i = 0; i < n; i++)
31 if (a[i] != b[i])
32 equal = $false;
33 //@ focus F;
34 assert($forall (int i: 0 .. n-1) equal => a[i] == b[i]);
35 return equal;
36}
37
38int main() {
39 _Bool ret = arrayEquals(a, b, N);
40
41 if (ret) {
42 assert($forall (int i: 0 .. N-1) a[i] == b[i]);
43 }
44}
Note: See TracBrowser for help on using the repository browser.