syntax [] for array access in programs

This commit is contained in:
Jean-Christophe Filliatre
2011-05-16 15:59:52 +02:00
parent c232ed5bac
commit 01546f5dfd
8 changed files with 142 additions and 109 deletions

View File

@@ -28,8 +28,8 @@ module Decrease1
invariant { 0 <= i and
forall j: int. 0 <= j < i -> j < length a -> a[j] <> 0 }
variant { length a - i }
if get a !i = 0 then raise Found;
if get a !i > 0 then i := !i + get a !i else i := !i + 1
if a[!i] = 0 then raise Found;
if a[!i] > 0 then i := !i + a[!i] else i := !i + 1
done;
-1
with Found ->
@@ -42,8 +42,8 @@ module Decrease1
let rec search_rec (a: array int) (i : int) =
{ decrease1 a and 0 <= i }
if i < length a then
if get a i = 0 then i
else if get a i > 0 then search_rec a (i + get a i)
if a[i] = 0 then i
else if a[i] > 0 then search_rec a (i + a[i])
else search_rec a (i + 1)
else
-1