source: CIVL/examples/tickets/ticket_913_loop_bounds.cvl

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.6 KB
RevLine 
[0d6233d]1/* Theory loop_bounds. Two parameters: n and b.
2 * To prove consistency of this theory:
3 * civl verify -D_PROVE loop_bounds.cvl
4 * To use this theory in a program:
5 * 1. Add #include "loop_bounds.cvl" somewhere before first use of the theory
6 * 2. Add instantiate_theory_loop_bounds(n,b) for each pair of vars n,b you wish
7 * to generate the lemmas for.
8 */
9#pragma CIVL ACSL
10#ifdef _PROVE
11#define $ASSUME $assume
12#define $ASSERT $assert
13$input int n,b,o;
14/*@ logic int loop_max(int offset, int up, int step) = up > offset ? up+step-1-(up-offset-1)%step : offset;
15 @
16 @ // describing the relationship among variables in a loop : for (int i = offset; i < up; i+=step)
17 @ predicate in_stride(int offset, int i, int step) = i - offset >= 0 && ((i - offset) % step == 0);
18 @*/
19int main() {
20#else
21#define $ASSUME $assert
22#define $ASSERT $assume
23 $abstract int loop_max(int offset, int up, int step);
24 $abstract _Bool in_stride(int offset, int i, int step);
25#endif
26#define instantiate_theory_loop_bounds(n,b,o) \
27 $ASSUME(0<b && b<n && 0 <= o && o <= b); \
28 $ASSERT($forall (int x) (in_stride(o, x, b) && n-b > x && o < n-b => loop_max(o, n-b, b) >= x + b)); \
29 $ASSERT($forall (int x| x>0) in_stride(o, x, b) => in_stride(o, x+b, b)); \
30 $ASSERT(in_stride(o, o, b)); \
31 $ASSERT($forall (int x) (in_stride(o, x, b) && x >= n-b => x >= loop_max(o, n-b, b))); \
32 $ASSERT(n-b <= loop_max(o, n-b, b) && loop_max(o, n-b, b) < n);
33#define in_range(i, offset, up, step) (in_stride((offset), (i), (step)) && 1 <= (i) && (i) <= loop_max((offset), (up), (step)))
34#ifdef _PROVE
35 instantiate_theory_loop_bounds(n,b,o)
36}
37#endif
Note: See TracBrowser for help on using the repository browser.