Commit 01546f5d by Jean-Christophe Filliâtre

### syntax [] for array access in programs

parent c232ed5b
 ... ... @@ -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 ... ...
 ... ... @@ -8,154 +8,175 @@ ... ...
 ... ... @@ -21,7 +21,7 @@ module Muller invariant { 0 <= count = num_of a.elts 0 i <= i and length u = num_of a.elts 0 (length a) } if a[i] <> 0 then begin set u !count a[i]; incr count end done doneg end ... ...
 ... ... @@ -84,13 +84,13 @@ let search_safety () = label Init: let s = ref 0 in for i = 0 to m - 1 do (* could be n instead of m *) s := !s + get x i s := !s + x[i] done; for d = 0 to m - 1 do invariant { length x = m } for c = get x d + 1 to 9 do for c = x[d] + 1 to 9 do invariant { length x = m } let delta = y - !s - c + get x d in let delta = y - !s - c + x[d] in if 0 <= delta && delta <= 9 * d then begin set x d c; let k = div delta 9 in ... ... @@ -103,7 +103,7 @@ let search_safety () = raise Success end done; s := !s - get x d s := !s - x[d] done { true } | Success -> { true } ... ... @@ -120,7 +120,7 @@ let search () = let s = ref 0 in for i = 0 to m - 1 do (* could be n instead of m *) invariant { s = sum x.elts 0 i } s := !s + get x i s := !s + x[i] done; assert { s = sum x.elts 0 m }; for d = 0 to m - 1 do ... ... @@ -128,9 +128,9 @@ let search () = x = at x Init and s = sum x.elts d m } for c = get x d + 1 to 9 do for c = x[d] + 1 to 9 do invariant { x = at x Init } let delta = y - !s - c + get x d in let delta = y - !s - c + x[d] in if 0 <= delta && delta <= 9 * d then begin set x d c; assert { sum x.elts d m = y - delta }; ... ... @@ -149,7 +149,7 @@ let search () = raise Success end done; s := !s - get x d s := !s - x[d] done { true } | Success -> { is_integer x.elts and sum x.elts 0 m = y } ... ... @@ -244,7 +244,7 @@ let search_smallest () = let s = ref 0 in for i = 0 to m - 1 do (* could be n instead of m *) invariant { s = sum x.elts 0 i } s := !s + get x i s := !s + x[i] done; assert { s = sum x.elts 0 m }; for d = 0 to m - 1 do ... ... @@ -254,14 +254,14 @@ let search_smallest () = forall u : int. interp (at x.elts Init) 0 m < u <= interp9 x.elts d m -> sum_digits u <> y } for c = get x d + 1 to 9 do for c = x[d] + 1 to 9 do invariant { x = at x Init and forall c' : int. x[d] < c' < c -> forall u : int. interp (at x.elts Init) 0 m < u <= interp9 (M.set x.elts d c') d m -> sum_digits u <> y } let delta = y - !s - c + get x d in let delta = y - !s - c + x[d] in if 0 <= delta && delta <= 9 * d then begin assert { smallest_size delta <= d }; set x d c; ... ... @@ -288,7 +288,7 @@ let search_smallest () = raise Success end done; s := !s - get x d s := !s - x[d] done { false } | Success -> { is_integer x.elts and sum x.elts 0 m = y and ... ...
 ... ... @@ -16,9 +16,9 @@ module Quicksort let swap (t:array int) (i:int) (j:int) = { 0 <= i < length t and 0 <= j < length t } let v = get t i in let v = t[i] in begin set t i (get t j); set t i t[j]; set t j v end { exchange t (old t) i j } ... ...
 ... ... @@ -34,8 +34,9 @@ module Array type array 'a model {| length : int; mutable elts : map int 'a |} logic ([]) (a: array 'a) (i :int) : 'a = M.([]) a.elts i logic unsafe_get (a: array 'a) (i :int) : 'a = M.([]) a.elts i parameter get : a:array 'a -> i:int -> parameter ([]) : a:array 'a -> i:int -> { 0 <= i < length a } 'a reads a { result = a[i] } parameter set : a:array 'a -> i:int -> v:'a -> ... ...
 ... ... @@ -35,9 +35,9 @@ module String use import int.Int use import module Char use array.Array as S use map.Map as S type string model {| length : int; mutable chars : S.t int char |} type string model {| length: int; mutable chars: S.t int char |} parameter create : len:int -> { len >= 0 } string { S.length result = len } ... ...
 ... ... @@ -215,6 +215,12 @@ and specialize_binder ~loc htv v = (* | PSlogic -> *) (* ps, *) let parameter x = "parameter " ^ x let rec parameter_q = function | [] -> assert false | [x] -> [parameter x] | x :: q -> x :: parameter_q q let dot fmt () = pp_print_string fmt "." let print_qualids = print_list dot pp_print_string let print_qualid fmt q = ... ... @@ -427,8 +433,12 @@ and dexpr_desc ~ghost env loc = function region_vars := Htv.create 17 :: !region_vars; let x = Typing.string_list_of_qualid [] p in let ls = try ns_find_ls (get_namespace (impure_uc env.uc)) x with Not_found -> errorm ~loc "unbound symbol %a" print_qualid p try ns_find_ls (get_namespace (impure_uc env.uc)) x with Not_found -> try ns_find_ls (get_namespace (impure_uc env.uc)) (parameter_q x) with Not_found -> errorm ~loc "unbound symbol %a" print_qualid p in let ps = get_psymbol ls in begin match ps.ps_kind with ... ... @@ -1800,6 +1810,7 @@ let add_impure_decl uc ls = Pgm_module.add_impure_decl (Decl.create_logic_decl [ls, None]) uc let add_global_fun loc x tyv uc = let x = parameter x in try let ps = create_psymbol_fun (id_user x loc) tyv in let d = Decl.create_logic_decl [ps.ps_impure, None] in ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!