3 The following program sorts an array of Boolean values, with False<True.
7 1. Prove safety i.e. the absence of array access out of bounds.
11 3. Prove that array a is sorted after execution of function two_way_sort
12 (using the predicate sorted that is provided).
14 4. Show that after execution the array contents is a permutation of its
15 initial contents. Use the library predicate "permut_all" to do so
16 (the corresponding module ArrayPermut is already imported).
18 Within a postcondition, you can refer to the contents of array a
19 at the beginning of the function with notation (old a).
20 Within a loop invariant, you can refer to it with notation (at a 'Init).
33 predicate (<<) (x y: bool) = x = False \/ y = True
35 predicate sorted (a: array bool) =
36 forall i1 i2: int. 0 <= i1 <= i2 < a.length -> a[i1] << a[i2]
38 let two_way_sort [@bddinfer] [@infer](a: array bool) : unit
39 requires { length a >= 0 }
44 let j = ref (length a - 1) in
47 invariant { forall k:int. 0 <= k < !i -> not a[k] }
48 invariant { forall k:int. !j < k < length a -> a[k] }
60 let two_way_sort3 [@bddinfer] [@infer:box](a: array bool) : unit
61 requires { length a >= 0 }
66 let j = ref (length a - 1) in
69 invariant { forall k:int. 0 <= k < !i -> not a[k] }
70 invariant { forall k:int. !j < k < length a -> a[k] }