file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
Pulse.Typing.fst
Pulse.Typing.lift_typing_to_ghost_typing
val lift_typing_to_ghost_typing (#g: env) (#e: term) (#eff: T.tot_or_ghost) (#t: term) (d: typing g e eff t) : ghost_typing g e t
val lift_typing_to_ghost_typing (#g: env) (#e: term) (#eff: T.tot_or_ghost) (#t: term) (d: typing g e eff t) : ghost_typing g e t
let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 55, "end_line": 508, "start_col": 0, "start_line": 502 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
d: Pulse.Typing.typing g e eff t -> Pulse.Typing.ghost_typing g e t
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.term", "FStar.Stubs.TypeChecker.Core.tot_or_ghost", "Pulse.Typing.typing", "Prims.op_Equality", "FStar.Stubs.TypeChecker.Core.E_Ghost", "Prims.bool", "FStar.Reflection.Typing.typing", "Pulse.Typing.elab_env", "Pulse.Elaborate.Pure.elab_term", "FStar.Pervasives.Native.Mktuple2", "FStar.Stubs.Reflection.Types.typ", "Pulse.Typing.E", "FStar.Reflection.Typing.T_Sub", "FStar.Reflection.Typing.Relc_total_ghost", "Pulse.Typing.ghost_typing" ]
[]
false
false
false
false
false
let lift_typing_to_ghost_typing (#g: env) (#e: term) (#eff: T.tot_or_ghost) (#t: term) (d: typing g e eff t) : ghost_typing g e t =
if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _))
false
Pulse.Typing.fst
Pulse.Typing.non_informative_c
val non_informative_c : g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0
let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c)
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 45, "end_line": 517, "start_col": 0, "start_line": 516 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Typing.Env.env -> c: Pulse.Syntax.Base.comp_st -> Type0
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Syntax.Base.comp_st", "Pulse.Typing.non_informative_t", "Pulse.Syntax.Base.comp_u", "Pulse.Syntax.Base.comp_res" ]
[]
false
false
false
true
true
let non_informative_c (g: env) (c: comp_st) =
non_informative_t g (comp_u c) (comp_res c)
false
Pulse.Typing.fst
Pulse.Typing.add_iname_at_least_unobservable
val add_iname_at_least_unobservable : s: Pulse.Syntax.Base.comp_st{C_STAtomic? s} -> inv_vprop: Pulse.Syntax.Base.term -> inv_tm: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp
let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 62, "end_line": 252, "start_col": 0, "start_line": 246 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Pulse.Syntax.Base.comp_st{C_STAtomic? s} -> inv_vprop: Pulse.Syntax.Base.term -> inv_tm: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.comp
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.comp_st", "Prims.b2t", "Pulse.Syntax.Base.uu___is_C_STAtomic", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.observability", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.C_STAtomic", "Pulse.Typing.join_obs", "Pulse.Syntax.Base.Unobservable", "Pulse.Syntax.Base.comp", "Pulse.Syntax.Base.tm_fstar", "Pulse.Reflection.Util.add_inv_tm", "Pulse.Elaborate.Pure.elab_term", "Pulse.Syntax.Base.__proj__Mkterm__item__range" ]
[]
false
false
false
false
false
let add_iname_at_least_unobservable (s: comp_st{C_STAtomic? s}) (inv_vprop inv_tm: term) =
let add_inv_tm (inames: term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s
false
Pulse.Typing.fst
Pulse.Typing.tr_binding
val tr_binding (vt: var & typ) : Tot R.binding
val tr_binding (vt: var & typ) : Tot R.binding
let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; }
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 2, "end_line": 670, "start_col": 0, "start_line": 664 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vt: (Pulse.Syntax.Base.var * Pulse.Syntax.Base.typ) -> FStar.Stubs.Reflection.V2.Data.binding
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.tuple2", "Pulse.Syntax.Base.var", "Pulse.Syntax.Base.typ", "FStar.Stubs.Reflection.V2.Data.Mkbinding", "Pulse.Elaborate.Pure.elab_term", "Pulse.Syntax.Base.__proj__Mkppname__item__name", "Pulse.Syntax.Base.ppname_default", "FStar.Stubs.Reflection.V2.Data.binding" ]
[]
false
false
false
true
false
let tr_binding (vt: var & typ) : Tot R.binding =
let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name }
false
Pulse.Typing.fst
Pulse.Typing.wr
val wr (ct: comp_st) (t: st_term') : st_term
val wr (ct: comp_st) (t: st_term') : st_term
let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 136, "end_line": 634, "start_col": 0, "start_line": 634 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c))
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ct: Pulse.Syntax.Base.comp_st -> t: Pulse.Syntax.Base.st_term' -> Pulse.Syntax.Base.st_term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.comp_st", "Pulse.Syntax.Base.st_term'", "Pulse.Syntax.Base.Mkst_term", "FStar.Range.range_0", "Pulse.Syntax.Base.as_effect_hint", "Pulse.Syntax.Base.ctag_of_comp_st", "Pulse.Syntax.Base.st_term" ]
[]
false
false
false
true
false
let wr (ct: comp_st) (t: st_term') : st_term =
{ term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) }
false
Pulse.Typing.fst
Pulse.Typing.sub_observability
val sub_observability : o1: Pulse.Syntax.Base.observability -> o2: Pulse.Syntax.Base.observability -> Prims.bool
let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 88, "end_line": 578, "start_col": 0, "start_line": 578 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o1: Pulse.Syntax.Base.observability -> o2: Pulse.Syntax.Base.observability -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.observability", "Prims.op_BarBar", "Prims.op_Equality", "Pulse.Syntax.Base.Neutral", "Pulse.Syntax.Base.Observable", "Prims.bool" ]
[]
false
false
false
true
false
let sub_observability (o1 o2: observability) =
o1 = Neutral || o1 = o2 || o2 = Observable
false
Pulse.Typing.fst
Pulse.Typing.wtag
val wtag (ct: option ctag) (t: st_term') : st_term
val wtag (ct: option ctag) (t: st_term') : st_term
let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 128, "end_line": 635, "start_col": 0, "start_line": 635 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c))
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ct: FStar.Pervasives.Native.option Pulse.Syntax.Base.ctag -> t: Pulse.Syntax.Base.st_term' -> Pulse.Syntax.Base.st_term
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.ctag", "Pulse.Syntax.Base.st_term'", "Pulse.Syntax.Base.Mkst_term", "FStar.Range.range_0", "FStar.Sealed.seal", "Pulse.Syntax.Base.st_term" ]
[]
false
false
false
true
false
let wtag (ct: option ctag) (t: st_term') : st_term =
{ term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct }
false
Pulse.Typing.fst
Pulse.Typing.inv_disjointness
val inv_disjointness : inv_p: Pulse.Syntax.Base.term -> inames: Pulse.Syntax.Base.term -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term
let inv_disjointness (inv_p inames inv:term) = let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 22, "end_line": 724, "start_col": 0, "start_line": 722 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2) let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; } let tr_bindings = L.map tr_binding [@@ no_auto_projectors] noeq type comp_typing : env -> comp -> universe -> Type = | CT_Tot : g:env -> t:term -> u:universe -> universe_of g t u -> comp_typing g (C_Tot t) u | CT_ST : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_ST st) (universe_of_comp (C_ST st)) | CT_STAtomic : g:env -> inames:term -> obs:observability -> st:st_comp -> tot_typing g inames tm_inames -> st_comp_typing g st -> comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st)) | CT_STGhost : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) let subtyping_token g t1 t2 = T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) val readback_binding : R.binding -> binding let readback_binding b = assume (host_term == R.term); // fixme! expose this fact match readback_ty b.sort with | Some sort -> (b.uniq, sort) | None -> let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in (b.uniq, sort) let non_informative (g:env) (c:comp) = my_erased (RT.non_informative (elab_env g) (elab_comp c))
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inv_p: Pulse.Syntax.Base.term -> inames: Pulse.Syntax.Base.term -> inv: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.tm_fstar", "Pulse.Syntax.Base.__proj__Mkterm__item__range", "FStar.Stubs.Reflection.Types.term", "Pulse.Reflection.Util.inv_disjointness_goal", "Pulse.Elaborate.Pure.elab_term" ]
[]
false
false
false
true
false
let inv_disjointness (inv_p inames inv: term) =
let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range
false
Pulse.Typing.fst
Pulse.Typing.tm_join_inames
val tm_join_inames (inames1 inames2: term) : term
val tm_join_inames (inames1 inames2: term) : term
let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1)
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 530, "start_col": 0, "start_line": 520 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inames1: Pulse.Syntax.Base.term -> inames2: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.eq_tm", "Pulse.Syntax.Base.tm_emp_inames", "Prims.bool", "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_FStar", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "FStar.Stubs.Reflection.Types.term", "Prims.Nil", "FStar.Stubs.Reflection.V2.Builtins.range_of_term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Prims.list", "Prims.string", "Pulse.Reflection.Util.mk_pulse_lib_core_lid", "Pulse.Elaborate.Pure.elab_term" ]
[]
false
false
false
true
false
let tm_join_inames (inames1 inames2: term) : term =
if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join:R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1)
false
Pulse.Typing.fst
Pulse.Typing.comp_post_matches_hint
val comp_post_matches_hint : c: Pulse.Syntax.Base.comp_st -> post_hint: FStar.Pervasives.Native.option Pulse.Typing.post_hint_t -> Prims.logical
let comp_post_matches_hint (c:comp_st) (post_hint:option post_hint_t) = match post_hint with | None -> True | Some post_hint -> comp_res c == post_hint.ret_ty /\ comp_u c == post_hint.u /\ comp_post c == post_hint.post /\ effect_annot_matches c post_hint.effect_annot
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 49, "end_line": 1208, "start_col": 0, "start_line": 1201 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2) let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; } let tr_bindings = L.map tr_binding [@@ no_auto_projectors] noeq type comp_typing : env -> comp -> universe -> Type = | CT_Tot : g:env -> t:term -> u:universe -> universe_of g t u -> comp_typing g (C_Tot t) u | CT_ST : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_ST st) (universe_of_comp (C_ST st)) | CT_STAtomic : g:env -> inames:term -> obs:observability -> st:st_comp -> tot_typing g inames tm_inames -> st_comp_typing g st -> comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st)) | CT_STGhost : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) let subtyping_token g t1 t2 = T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) val readback_binding : R.binding -> binding let readback_binding b = assume (host_term == R.term); // fixme! expose this fact match readback_ty b.sort with | Some sort -> (b.uniq, sort) | None -> let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in (b.uniq, sort) let non_informative (g:env) (c:comp) = my_erased (RT.non_informative (elab_env g) (elab_comp c)) let inv_disjointness (inv_p inames inv:term) = let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range let eff_of_ctag = function | STT_Ghost -> T.E_Ghost | _ -> T.E_Total [@@ no_auto_projectors] noeq type st_typing : env -> st_term -> comp -> Type = | T_Abs: g:env -> x:var { None? (lookup g x) } -> q:option qualifier -> b:binder -> u:universe -> body:st_term {~ (x `Set.mem` freevars_st body) } -> c:comp -> tot_typing g b.binder_ty (tm_type u) -> st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c -> st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription})) (C_Tot (tm_arrow b q (close_comp c x))) | T_STApp : g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> tot_typing g head (tm_arrow (as_binder ty) q res) -> tot_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) // // this rule requires a non-informative judgment // for C_STGhost, this will always be the case // however, when doing the soundness proof, // we cannot call into the reflection API to get the token // may be there is another way to make it so that we can get this once-and-for-all // for C_STGhost // | T_STGhostApp: g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } -> ghost_typing g head (tm_arrow (as_binder ty) q res) -> non_informative (push_binding g x ppname_default ty) (open_comp_with res (null_var x)) -> ghost_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) | T_Return: g:env -> c:ctag -> use_eq:bool -> u:universe -> t:term -> e:term -> post:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } -> universe_of g t u -> typing g e (eff_of_ctag c) t -> tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop -> st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e })) (comp_return c use_eq u t e post x) | T_Lift: g:env -> e:st_term -> c1:comp_st -> c2:comp_st -> st_typing g e c1 -> lift_comp g c1 c2 -> st_typing g e c2 | T_Bind: g:env -> e1:st_term -> e2:st_term -> c1:comp_st -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> c:comp -> st_typing g e1 c1 -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> bind_comp g x c1 c2 c -> st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c | T_BindFn: g:env -> e1:st_term -> e2:st_term -> c1:comp { C_Tot? c1 } -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> st_typing g e1 c1 -> u:Ghost.erased universe -> tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> comp_typing_u g c2 -> st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2 | T_If: g:env -> b:term -> e1:st_term -> e2:st_term -> c:comp_st -> (* This is a little weird, we introduce a name hyp in the environment, but the branches are not allowed to use it (except perhaps in a silent way for proofs). Maybe more natural to have one free var in e1,e2 and to open it with hyp? But that's also a change to FStar.Reflection.Typing *) hyp:var { None? (lookup g hyp) /\ ~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2)) } -> tot_typing g b tm_bool -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c -> my_erased (comp_typing_u g c) -> st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c | T_Match : g:env -> sc_u:universe -> sc_ty:typ -> sc:term -> tot_typing g sc_ty (tm_type sc_u) -> tot_typing g sc sc_ty -> c:comp_st -> my_erased (comp_typing_u g c) -> brs:list (pattern & st_term) -> brs_typing g sc_u sc_ty sc brs c -> pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) -> st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c | T_Frame: g:env -> e:st_term -> c:comp_st -> frame:term -> tot_typing g frame tm_vprop -> st_typing g e c -> st_typing g e (add_frame c frame) | T_Equiv: g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_equiv g c c' -> st_typing g e c' | T_Sub : g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_sub g c c' -> st_typing g e c' | T_IntroPure: g:env -> p:term -> tot_typing g p tm_prop -> prop_validity g p -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p })) (comp_intro_pure p) | T_ElimExists: g:env -> u:universe -> t:term -> p:term -> x:var { None? (lookup g x) } -> tot_typing g t (tm_type u) -> tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop -> st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p })) (comp_elim_exists u t p (v_as_nv x)) | T_IntroExists: g:env -> u:universe -> b:binder -> p:term -> e:term -> tot_typing g b.binder_ty (tm_type u) -> tot_typing g (tm_exists_sl u b p) tm_vprop -> ghost_typing g e b.binder_ty -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p; witnesses= [e] })) (comp_intro_exists u b p e) | T_While: g:env -> inv:term -> cond:st_term -> body:st_term -> tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop -> st_typing g cond (comp_while_cond ppname_default inv) -> st_typing g body (comp_while_body ppname_default inv) -> st_typing g (wtag (Some STT) (Tm_While { invariant = inv; condition = cond; body; condition_var = ppname_default } )) (comp_while ppname_default inv) | T_Par: g:env -> eL:st_term -> cL:comp { C_ST? cL } -> eR:st_term -> cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } -> x:var { None? (lookup g x) } -> // TODO: can comp_typing come from inversion of eL : cL and eR : cR? comp_typing_u g cL -> comp_typing_u g cR -> st_typing g eL cL -> st_typing g eR cR -> st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown; pre2=tm_unknown; body2=eR; post2=tm_unknown })) (comp_par cL cR x) | T_WithLocal: g:env -> binder_ppname:ppname -> init:term -> body:st_term -> init_t:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g init init_t -> universe_of g init_t u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) -> st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c | T_WithLocalArray: g:env -> binder_ppname:ppname -> initializer:term -> length:term -> body:st_term -> a:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g initializer a -> tot_typing g length tm_szt -> universe_of g a u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_array a)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x a initializer length c) -> st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c | T_Rewrite: g:env -> p:vprop -> q:vprop -> tot_typing g p tm_vprop -> vprop_equiv g p q -> st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } )) (comp_rewrite p q) | T_Admit: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None })) (comp_admit c s) | T_Unreachable: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> prop_validity g (tm_fstar (`False) FStar.Range.range_0) -> st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s) (* This limits the body to be atomic, rather than also allowing unobservable *) | T_WithInv: g:env -> inv_tm : term -> inv_vprop : vprop -> inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) -> body : st_term -> c : comp_st { C_STAtomic? c } -> body_typing : st_typing g body (add_frame c inv_vprop) -> inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) -> st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None})) (add_iname_at_least_unobservable c inv_vprop inv_tm) and pats_complete : env -> term -> typ -> list R.pattern -> Type0 = // just check the elaborated term with the core tc | PC_Elab : g:env -> sc:term -> sc_ty:typ -> pats:list R.pattern -> bnds:list (list R.binding) -> RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds -> pats_complete g sc sc_ty pats and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type = | TBRS_0 : c:comp_st -> brs_typing g sc_u sc_ty sc [] c | TBRS_1 : c:comp_st -> p:pattern -> e:st_term -> br_typing g sc_u sc_ty sc p e c -> rest:list branch -> brs_typing g sc_u sc_ty sc rest c -> brs_typing g sc_u sc_ty sc ((p,e)::rest) c and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type = | TBR : g:env -> sc_u : universe -> sc_ty : typ -> sc:term -> c:comp_st -> p:pattern -> e:st_term -> bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} -> _ : squash (all_fresh g (L.map readback_binding bs)) -> _ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) -> _ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} -> st_typing ( push_binding (push_bindings g (L.map readback_binding bs)) hyp ({name=Sealed.seal "branch equality"; range=FStar.Range.range_0}) (mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0)) ) e c -> br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c (* this requires some metatheory on FStar.Reflection.Typing G |- fv e : t G(fv) = t0 -> t1 G |- e : t0 G |- t1 <: t G |- e0 e1 : t ==> exists t0 t1. G |- e0 : t0 -> t1 /\ G |- e1 : t0 *) let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t0 tm_vprop = admit () let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t1 tm_vprop = admit () let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () let vprop_eq_typing_inversion g (t0 t1:term) (token:FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1)) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () (* These I can easily prove *) let star_typing (#g:_) (#t0 #t1:term) (d0:tot_typing g t0 tm_vprop) (d1:tot_typing g t1 tm_vprop) : tot_typing g (tm_star t0 t1) tm_vprop = admit () let emp_typing (#g:_) : tot_typing g tm_emp tm_vprop = admit () let fresh_wrt (x:var) (g:env) (vars:_) = None? (lookup g x) /\ ~(x `Set.mem` vars) let effect_annot_typing (g:env) (e:effect_annot) = match e with | EffectAnnotAtomic { opens } -> tot_typing g opens tm_inames | _ -> unit noeq type post_hint_t = { g:env; effect_annot:effect_annot; effect_annot_typing:effect_annot_typing g effect_annot; ret_ty:term; u:universe; ty_typing:universe_of g ret_ty u; post:term; x:(x:var { fresh_wrt x g (freevars post) }); post_typing_src:tot_typing (push_binding g x ppname_default ret_ty) (open_term post x) tm_vprop; post_typing: FStar.Ghost.erased (RT.tot_typing (elab_env g) (RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post))) (RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop))) } let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] = env_extends_push g x ppname_default b let post_hint_for_env (g:env) = p:post_hint_t { post_hint_for_env_p g p } let post_hint_opt (g:env) = o:option post_hint_t { None? o \/ post_hint_for_env_p g (Some?.v o) } noeq type post_hint_typing_t (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) = { effect_annot_typing:effect_annot_typing g p.effect_annot; ty_typing:universe_of g p.ret_ty p.u; post_typing:tot_typing (push_binding g x ppname_default p.ret_ty) (open_term p.post x) tm_vprop } irreducible let post_hint_typing (g:env) (p:post_hint_for_env g) (x:var { fresh_wrt x g (freevars p.post) }) : post_hint_typing_t g p x = let effect_annot_typing : effect_annot_typing g p.effect_annot = match p.effect_annot with | EffectAnnotAtomic { opens } -> let opens_typing : tot_typing g opens tm_inames = RU.magic () in //weakening opens_typing | _ -> () in { effect_annot_typing; ty_typing = RU.magic (); //weakening post_typing = RU.magic (); } let effect_annot_matches c (effect_annot:effect_annot) : prop = match c, effect_annot with | C_ST _, EffectAnnotSTT | C_STGhost _, EffectAnnotGhost -> True | C_STAtomic inames' _ _, EffectAnnotAtomic { opens } -> inames' == opens | _ -> False
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Pulse.Syntax.Base.comp_st -> post_hint: FStar.Pervasives.Native.option Pulse.Typing.post_hint_t -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.comp_st", "FStar.Pervasives.Native.option", "Pulse.Typing.post_hint_t", "Prims.l_True", "Prims.l_and", "Prims.eq2", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.comp_res", "Pulse.Typing.__proj__Mkpost_hint_t__item__ret_ty", "Pulse.Syntax.Base.universe", "Pulse.Syntax.Base.comp_u", "Pulse.Typing.__proj__Mkpost_hint_t__item__u", "Pulse.Syntax.Base.comp_post", "Pulse.Typing.__proj__Mkpost_hint_t__item__post", "Pulse.Typing.effect_annot_matches", "Pulse.Typing.__proj__Mkpost_hint_t__item__effect_annot", "Prims.logical" ]
[]
false
false
false
true
true
let comp_post_matches_hint (c: comp_st) (post_hint: option post_hint_t) =
match post_hint with | None -> True | Some post_hint -> comp_res c == post_hint.ret_ty /\ comp_u c == post_hint.u /\ comp_post c == post_hint.post /\ effect_annot_matches c post_hint.effect_annot
false
Pulse.Typing.fst
Pulse.Typing.fresh_wrt
val fresh_wrt : x: Pulse.Syntax.Base.var -> g: Pulse.Typing.Env.env -> vars: FStar.Set.set Pulse.Syntax.Base.var -> Prims.logical
let fresh_wrt (x:var) (g:env) (vars:_) = None? (lookup g x) /\ ~(x `Set.mem` vars)
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 46, "end_line": 1127, "start_col": 0, "start_line": 1126 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2) let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; } let tr_bindings = L.map tr_binding [@@ no_auto_projectors] noeq type comp_typing : env -> comp -> universe -> Type = | CT_Tot : g:env -> t:term -> u:universe -> universe_of g t u -> comp_typing g (C_Tot t) u | CT_ST : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_ST st) (universe_of_comp (C_ST st)) | CT_STAtomic : g:env -> inames:term -> obs:observability -> st:st_comp -> tot_typing g inames tm_inames -> st_comp_typing g st -> comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st)) | CT_STGhost : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) let subtyping_token g t1 t2 = T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) val readback_binding : R.binding -> binding let readback_binding b = assume (host_term == R.term); // fixme! expose this fact match readback_ty b.sort with | Some sort -> (b.uniq, sort) | None -> let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in (b.uniq, sort) let non_informative (g:env) (c:comp) = my_erased (RT.non_informative (elab_env g) (elab_comp c)) let inv_disjointness (inv_p inames inv:term) = let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range let eff_of_ctag = function | STT_Ghost -> T.E_Ghost | _ -> T.E_Total [@@ no_auto_projectors] noeq type st_typing : env -> st_term -> comp -> Type = | T_Abs: g:env -> x:var { None? (lookup g x) } -> q:option qualifier -> b:binder -> u:universe -> body:st_term {~ (x `Set.mem` freevars_st body) } -> c:comp -> tot_typing g b.binder_ty (tm_type u) -> st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c -> st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription})) (C_Tot (tm_arrow b q (close_comp c x))) | T_STApp : g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> tot_typing g head (tm_arrow (as_binder ty) q res) -> tot_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) // // this rule requires a non-informative judgment // for C_STGhost, this will always be the case // however, when doing the soundness proof, // we cannot call into the reflection API to get the token // may be there is another way to make it so that we can get this once-and-for-all // for C_STGhost // | T_STGhostApp: g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } -> ghost_typing g head (tm_arrow (as_binder ty) q res) -> non_informative (push_binding g x ppname_default ty) (open_comp_with res (null_var x)) -> ghost_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) | T_Return: g:env -> c:ctag -> use_eq:bool -> u:universe -> t:term -> e:term -> post:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } -> universe_of g t u -> typing g e (eff_of_ctag c) t -> tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop -> st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e })) (comp_return c use_eq u t e post x) | T_Lift: g:env -> e:st_term -> c1:comp_st -> c2:comp_st -> st_typing g e c1 -> lift_comp g c1 c2 -> st_typing g e c2 | T_Bind: g:env -> e1:st_term -> e2:st_term -> c1:comp_st -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> c:comp -> st_typing g e1 c1 -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> bind_comp g x c1 c2 c -> st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c | T_BindFn: g:env -> e1:st_term -> e2:st_term -> c1:comp { C_Tot? c1 } -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> st_typing g e1 c1 -> u:Ghost.erased universe -> tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> comp_typing_u g c2 -> st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2 | T_If: g:env -> b:term -> e1:st_term -> e2:st_term -> c:comp_st -> (* This is a little weird, we introduce a name hyp in the environment, but the branches are not allowed to use it (except perhaps in a silent way for proofs). Maybe more natural to have one free var in e1,e2 and to open it with hyp? But that's also a change to FStar.Reflection.Typing *) hyp:var { None? (lookup g hyp) /\ ~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2)) } -> tot_typing g b tm_bool -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c -> my_erased (comp_typing_u g c) -> st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c | T_Match : g:env -> sc_u:universe -> sc_ty:typ -> sc:term -> tot_typing g sc_ty (tm_type sc_u) -> tot_typing g sc sc_ty -> c:comp_st -> my_erased (comp_typing_u g c) -> brs:list (pattern & st_term) -> brs_typing g sc_u sc_ty sc brs c -> pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) -> st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c | T_Frame: g:env -> e:st_term -> c:comp_st -> frame:term -> tot_typing g frame tm_vprop -> st_typing g e c -> st_typing g e (add_frame c frame) | T_Equiv: g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_equiv g c c' -> st_typing g e c' | T_Sub : g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_sub g c c' -> st_typing g e c' | T_IntroPure: g:env -> p:term -> tot_typing g p tm_prop -> prop_validity g p -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p })) (comp_intro_pure p) | T_ElimExists: g:env -> u:universe -> t:term -> p:term -> x:var { None? (lookup g x) } -> tot_typing g t (tm_type u) -> tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop -> st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p })) (comp_elim_exists u t p (v_as_nv x)) | T_IntroExists: g:env -> u:universe -> b:binder -> p:term -> e:term -> tot_typing g b.binder_ty (tm_type u) -> tot_typing g (tm_exists_sl u b p) tm_vprop -> ghost_typing g e b.binder_ty -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p; witnesses= [e] })) (comp_intro_exists u b p e) | T_While: g:env -> inv:term -> cond:st_term -> body:st_term -> tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop -> st_typing g cond (comp_while_cond ppname_default inv) -> st_typing g body (comp_while_body ppname_default inv) -> st_typing g (wtag (Some STT) (Tm_While { invariant = inv; condition = cond; body; condition_var = ppname_default } )) (comp_while ppname_default inv) | T_Par: g:env -> eL:st_term -> cL:comp { C_ST? cL } -> eR:st_term -> cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } -> x:var { None? (lookup g x) } -> // TODO: can comp_typing come from inversion of eL : cL and eR : cR? comp_typing_u g cL -> comp_typing_u g cR -> st_typing g eL cL -> st_typing g eR cR -> st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown; pre2=tm_unknown; body2=eR; post2=tm_unknown })) (comp_par cL cR x) | T_WithLocal: g:env -> binder_ppname:ppname -> init:term -> body:st_term -> init_t:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g init init_t -> universe_of g init_t u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) -> st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c | T_WithLocalArray: g:env -> binder_ppname:ppname -> initializer:term -> length:term -> body:st_term -> a:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g initializer a -> tot_typing g length tm_szt -> universe_of g a u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_array a)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x a initializer length c) -> st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c | T_Rewrite: g:env -> p:vprop -> q:vprop -> tot_typing g p tm_vprop -> vprop_equiv g p q -> st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } )) (comp_rewrite p q) | T_Admit: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None })) (comp_admit c s) | T_Unreachable: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> prop_validity g (tm_fstar (`False) FStar.Range.range_0) -> st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s) (* This limits the body to be atomic, rather than also allowing unobservable *) | T_WithInv: g:env -> inv_tm : term -> inv_vprop : vprop -> inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) -> body : st_term -> c : comp_st { C_STAtomic? c } -> body_typing : st_typing g body (add_frame c inv_vprop) -> inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) -> st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None})) (add_iname_at_least_unobservable c inv_vprop inv_tm) and pats_complete : env -> term -> typ -> list R.pattern -> Type0 = // just check the elaborated term with the core tc | PC_Elab : g:env -> sc:term -> sc_ty:typ -> pats:list R.pattern -> bnds:list (list R.binding) -> RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds -> pats_complete g sc sc_ty pats and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type = | TBRS_0 : c:comp_st -> brs_typing g sc_u sc_ty sc [] c | TBRS_1 : c:comp_st -> p:pattern -> e:st_term -> br_typing g sc_u sc_ty sc p e c -> rest:list branch -> brs_typing g sc_u sc_ty sc rest c -> brs_typing g sc_u sc_ty sc ((p,e)::rest) c and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type = | TBR : g:env -> sc_u : universe -> sc_ty : typ -> sc:term -> c:comp_st -> p:pattern -> e:st_term -> bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} -> _ : squash (all_fresh g (L.map readback_binding bs)) -> _ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) -> _ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} -> st_typing ( push_binding (push_bindings g (L.map readback_binding bs)) hyp ({name=Sealed.seal "branch equality"; range=FStar.Range.range_0}) (mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0)) ) e c -> br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c (* this requires some metatheory on FStar.Reflection.Typing G |- fv e : t G(fv) = t0 -> t1 G |- e : t0 G |- t1 <: t G |- e0 e1 : t ==> exists t0 t1. G |- e0 : t0 -> t1 /\ G |- e1 : t0 *) let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t0 tm_vprop = admit () let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t1 tm_vprop = admit () let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () let vprop_eq_typing_inversion g (t0 t1:term) (token:FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1)) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () (* These I can easily prove *) let star_typing (#g:_) (#t0 #t1:term) (d0:tot_typing g t0 tm_vprop) (d1:tot_typing g t1 tm_vprop) : tot_typing g (tm_star t0 t1) tm_vprop = admit () let emp_typing (#g:_) : tot_typing g tm_emp tm_vprop = admit ()
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Pulse.Syntax.Base.var -> g: Pulse.Typing.Env.env -> vars: FStar.Set.set Pulse.Syntax.Base.var -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.var", "Pulse.Typing.Env.env", "FStar.Set.set", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.lookup", "Prims.l_not", "FStar.Set.mem", "Prims.logical" ]
[]
false
false
false
true
true
let fresh_wrt (x: var) (g: env) (vars: _) =
None? (lookup g x) /\ ~(x `Set.mem` vars)
false
Pulse.Typing.fst
Pulse.Typing.tm_inames_subset
val tm_inames_subset (inames1 inames2: term) : term
val tm_inames_subset (inames1 inames2: term) : term
let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1)
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 538, "start_col": 0, "start_line": 532 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1)
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inames1: Pulse.Syntax.Base.term -> inames2: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term
Prims.Tot
[ "total" ]
[]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_FStar", "FStar.Reflection.V2.Derived.mk_e_app", "Prims.Cons", "FStar.Stubs.Reflection.Types.term", "Prims.Nil", "FStar.Stubs.Reflection.V2.Builtins.range_of_term", "FStar.Stubs.Reflection.V2.Builtins.pack_ln", "FStar.Stubs.Reflection.V2.Data.Tv_FVar", "FStar.Stubs.Reflection.V2.Builtins.pack_fv", "Prims.list", "Prims.string", "Pulse.Reflection.Util.mk_pulse_lib_core_lid", "Pulse.Elaborate.Pure.elab_term" ]
[]
false
false
false
true
false
let tm_inames_subset (inames1 inames2: term) : term =
let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join:R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1)
false
TwoLockQueue.fst
TwoLockQueue.enqueue
val enqueue (#a: _) (hdl: t a) (x: a) : SteelT unit emp (fun _ -> emp)
val enqueue (#a: _) (hdl: t a) (x: a) : SteelT unit emp (fun _ -> emp)
let enqueue (#a:_) (hdl:t a) (x:a) : SteelT unit emp (fun _ -> emp) = // Blocks until it can acquire the tail lock corresponding to the enqueuer Steel.SpinLock.acquire hdl.tail.lock; let cell = Q.({ data = x; next = null} ) in let v:erased (Q.t a) = open_exists () in let tl = read_pt hdl.tail.ptr in // Creates a new cell for the enqueued element let node = alloc_pt cell in // Core, atomic enqueue function, calling the concrete enqueue function while also // modifying ghost state to preserve the invariants let enqueue_core #u () : SteelAtomicT unit u (queue_invariant hdl.head hdl.tail `star` (ghost_pts_to hdl.tail.ghost half tl `star` pts_to node full cell)) (fun _ -> queue_invariant hdl.head hdl.tail `star` ghost_pts_to hdl.tail.ghost half node) = let open FStar.Ghost in let h = open_exists () in let t = open_exists () in ghost_gather tl hdl.tail.ghost; Q.enqueue tl node; ghost_write_pt hdl.tail.ghost node; ghost_share_pt #_ #_ hdl.tail.ghost; pack_queue_invariant h (hide node) hdl.head hdl.tail; return () in // Actually executing the atomic enqueue operation while preserving the global queue invariant let r1 = with_invariant hdl.inv enqueue_core in // Updates the queue tail pointer let r2 = write_pt hdl.tail.ptr node in // Updates the queue tail ghost state let r3 = intro_exists _ (fun (n:(Q.t a)) -> pts_to hdl.tail.ptr full_perm n `star` ghost_pts_to hdl.tail.ghost half n) in // Releases the tail lock corresponding to the enqueuer Steel.SpinLock.release hdl.tail.lock
{ "file_name": "share/steel/examples/steel/TwoLockQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 207, "start_col": 0, "start_line": 167 }
module TwoLockQueue open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.FractionalPermission open Steel.Reference open Steel.SpinLock module L = FStar.List.Tot module U = Steel.Utils module Q = Queue /// This module provides an implementation of Michael and Scott's two lock queue, using the /// abstract interface for queues provided in Queue.fsti. /// This implementation allows an enqueue and a dequeue operation to safely operate in parallel. /// There is a lock associated to both the enqueuer and the dequeuer, which guards each of those operation, /// ensuring that at most one enqueue (resp. dequeue) is happening at any time /// We only prove that this implementation is memory safe, and do not prove the functional correctness of the concurrent queue #push-options "--ide_id_info_off" /// Adding the definition of the vprop equivalence to the context, for proof purposes let _: squash (forall p q. p `equiv` q <==> hp_of p `Steel.Memory.equiv` hp_of q) = Classical.forall_intro_2 reveal_equiv (* Some wrappers to reduce clutter in the code *) [@@__reduce__] let full = full_perm [@@__reduce__] let half = half_perm full (* Wrappers around fst and snd to avoid overnormalization. TODO: The frame inference tactic should not normalize fst and snd *) let fst x = fst x let snd x = snd x (* Some wrappers around Steel functions which are easier to use inside this module *) let ghost_gather (#a:Type) (#u:_) (#p0 #p1:perm) (#p:perm{p == sum_perm p0 p1}) (x0 #x1:erased a) (r:ghost_ref a) : SteelGhost unit u (ghost_pts_to r p0 x0 `star` ghost_pts_to r p1 x1) (fun _ -> ghost_pts_to r p x0) (requires fun _ -> True) (ensures fun _ _ _ -> x0 == x1) = let _ = ghost_gather_pt #a #u #p0 #p1 r in () let rewrite #u (p q:vprop) : SteelGhost unit u p (fun _ -> q) (requires fun _ -> p `equiv` q) (ensures fun _ _ _ -> True) = rewrite_slprop p q (fun _ -> reveal_equiv p q) let elim_pure (#p:prop) #u () : SteelGhost unit u (pure p) (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let _ = Steel.Effect.Atomic.elim_pure p in () let open_exists (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit) : SteelGhostT (Ghost.erased a) opened_invariants (h_exists p) (fun r -> p (reveal r)) = let v : erased a = witness_exists () in v (*** Queue invariant ***) /// The invariant associated to the lock. Basically a variant of the /// Owicki-Gries invariant, but applied to queues [@@__reduce__] let lock_inv #a (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) = h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) let intro_lock_inv #a #u (ptr:ref (Q.t a)) (ghost:ghost_ref (Q.t a)) : SteelGhostT unit u (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (fun _ -> lock_inv ptr ghost) = assert_spinoff (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v) == lock_inv ptr ghost); rewrite_slprop (h_exists (fun (v:Q.t a) -> pts_to ptr full v `star` ghost_pts_to ghost half v)) (lock_inv _ _) (fun _ -> ()) /// The type of a queue pointer. /// Contains the concrete pointer [ptr], the pointer to ghost state [ghost], /// and a lock [lock] protecting the invariant relating the concrete and ghost states noeq type q_ptr (a:Type) = { ptr : ref (Q.t a); ghost: ghost_ref (Q.t a); lock: lock (lock_inv ptr ghost); } /// The global queue invariant, which will be shared by the enqueuer and the dequeuer. /// Again, inspired by the Owicki-Gries counter: It contains half the permission for the ghost /// state of the enqueuer and dequeuer, while ensuring that the concrete queue always remains /// a valid queue let queue_invariant (#a:_) ([@@@smt_fallback]head:q_ptr a) ([@@@smt_fallback] tail:q_ptr a) = h_exists (fun (h:Q.t a) -> h_exists (fun (t:Q.t a) -> ghost_pts_to head.ghost half h `star` ghost_pts_to tail.ghost half t `star` Q.queue h t)) let pack_queue_invariant (#a:_) (#u:_) (x:erased (Q.t a)) (y:erased (Q.t a)) (head tail:q_ptr a) : SteelGhostT unit u (ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y) (fun _ -> queue_invariant head tail) = intro_exists (reveal y) (fun y -> ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y); intro_exists (reveal x) (fun x -> h_exists (fun y -> ghost_pts_to head.ghost half x `star` ghost_pts_to tail.ghost half y `star` Q.queue x y)) /// The type of a queue. It contains a head and tail pointers, each with their own ghost state, /// as well as the global queue invariant [inv]. Note that compared to the locks in the head and tail /// pointers with type `q_ptr`, since invariant is a true Steel invariant, only accessible inside /// atomic computations noeq type t (a:Type0) = { head : q_ptr a; tail : q_ptr a; inv : inv (queue_invariant head tail) } /// Creating a new queue. let new_queue (#a:_) (x:a) : SteelT (t a) emp (fun _ -> emp) = let new_qptr (#a:_) (q:Q.t a) : SteelT (q_ptr a) emp (fun qp -> ghost_pts_to qp.ghost half q) = // Allocates the concrete pointer. let ptr = alloc_pt q in // Allocates the ghost state, and sets the corresponding lock invariant let ghost = ghost_alloc_pt q in ghost_share_pt ghost; intro_exists _ (fun q -> pts_to ptr full q `star` ghost_pts_to ghost half q); let lock = Steel.SpinLock.new_lock _ in { ptr; ghost; lock} in // Creating a concrete queue let hd = Q.new_queue x in // Creating the head and queue pointers let head = new_qptr hd in let tail = new_qptr hd in // Creating the global queue invariant pack_queue_invariant (hide hd) (hide hd) head tail; let inv = new_invariant _ in // Packing the different components to return a queue, as defined in type `t` return ({ head; tail; inv }) #restart-solver
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.Reference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Queue.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "TwoLockQueue.fst" }
[ { "abbrev": true, "full_module": "Queue", "short_module": "Q" }, { "abbrev": true, "full_module": "Steel.Utils", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hdl: TwoLockQueue.t a -> x: a -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "TwoLockQueue.t", "Steel.SpinLock.release", "TwoLockQueue.lock_inv", "TwoLockQueue.__proj__Mkq_ptr__item__ptr", "TwoLockQueue.__proj__Mkt__item__tail", "TwoLockQueue.__proj__Mkq_ptr__item__ghost", "TwoLockQueue.__proj__Mkq_ptr__item__lock", "Prims.unit", "Steel.Effect.Atomic.intro_exists", "Queue.Def.t", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Reference.ghost_pts_to", "TwoLockQueue.half", "Steel.Effect.Common.vprop", "Steel.Reference.write_pt", "Steel.Effect.Atomic.with_invariant", "Queue.Def.cell", "TwoLockQueue.full", "Steel.Effect.Common.Observable", "TwoLockQueue.queue_invariant", "TwoLockQueue.__proj__Mkt__item__head", "TwoLockQueue.__proj__Mkt__item__inv", "Steel.Effect.Common.add_inv", "Steel.Memory.inames", "FStar.Ghost.reveal", "FStar.Ghost.return", "TwoLockQueue.pack_queue_invariant", "Steel.Reference.ghost_share_pt", "Steel.Reference.ghost_write_pt", "Queue.enqueue", "TwoLockQueue.ghost_gather", "Steel.FractionalPermission.half_perm", "FStar.Ghost.erased", "TwoLockQueue.open_exists", "Steel.Effect.Common.VStar", "Queue.queue", "Steel.Effect.Atomic.h_exists", "Steel.Reference.ref", "Steel.Reference.alloc_pt", "Steel.Reference.read_pt", "Queue.Def.Mkcell", "Steel.Reference.null", "Steel.SpinLock.acquire", "Steel.Effect.Common.emp" ]
[]
false
true
false
false
false
let enqueue (#a: _) (hdl: t a) (x: a) : SteelT unit emp (fun _ -> emp) =
Steel.SpinLock.acquire hdl.tail.lock; let cell = let open Q in { data = x; next = null } in let v:erased (Q.t a) = open_exists () in let tl = read_pt hdl.tail.ptr in let node = alloc_pt cell in let enqueue_core #u () : SteelAtomicT unit u ((queue_invariant hdl.head hdl.tail) `star` ((ghost_pts_to hdl.tail.ghost half tl) `star` (pts_to node full cell))) (fun _ -> (queue_invariant hdl.head hdl.tail) `star` (ghost_pts_to hdl.tail.ghost half node)) = let open FStar.Ghost in let h = open_exists () in let t = open_exists () in ghost_gather tl hdl.tail.ghost; Q.enqueue tl node; ghost_write_pt hdl.tail.ghost node; ghost_share_pt #_ #_ hdl.tail.ghost; pack_queue_invariant h (hide node) hdl.head hdl.tail; return () in let r1 = with_invariant hdl.inv enqueue_core in let r2 = write_pt hdl.tail.ptr node in let r3 = intro_exists _ (fun (n: (Q.t a)) -> (pts_to hdl.tail.ptr full_perm n) `star` (ghost_pts_to hdl.tail.ghost half n)) in Steel.SpinLock.release hdl.tail.lock
false
Pulse.Typing.fst
Pulse.Typing.post_hint_opt
val post_hint_opt : g: Pulse.Typing.Env.env -> Type0
let post_hint_opt (g:env) = o:option post_hint_t { None? o \/ post_hint_for_env_p g (Some?.v o) }
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 97, "end_line": 1164, "start_col": 0, "start_line": 1164 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2) let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; } let tr_bindings = L.map tr_binding [@@ no_auto_projectors] noeq type comp_typing : env -> comp -> universe -> Type = | CT_Tot : g:env -> t:term -> u:universe -> universe_of g t u -> comp_typing g (C_Tot t) u | CT_ST : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_ST st) (universe_of_comp (C_ST st)) | CT_STAtomic : g:env -> inames:term -> obs:observability -> st:st_comp -> tot_typing g inames tm_inames -> st_comp_typing g st -> comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st)) | CT_STGhost : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) let subtyping_token g t1 t2 = T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) val readback_binding : R.binding -> binding let readback_binding b = assume (host_term == R.term); // fixme! expose this fact match readback_ty b.sort with | Some sort -> (b.uniq, sort) | None -> let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in (b.uniq, sort) let non_informative (g:env) (c:comp) = my_erased (RT.non_informative (elab_env g) (elab_comp c)) let inv_disjointness (inv_p inames inv:term) = let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range let eff_of_ctag = function | STT_Ghost -> T.E_Ghost | _ -> T.E_Total [@@ no_auto_projectors] noeq type st_typing : env -> st_term -> comp -> Type = | T_Abs: g:env -> x:var { None? (lookup g x) } -> q:option qualifier -> b:binder -> u:universe -> body:st_term {~ (x `Set.mem` freevars_st body) } -> c:comp -> tot_typing g b.binder_ty (tm_type u) -> st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c -> st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription})) (C_Tot (tm_arrow b q (close_comp c x))) | T_STApp : g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> tot_typing g head (tm_arrow (as_binder ty) q res) -> tot_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) // // this rule requires a non-informative judgment // for C_STGhost, this will always be the case // however, when doing the soundness proof, // we cannot call into the reflection API to get the token // may be there is another way to make it so that we can get this once-and-for-all // for C_STGhost // | T_STGhostApp: g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } -> ghost_typing g head (tm_arrow (as_binder ty) q res) -> non_informative (push_binding g x ppname_default ty) (open_comp_with res (null_var x)) -> ghost_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) | T_Return: g:env -> c:ctag -> use_eq:bool -> u:universe -> t:term -> e:term -> post:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } -> universe_of g t u -> typing g e (eff_of_ctag c) t -> tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop -> st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e })) (comp_return c use_eq u t e post x) | T_Lift: g:env -> e:st_term -> c1:comp_st -> c2:comp_st -> st_typing g e c1 -> lift_comp g c1 c2 -> st_typing g e c2 | T_Bind: g:env -> e1:st_term -> e2:st_term -> c1:comp_st -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> c:comp -> st_typing g e1 c1 -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> bind_comp g x c1 c2 c -> st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c | T_BindFn: g:env -> e1:st_term -> e2:st_term -> c1:comp { C_Tot? c1 } -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> st_typing g e1 c1 -> u:Ghost.erased universe -> tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> comp_typing_u g c2 -> st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2 | T_If: g:env -> b:term -> e1:st_term -> e2:st_term -> c:comp_st -> (* This is a little weird, we introduce a name hyp in the environment, but the branches are not allowed to use it (except perhaps in a silent way for proofs). Maybe more natural to have one free var in e1,e2 and to open it with hyp? But that's also a change to FStar.Reflection.Typing *) hyp:var { None? (lookup g hyp) /\ ~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2)) } -> tot_typing g b tm_bool -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c -> my_erased (comp_typing_u g c) -> st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c | T_Match : g:env -> sc_u:universe -> sc_ty:typ -> sc:term -> tot_typing g sc_ty (tm_type sc_u) -> tot_typing g sc sc_ty -> c:comp_st -> my_erased (comp_typing_u g c) -> brs:list (pattern & st_term) -> brs_typing g sc_u sc_ty sc brs c -> pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) -> st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c | T_Frame: g:env -> e:st_term -> c:comp_st -> frame:term -> tot_typing g frame tm_vprop -> st_typing g e c -> st_typing g e (add_frame c frame) | T_Equiv: g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_equiv g c c' -> st_typing g e c' | T_Sub : g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_sub g c c' -> st_typing g e c' | T_IntroPure: g:env -> p:term -> tot_typing g p tm_prop -> prop_validity g p -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p })) (comp_intro_pure p) | T_ElimExists: g:env -> u:universe -> t:term -> p:term -> x:var { None? (lookup g x) } -> tot_typing g t (tm_type u) -> tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop -> st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p })) (comp_elim_exists u t p (v_as_nv x)) | T_IntroExists: g:env -> u:universe -> b:binder -> p:term -> e:term -> tot_typing g b.binder_ty (tm_type u) -> tot_typing g (tm_exists_sl u b p) tm_vprop -> ghost_typing g e b.binder_ty -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p; witnesses= [e] })) (comp_intro_exists u b p e) | T_While: g:env -> inv:term -> cond:st_term -> body:st_term -> tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop -> st_typing g cond (comp_while_cond ppname_default inv) -> st_typing g body (comp_while_body ppname_default inv) -> st_typing g (wtag (Some STT) (Tm_While { invariant = inv; condition = cond; body; condition_var = ppname_default } )) (comp_while ppname_default inv) | T_Par: g:env -> eL:st_term -> cL:comp { C_ST? cL } -> eR:st_term -> cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } -> x:var { None? (lookup g x) } -> // TODO: can comp_typing come from inversion of eL : cL and eR : cR? comp_typing_u g cL -> comp_typing_u g cR -> st_typing g eL cL -> st_typing g eR cR -> st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown; pre2=tm_unknown; body2=eR; post2=tm_unknown })) (comp_par cL cR x) | T_WithLocal: g:env -> binder_ppname:ppname -> init:term -> body:st_term -> init_t:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g init init_t -> universe_of g init_t u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) -> st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c | T_WithLocalArray: g:env -> binder_ppname:ppname -> initializer:term -> length:term -> body:st_term -> a:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g initializer a -> tot_typing g length tm_szt -> universe_of g a u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_array a)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x a initializer length c) -> st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c | T_Rewrite: g:env -> p:vprop -> q:vprop -> tot_typing g p tm_vprop -> vprop_equiv g p q -> st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } )) (comp_rewrite p q) | T_Admit: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None })) (comp_admit c s) | T_Unreachable: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> prop_validity g (tm_fstar (`False) FStar.Range.range_0) -> st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s) (* This limits the body to be atomic, rather than also allowing unobservable *) | T_WithInv: g:env -> inv_tm : term -> inv_vprop : vprop -> inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) -> body : st_term -> c : comp_st { C_STAtomic? c } -> body_typing : st_typing g body (add_frame c inv_vprop) -> inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) -> st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None})) (add_iname_at_least_unobservable c inv_vprop inv_tm) and pats_complete : env -> term -> typ -> list R.pattern -> Type0 = // just check the elaborated term with the core tc | PC_Elab : g:env -> sc:term -> sc_ty:typ -> pats:list R.pattern -> bnds:list (list R.binding) -> RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds -> pats_complete g sc sc_ty pats and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type = | TBRS_0 : c:comp_st -> brs_typing g sc_u sc_ty sc [] c | TBRS_1 : c:comp_st -> p:pattern -> e:st_term -> br_typing g sc_u sc_ty sc p e c -> rest:list branch -> brs_typing g sc_u sc_ty sc rest c -> brs_typing g sc_u sc_ty sc ((p,e)::rest) c and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type = | TBR : g:env -> sc_u : universe -> sc_ty : typ -> sc:term -> c:comp_st -> p:pattern -> e:st_term -> bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} -> _ : squash (all_fresh g (L.map readback_binding bs)) -> _ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) -> _ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} -> st_typing ( push_binding (push_bindings g (L.map readback_binding bs)) hyp ({name=Sealed.seal "branch equality"; range=FStar.Range.range_0}) (mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0)) ) e c -> br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c (* this requires some metatheory on FStar.Reflection.Typing G |- fv e : t G(fv) = t0 -> t1 G |- e : t0 G |- t1 <: t G |- e0 e1 : t ==> exists t0 t1. G |- e0 : t0 -> t1 /\ G |- e1 : t0 *) let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t0 tm_vprop = admit () let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t1 tm_vprop = admit () let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () let vprop_eq_typing_inversion g (t0 t1:term) (token:FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1)) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () (* These I can easily prove *) let star_typing (#g:_) (#t0 #t1:term) (d0:tot_typing g t0 tm_vprop) (d1:tot_typing g t1 tm_vprop) : tot_typing g (tm_star t0 t1) tm_vprop = admit () let emp_typing (#g:_) : tot_typing g tm_emp tm_vprop = admit () let fresh_wrt (x:var) (g:env) (vars:_) = None? (lookup g x) /\ ~(x `Set.mem` vars) let effect_annot_typing (g:env) (e:effect_annot) = match e with | EffectAnnotAtomic { opens } -> tot_typing g opens tm_inames | _ -> unit noeq type post_hint_t = { g:env; effect_annot:effect_annot; effect_annot_typing:effect_annot_typing g effect_annot; ret_ty:term; u:universe; ty_typing:universe_of g ret_ty u; post:term; x:(x:var { fresh_wrt x g (freevars post) }); post_typing_src:tot_typing (push_binding g x ppname_default ret_ty) (open_term post x) tm_vprop; post_typing: FStar.Ghost.erased (RT.tot_typing (elab_env g) (RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post))) (RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop))) } let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] = env_extends_push g x ppname_default b
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Typing.Env.env -> Type0
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "FStar.Pervasives.Native.option", "Pulse.Typing.post_hint_t", "Prims.l_or", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "Pulse.Typing.post_hint_for_env_p", "FStar.Pervasives.Native.__proj__Some__item__v" ]
[]
false
false
false
true
true
let post_hint_opt (g: env) =
o: option post_hint_t {None? o \/ post_hint_for_env_p g (Some?.v o)}
false
Pulse.Typing.fst
Pulse.Typing.post_hint_for_env_extends
val post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
val post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)]
let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] = env_extends_push g x ppname_default b
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 41, "end_line": 1161, "start_col": 0, "start_line": 1156 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2) let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; } let tr_bindings = L.map tr_binding [@@ no_auto_projectors] noeq type comp_typing : env -> comp -> universe -> Type = | CT_Tot : g:env -> t:term -> u:universe -> universe_of g t u -> comp_typing g (C_Tot t) u | CT_ST : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_ST st) (universe_of_comp (C_ST st)) | CT_STAtomic : g:env -> inames:term -> obs:observability -> st:st_comp -> tot_typing g inames tm_inames -> st_comp_typing g st -> comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st)) | CT_STGhost : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) let subtyping_token g t1 t2 = T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) val readback_binding : R.binding -> binding let readback_binding b = assume (host_term == R.term); // fixme! expose this fact match readback_ty b.sort with | Some sort -> (b.uniq, sort) | None -> let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in (b.uniq, sort) let non_informative (g:env) (c:comp) = my_erased (RT.non_informative (elab_env g) (elab_comp c)) let inv_disjointness (inv_p inames inv:term) = let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range let eff_of_ctag = function | STT_Ghost -> T.E_Ghost | _ -> T.E_Total [@@ no_auto_projectors] noeq type st_typing : env -> st_term -> comp -> Type = | T_Abs: g:env -> x:var { None? (lookup g x) } -> q:option qualifier -> b:binder -> u:universe -> body:st_term {~ (x `Set.mem` freevars_st body) } -> c:comp -> tot_typing g b.binder_ty (tm_type u) -> st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c -> st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription})) (C_Tot (tm_arrow b q (close_comp c x))) | T_STApp : g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> tot_typing g head (tm_arrow (as_binder ty) q res) -> tot_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) // // this rule requires a non-informative judgment // for C_STGhost, this will always be the case // however, when doing the soundness proof, // we cannot call into the reflection API to get the token // may be there is another way to make it so that we can get this once-and-for-all // for C_STGhost // | T_STGhostApp: g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } -> ghost_typing g head (tm_arrow (as_binder ty) q res) -> non_informative (push_binding g x ppname_default ty) (open_comp_with res (null_var x)) -> ghost_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) | T_Return: g:env -> c:ctag -> use_eq:bool -> u:universe -> t:term -> e:term -> post:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } -> universe_of g t u -> typing g e (eff_of_ctag c) t -> tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop -> st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e })) (comp_return c use_eq u t e post x) | T_Lift: g:env -> e:st_term -> c1:comp_st -> c2:comp_st -> st_typing g e c1 -> lift_comp g c1 c2 -> st_typing g e c2 | T_Bind: g:env -> e1:st_term -> e2:st_term -> c1:comp_st -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> c:comp -> st_typing g e1 c1 -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> bind_comp g x c1 c2 c -> st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c | T_BindFn: g:env -> e1:st_term -> e2:st_term -> c1:comp { C_Tot? c1 } -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> st_typing g e1 c1 -> u:Ghost.erased universe -> tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> comp_typing_u g c2 -> st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2 | T_If: g:env -> b:term -> e1:st_term -> e2:st_term -> c:comp_st -> (* This is a little weird, we introduce a name hyp in the environment, but the branches are not allowed to use it (except perhaps in a silent way for proofs). Maybe more natural to have one free var in e1,e2 and to open it with hyp? But that's also a change to FStar.Reflection.Typing *) hyp:var { None? (lookup g hyp) /\ ~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2)) } -> tot_typing g b tm_bool -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c -> my_erased (comp_typing_u g c) -> st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c | T_Match : g:env -> sc_u:universe -> sc_ty:typ -> sc:term -> tot_typing g sc_ty (tm_type sc_u) -> tot_typing g sc sc_ty -> c:comp_st -> my_erased (comp_typing_u g c) -> brs:list (pattern & st_term) -> brs_typing g sc_u sc_ty sc brs c -> pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) -> st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c | T_Frame: g:env -> e:st_term -> c:comp_st -> frame:term -> tot_typing g frame tm_vprop -> st_typing g e c -> st_typing g e (add_frame c frame) | T_Equiv: g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_equiv g c c' -> st_typing g e c' | T_Sub : g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_sub g c c' -> st_typing g e c' | T_IntroPure: g:env -> p:term -> tot_typing g p tm_prop -> prop_validity g p -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p })) (comp_intro_pure p) | T_ElimExists: g:env -> u:universe -> t:term -> p:term -> x:var { None? (lookup g x) } -> tot_typing g t (tm_type u) -> tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop -> st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p })) (comp_elim_exists u t p (v_as_nv x)) | T_IntroExists: g:env -> u:universe -> b:binder -> p:term -> e:term -> tot_typing g b.binder_ty (tm_type u) -> tot_typing g (tm_exists_sl u b p) tm_vprop -> ghost_typing g e b.binder_ty -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p; witnesses= [e] })) (comp_intro_exists u b p e) | T_While: g:env -> inv:term -> cond:st_term -> body:st_term -> tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop -> st_typing g cond (comp_while_cond ppname_default inv) -> st_typing g body (comp_while_body ppname_default inv) -> st_typing g (wtag (Some STT) (Tm_While { invariant = inv; condition = cond; body; condition_var = ppname_default } )) (comp_while ppname_default inv) | T_Par: g:env -> eL:st_term -> cL:comp { C_ST? cL } -> eR:st_term -> cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } -> x:var { None? (lookup g x) } -> // TODO: can comp_typing come from inversion of eL : cL and eR : cR? comp_typing_u g cL -> comp_typing_u g cR -> st_typing g eL cL -> st_typing g eR cR -> st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown; pre2=tm_unknown; body2=eR; post2=tm_unknown })) (comp_par cL cR x) | T_WithLocal: g:env -> binder_ppname:ppname -> init:term -> body:st_term -> init_t:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g init init_t -> universe_of g init_t u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) -> st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c | T_WithLocalArray: g:env -> binder_ppname:ppname -> initializer:term -> length:term -> body:st_term -> a:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g initializer a -> tot_typing g length tm_szt -> universe_of g a u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_array a)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x a initializer length c) -> st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c | T_Rewrite: g:env -> p:vprop -> q:vprop -> tot_typing g p tm_vprop -> vprop_equiv g p q -> st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } )) (comp_rewrite p q) | T_Admit: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None })) (comp_admit c s) | T_Unreachable: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> prop_validity g (tm_fstar (`False) FStar.Range.range_0) -> st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s) (* This limits the body to be atomic, rather than also allowing unobservable *) | T_WithInv: g:env -> inv_tm : term -> inv_vprop : vprop -> inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) -> body : st_term -> c : comp_st { C_STAtomic? c } -> body_typing : st_typing g body (add_frame c inv_vprop) -> inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) -> st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None})) (add_iname_at_least_unobservable c inv_vprop inv_tm) and pats_complete : env -> term -> typ -> list R.pattern -> Type0 = // just check the elaborated term with the core tc | PC_Elab : g:env -> sc:term -> sc_ty:typ -> pats:list R.pattern -> bnds:list (list R.binding) -> RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds -> pats_complete g sc sc_ty pats and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type = | TBRS_0 : c:comp_st -> brs_typing g sc_u sc_ty sc [] c | TBRS_1 : c:comp_st -> p:pattern -> e:st_term -> br_typing g sc_u sc_ty sc p e c -> rest:list branch -> brs_typing g sc_u sc_ty sc rest c -> brs_typing g sc_u sc_ty sc ((p,e)::rest) c and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type = | TBR : g:env -> sc_u : universe -> sc_ty : typ -> sc:term -> c:comp_st -> p:pattern -> e:st_term -> bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} -> _ : squash (all_fresh g (L.map readback_binding bs)) -> _ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) -> _ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} -> st_typing ( push_binding (push_bindings g (L.map readback_binding bs)) hyp ({name=Sealed.seal "branch equality"; range=FStar.Range.range_0}) (mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0)) ) e c -> br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c (* this requires some metatheory on FStar.Reflection.Typing G |- fv e : t G(fv) = t0 -> t1 G |- e : t0 G |- t1 <: t G |- e0 e1 : t ==> exists t0 t1. G |- e0 : t0 -> t1 /\ G |- e1 : t0 *) let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t0 tm_vprop = admit () let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t1 tm_vprop = admit () let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () let vprop_eq_typing_inversion g (t0 t1:term) (token:FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1)) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () (* These I can easily prove *) let star_typing (#g:_) (#t0 #t1:term) (d0:tot_typing g t0 tm_vprop) (d1:tot_typing g t1 tm_vprop) : tot_typing g (tm_star t0 t1) tm_vprop = admit () let emp_typing (#g:_) : tot_typing g tm_emp tm_vprop = admit () let fresh_wrt (x:var) (g:env) (vars:_) = None? (lookup g x) /\ ~(x `Set.mem` vars) let effect_annot_typing (g:env) (e:effect_annot) = match e with | EffectAnnotAtomic { opens } -> tot_typing g opens tm_inames | _ -> unit noeq type post_hint_t = { g:env; effect_annot:effect_annot; effect_annot_typing:effect_annot_typing g effect_annot; ret_ty:term; u:universe; ty_typing:universe_of g ret_ty u; post:term; x:(x:var { fresh_wrt x g (freevars post) }); post_typing_src:tot_typing (push_binding g x ppname_default ret_ty) (open_term post x) tm_vprop; post_typing: FStar.Ghost.erased (RT.tot_typing (elab_env g) (RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post))) (RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop))) } let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Typing.Env.env -> p: Pulse.Typing.post_hint_t -> x: Pulse.Syntax.Base.var{~(FStar.Set.mem x (Pulse.Typing.Env.dom g))} -> b: Pulse.Syntax.Base.typ -> FStar.Pervasives.Lemma (requires Pulse.Typing.post_hint_for_env_p g p) (ensures Pulse.Typing.post_hint_for_env_p (Pulse.Typing.Env.push_binding g x Pulse.Syntax.Base.ppname_default b) p) [ SMTPat (Pulse.Typing.post_hint_for_env_p (Pulse.Typing.Env.push_binding g x Pulse.Syntax.Base.ppname_default b) p) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.post_hint_t", "Pulse.Syntax.Base.var", "Prims.l_not", "Prims.b2t", "FStar.Set.mem", "Pulse.Typing.Env.dom", "Pulse.Syntax.Base.typ", "Pulse.Typing.Env.env_extends_push", "Pulse.Syntax.Base.ppname_default", "Prims.unit", "Pulse.Typing.post_hint_for_env_p", "Prims.squash", "Pulse.Typing.Env.push_binding", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[]
true
false
true
false
false
let post_hint_for_env_extends (g: env) (p: post_hint_t) (x: var{~(Set.mem x (dom g))}) (b: typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] =
env_extends_push g x ppname_default b
false
Pulse.Typing.fst
Pulse.Typing.post_hint_typing
val post_hint_typing (g: env) (p: post_hint_for_env g) (x: var{fresh_wrt x g (freevars p.post)}) : post_hint_typing_t g p x
val post_hint_typing (g: env) (p: post_hint_for_env g) (x: var{fresh_wrt x g (freevars p.post)}) : post_hint_typing_t g p x
let post_hint_typing (g:env) (p:post_hint_for_env g) (x:var { fresh_wrt x g (freevars p.post) }) : post_hint_typing_t g p x = let effect_annot_typing : effect_annot_typing g p.effect_annot = match p.effect_annot with | EffectAnnotAtomic { opens } -> let opens_typing : tot_typing g opens tm_inames = RU.magic () in //weakening opens_typing | _ -> () in { effect_annot_typing; ty_typing = RU.magic (); //weakening post_typing = RU.magic (); }
{ "file_name": "lib/steel/pulse/Pulse.Typing.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 1191, "start_col": 0, "start_line": 1175 }
(* Copyright 2023 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Pulse.Typing module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 open Pulse.Reflection.Util open FStar.List.Tot open Pulse.Syntax module L = FStar.List.Tot module FTB = FStar.Tactics.V2 module RU = Pulse.RuntimeUtils module T= FStar.Tactics.V2 include Pulse.Typing.Env let debug_log (level:string) (g:env) (f: unit -> T.Tac string) : T.Tac unit = if RU.debug_at_level (fstar_env g) level then T.print (Printf.sprintf "Debug@%s:{ %s }\n" level (f ())) let tm_unit = tm_fvar (as_fv unit_lid) let tm_bool = tm_fvar (as_fv bool_lid) let tm_int = tm_fvar (as_fv int_lid) let tm_nat = tm_fvar (as_fv nat_lid) let tm_szt = tm_fvar (as_fv szt_lid) let tm_true = tm_constant R.C_True let tm_false = tm_constant R.C_False let tm_prop = with_range (Tm_FStar FStar.Reflection.Typing.tm_prop) Range.range_0 let mk_erased (u:universe) (t:term) : term = let hd = tm_uinst (as_fv erased_lid) [u] in tm_pureapp hd None t let mk_reveal (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv reveal_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_hide (u:universe) (t:term) (e:term) : term = let hd = tm_uinst (as_fv hide_lid) [u] in let hd = tm_pureapp hd (Some Implicit) t in tm_pureapp hd None e let mk_eq2 (u:universe) (t:term) (e0 e1:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv R.eq2_qn) [u]) (Some Implicit) t) None e0) None e1 let mk_sq_eq2 (u:universe) (t:term) (e0 e1:term) : term = let eq = mk_eq2 u t e0 e1 in (tm_pureapp (tm_uinst (as_fv R.squash_qn) [u]) None eq) let mk_vprop_eq (e0 e1:term) : term = mk_eq2 u2 tm_vprop e0 e1 let mk_ref (t:term) : term = tm_pureapp (tm_fvar (as_fv ref_lid)) None t let mk_pts_to (ty:term) (r:term) (v:term) : term = let t = tm_fvar (as_fv pts_to_lid) in let t = tm_pureapp t (Some Implicit) ty in let t = tm_pureapp t None r in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v let comp_return (c:ctag) (use_eq:bool) (u:universe) (t:term) (e:term) (post:term) (x:var) : comp = let post_maybe_eq = if use_eq then let post = open_term' post (null_var x) 0 in let post = tm_star post (tm_pure (mk_eq2 u t (null_var x) e)) in close_term post x else post in match c with | STT -> C_ST { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Atomic -> C_STAtomic tm_emp_inames Neutral { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } | STT_Ghost -> C_STGhost { u; res = t; pre = open_term' post e 0; post = post_maybe_eq } module L = FStar.List.Tot let extend_env_l (f:R.env) (g:env_bindings) : R.env = L.fold_right (fun (x, b) g -> let t = elab_term b in RT.extend_env g x t) g f let elab_env (e:env) : R.env = extend_env_l (fstar_env e) (bindings e) (* * If I call this fresh, I get: * Pulse.Typing.fst(545,0-546,20): (Error 162) The qualifier list "[assume]" is not permissible for this element: definitions cannot be assumed or marked with equality qualifiers * What!?!? Oh.. there's a fresh in Pulse.Typing.Env, which is *included*... *) let freshv (g:env) (x:var) : prop = None? (lookup g x) let rec all_fresh (g:env) (xs:list binding) : Tot prop (decreases xs) = match xs with | [] -> True | x::xs -> freshv g (fst x) /\ all_fresh (push_binding g (fst x) ppname_default (snd x)) xs let rec push_bindings (g:env) (bs:list binding{all_fresh g bs}) : Tot (g':env{env_extends g' g}) (decreases bs) = match bs with | [] -> g | (x,t)::bs -> push_bindings (push_binding g x ppname_default t) bs let elab_push_binding (g:env) (x:var { ~ (Set.mem x (dom g)) }) (t:typ) : Lemma (elab_env (push_binding g x ppname_default t) == RT.extend_env (elab_env g) x (elab_term t)) = () [@@ erasable; no_auto_projectors] noeq type vprop_equiv : env -> term -> term -> Type = | VE_Refl: g:env -> t:term -> vprop_equiv g t t | VE_Sym: g:env -> t1:term -> t2:term -> vprop_equiv g t1 t2 -> vprop_equiv g t2 t1 | VE_Trans: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g t0 t1 -> vprop_equiv g t1 t2 -> vprop_equiv g t0 t2 | VE_Ctxt: g:env -> t0:term -> t1:term -> t0':term -> t1':term -> vprop_equiv g t0 t0' -> vprop_equiv g t1 t1' -> vprop_equiv g (tm_star t0 t1) (tm_star t0' t1') | VE_Unit: (* *) g:env -> t:term -> vprop_equiv g (tm_star tm_emp t) t | VE_Comm: g:env -> t0:term -> t1:term -> vprop_equiv g (tm_star t0 t1) (tm_star t1 t0) | VE_Assoc: g:env -> t0:term -> t1:term -> t2:term -> vprop_equiv g (tm_star t0 (tm_star t1 t2)) (tm_star (tm_star t0 t1) t2) | VE_Ext: g:env -> t0:term -> t1:term -> FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1) -> vprop_equiv g t0 t1 // | VE_Ex: // g:env -> // x:var { None? (lookup_ty g x) } -> // ty:term -> // t0:term -> // t1:term -> // vprop_equiv f ((x, Inl ty)::g) (open_term t0 x) (open_term t1 x) -> // vprop_equiv f g (tm_exists_sl ty t0) (tm_exists_sl ty t1) | VE_Fa: g:env -> x:var { None? (lookup g x) } -> u:universe -> b:binder -> t0:term { ~(x `Set.mem` freevars t0 ) } -> t1:term { ~(x `Set.mem` freevars t1 ) } -> vprop_equiv (push_binding g x ppname_default b.binder_ty) (open_term t0 x) (open_term t1 x) -> vprop_equiv g (tm_forall_sl u b t0) (tm_forall_sl u b t1) let add_frame (s:comp_st) (frame:term) : comp_st = let add_frame_s (s:st_comp) : st_comp = { s with pre = tm_star s.pre frame; post = tm_star s.post frame } in match s with | C_ST s -> C_ST (add_frame_s s) | C_STAtomic inames obs s -> C_STAtomic inames obs (add_frame_s s) | C_STGhost s -> C_STGhost (add_frame_s s) let add_inv (s:comp_st) (v:vprop) : comp_st = add_frame s v let at_most_one_observable o1 o2 = match o1, o2 with | Observable, Observable -> false | _ -> true let join_obs (o1 o2:observability) : observability = match o1, o2 with | Neutral, o | o, Neutral -> o | Observable, _ -> Observable | _, Observable -> Observable | Unobservable, Unobservable -> Unobservable let add_iname_at_least_unobservable (s:comp_st {C_STAtomic? s}) (inv_vprop inv_tm:term) = let add_inv_tm (inames:term) = tm_fstar (Pulse.Reflection.Util.add_inv_tm (elab_term inv_vprop) (elab_term inames) (elab_term inv_tm)) inames.range in let C_STAtomic inames obs s = s in C_STAtomic (add_inv_tm inames) (join_obs obs Unobservable) s let bind_comp_compatible (c1 c2:comp_st) : prop = match c1, c2 with | C_ST _, C_ST _ | C_STGhost _, C_STGhost _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ at_most_one_observable obs1 obs2 | _, _ -> False let bind_comp_pre (x:var) (c1 c2:comp_st) : prop = open_term (comp_post c1) x == comp_pre c2 /\ (~ (x `Set.mem` freevars (comp_post c2))) /\ //x doesn't escape in the result type bind_comp_compatible c1 c2 let bind_comp_out (c1:comp_st) (c2:comp_st{bind_comp_compatible c1 c2}) : comp_st = let s : st_comp = {u=comp_u c2; res=comp_res c2; pre=comp_pre c1; post=comp_post c2} in match c1, c2 with | C_STGhost _, C_STGhost _ -> C_STGhost s | C_STAtomic inames obs1 _, C_STAtomic _ obs2 _ -> C_STAtomic inames (join_obs obs1 obs2) s | C_ST _, C_ST _ -> C_ST s let st_equiv_pre (c1 c2:comp_st) : prop = comp_u c1 == comp_u c2 /\ (match c1, c2 with | C_ST _, C_ST _ -> True | C_STAtomic inames1 obs1 _, C_STAtomic inames2 obs2 _ -> inames1 == inames2 /\ obs1 == obs2 | C_STGhost _, C_STGhost _ -> True | _, _ -> False) let non_informative_witness_t (u:universe) (t:term) : term = tm_pureapp (tm_uinst (as_fv non_informative_witness_lid) [u]) None t let elim_exists_post (u:universe) (t:term) (p:term) (x:nvar) : term = let x_tm = term_of_nvar x in let p = open_term' p (mk_reveal u t x_tm) 0 in close_term p (snd x) let comp_elim_exists (u:universe) (t:term) (p:term) (x:nvar) : comp = C_STGhost { u=u; res=mk_erased u t; pre=tm_exists_sl u (as_binder t) p; post=elim_exists_post u t p x } let comp_intro_pure (p:term) = C_STGhost { u=u_zero; res=tm_unit; pre=tm_emp; post=tm_pure p } let named_binder (x:ppname) (t:term) = mk_binder_ppname t x let comp_intro_exists (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p e 0; post=tm_exists_sl u b p } let comp_intro_exists_erased (u:universe) (b:binder) (p:term) (e:term) : comp = C_STGhost { u=u0; res=tm_unit; pre=open_term' p (mk_reveal u b.binder_ty e) 0; post=tm_exists_sl u b p } let comp_while_cond (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_bool; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=inv } let comp_while_body (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=open_term' inv tm_true 0; post=tm_exists_sl u0 (named_binder x tm_bool) inv } let comp_while (x:ppname) (inv:term) : comp = C_ST { u=u0; res=tm_unit; pre=tm_exists_sl u0 (named_binder x tm_bool) inv; post=open_term' inv tm_false 0 } let mk_tuple2 (u1 u2:universe) (t1 t2:term) : term = tm_pureapp (tm_pureapp (tm_uinst (as_fv tuple2_lid) [u1; u2]) None t1) None t2 let mk_fst (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv fst_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let mk_snd (u1 u2:universe) (a1 a2 e:term) : term = tm_pureapp (tm_pureapp (tm_pureapp (tm_uinst (as_fv snd_lid) [u1; u2]) (Some Implicit) a1) (Some Implicit) a2) None e let par_post (uL uR:universe) (aL aR postL postR:term) (x:var) : term = let x_tm = term_of_no_name_var x in let postL = open_term' postL (mk_fst uL uR aL aR x_tm) 0 in let postR = open_term' postR (mk_snd uL uR aL aR x_tm) 0 in let post = tm_star postL postR in close_term post x let comp_par (cL:comp{C_ST? cL}) (cR:comp{C_ST? cR}) (x:var) : comp = let uL = comp_u cL in let uR = comp_u cR in let aL = comp_res cL in let aR = comp_res cR in let post = par_post uL uR aL aR (comp_post cL) (comp_post cR) x in C_ST { u = uL; res = mk_tuple2 uL uR aL aR; pre = tm_star (comp_pre cL) (comp_pre cR); post } let comp_withlocal_body_pre (pre:vprop) (init_t:term) (r:term) (init:term) : vprop = tm_star pre (mk_pts_to init_t r init) let comp_withlocal_body_post (post:term) (init_t:term) (r:term) : term = tm_star post (tm_exists_sl u0 (as_binder init_t) (mk_pts_to init_t r (null_bvar 0))) let comp_withlocal_body (r:var) (init_t:term) (init:term) (c:comp{C_ST? c}) : comp = let r = null_var r in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_body_pre (comp_pre c) init_t r init; post = comp_withlocal_body_post (comp_post c) init_t r } let mk_array (a:term) : term = tm_pureapp (tm_fvar (as_fv array_lid)) None a let mk_array_length (a:term) (arr:term) : term = let t = tm_fvar (as_fv array_length_lid) in let t = tm_pureapp t (Some Implicit) a in tm_pureapp t None arr let mk_array_pts_to (a:term) (arr:term) (v:term) : term = let t = tm_fvar (as_fv array_pts_to_lid) in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None arr in let t = tm_pureapp t (Some Implicit) (tm_fvar (as_fv full_perm_lid)) in tm_pureapp t None v // let mk_array_is_full (a:term) (arr:term) : term = // let t = tm_fvar (as_fv array_is_full_lid) in // let t = tm_pureapp t (Some Implicit) a in // tm_pureapp t None arr let mk_seq_create (u:universe) (a:term) (len:term) (v:term) : term = let t = tm_uinst (as_fv seq_create_lid) [u] in let t = tm_pureapp t (Some Implicit) a in let t = tm_pureapp t None len in tm_pureapp t None v let mk_szv (n:term) : term = let t = tm_fvar (as_fv szv_lid) in tm_pureapp t None n let comp_withlocal_array_body_pre (pre:vprop) (a:term) (arr:term) (init:term) (len:term) : vprop = tm_star pre (tm_star (mk_array_pts_to a arr (mk_seq_create u0 a (mk_szv len) init)) (tm_pure (mk_eq2 u0 tm_nat (mk_array_length a arr) (mk_szv len)))) let mk_seq (u:universe) (a:term) : term = let t = tm_uinst (as_fv seq_lid) [u] in tm_pureapp t None a let comp_withlocal_array_body_post (post:term) (a:term) (arr:term) : term = tm_star post (tm_exists_sl u0 (as_binder (mk_seq u0 a)) (mk_array_pts_to a arr (null_bvar 0))) let comp_withlocal_array_body (arr:var) (a:term) (init:term) (len:term) (c:comp{C_ST? c}) : comp = let arr = null_var arr in C_ST { u = comp_u c; res = comp_res c; pre = comp_withlocal_array_body_pre (comp_pre c) a arr init len; post = comp_withlocal_array_body_post (comp_post c) a arr } let comp_rewrite (p q:vprop) : comp = C_STGhost { u = u0; res = tm_unit; pre = p; post = q; } let comp_admit (c:ctag) (s:st_comp) : comp = match c with | STT -> C_ST s | STT_Atomic -> C_STAtomic tm_emp_inames Neutral s | STT_Ghost -> C_STGhost s [@@erasable] noeq type my_erased (a:Type) = | E of a let typing (g:env) (e:term) (eff:T.tot_or_ghost) (t:term) = my_erased (RT.typing (elab_env g) (elab_term e) (eff, elab_term t)) let tot_typing (g:env) (e:term) (t:term) = typing g e T.E_Total t let ghost_typing (g:env) (e:term) (t:typ) = typing g e T.E_Ghost t let lift_typing_to_ghost_typing (#g:env) (#e:term) (#eff:T.tot_or_ghost) (#t:term) (d:typing g e eff t) : ghost_typing g e t = if eff = T.E_Ghost then d else let E d = d in E (RT.T_Sub _ _ _ _ d (RT.Relc_total_ghost _ _)) let universe_of (g:env) (t:term) (u:universe) = tot_typing g t (tm_type u) let non_informative_t (g:env) (u:universe) (t:term) = w:term & tot_typing g w (non_informative_witness_t u t) let non_informative_c (g:env) (c:comp_st) = non_informative_t g (comp_u c) (comp_res c) // TODO: move let tm_join_inames (inames1 inames2 : term) : term = if eq_tm inames1 tm_emp_inames then inames2 else if eq_tm inames2 tm_emp_inames then inames1 else if eq_tm inames1 inames2 then inames1 else let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "join_inames" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset (inames1 inames2 : term) : term = let inames1 = elab_term inames1 in let inames2 = elab_term inames2 in let join_lid = Pulse.Reflection.Util.mk_pulse_lib_core_lid "inames_subset" in let join : R.term = R.pack_ln (R.Tv_FVar (R.pack_fv join_lid)) in with_range (Tm_FStar (R.mk_e_app join [inames1; inames2])) (T.range_of_term inames1) let tm_inames_subset_typing (g:env) (inames1 inames2 : term) : tot_typing g (tm_inames_subset inames1 inames2) tm_prop = (* Need to add the typing hypothesis for `inames_subset` to the env and a precondition that the inames have type Pulse.Lib.Core.inames in g, which the caller should get from an inversion lemma *) RU.magic() let prop_validity (g:env) (t:term) = FTB.prop_validity_token (elab_env g) (elab_term t) [@@ no_auto_projectors] noeq type st_equiv : env -> comp -> comp -> Type = | ST_VPropEquiv : g:env -> c1:comp_st -> c2:comp_st { st_equiv_pre c1 c2 } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars (comp_post c1)) /\ ~(x `Set.mem` freevars (comp_post c2)) } -> tot_typing g (comp_pre c1) tm_vprop -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> tot_typing (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) tm_vprop -> RT.equiv (elab_env g) (elab_term (comp_res c1)) (elab_term (comp_res c2)) -> vprop_equiv g (comp_pre c1) (comp_pre c2) -> vprop_equiv (push_binding g x ppname_default (comp_res c1)) (open_term (comp_post c1) x) (open_term (comp_post c2) x) -> st_equiv g c1 c2 | ST_TotEquiv : g:env -> t1:term -> t2:term -> u:_ -> universe_of g t1 u -> Ghost.erased (RT.equiv (elab_env g) (elab_term t1) (elab_term t2)) -> st_equiv g (C_Tot t1) (C_Tot t2) let sub_observability (o1 o2:observability) = o1 = Neutral || o1 = o2 || o2 = Observable [@@ no_auto_projectors] noeq type st_sub : env -> comp -> comp -> Type = | STS_Refl : g:env -> c:comp -> st_sub g c c | STS_Trans : g:env -> c1:comp -> c2:comp -> c3:comp -> st_sub g c1 c2 -> st_sub g c2 c3 -> st_sub g c1 c3 | STS_AtomicInvs : g:env -> stc:st_comp -> is1:term -> is2:term -> obs1:observability -> obs2:observability { sub_observability obs1 obs2 } -> prop_validity g (tm_inames_subset is1 is2) -> st_sub g (C_STAtomic is1 obs1 stc) (C_STAtomic is2 obs2 stc) [@@ no_auto_projectors] noeq type lift_comp : env -> comp -> comp -> Type = | Lift_STAtomic_ST : g:env -> c:comp_st{C_STAtomic? c} -> // Note: we have to reflect a univerese bound here! lift_comp g c (C_ST (st_comp_of_comp c)) | Lift_Observability: g:env -> c:comp_st{C_STAtomic? c } -> o2:observability { sub_observability (C_STAtomic?.obs c) o2 } -> lift_comp g (C_STAtomic (comp_inames c) (C_STAtomic?.obs c) (st_comp_of_comp c)) (C_STAtomic (comp_inames c) o2 (st_comp_of_comp c)) | Lift_Ghost_Neutral: g:env -> c:comp_st{C_STGhost? c} -> non_informative_c:non_informative_c g c -> lift_comp g c (C_STAtomic tm_emp_inames Neutral (st_comp_of_comp c)) | Lift_Neutral_Ghost: g:env -> c:comp_st{C_STAtomic? c /\ C_STAtomic?.obs c == Neutral } -> lift_comp g c (C_STGhost (st_comp_of_comp c)) let wr (ct:comp_st) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = as_effect_hint (ctag_of_comp_st ct) } let wtag (ct:option ctag) (t:st_term') : st_term = { term = t; range = FStar.Range.range_0; effect_tag = FStar.Sealed.seal ct } [@@ no_auto_projectors] noeq type st_comp_typing : env -> st_comp -> Type = | STC: g:env -> st:st_comp -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars st.post) } -> universe_of g st.res st.u -> tot_typing g st.pre tm_vprop -> tot_typing (push_binding g x ppname_default st.res) (open_term st.post x) tm_vprop -> st_comp_typing g st [@@ no_auto_projectors] noeq type bind_comp : env -> var -> comp -> comp -> comp -> Type = | Bind_comp : // (C_ST and C_ST) or (C_STGhost and C_STGhost) or (C_STAtomic and C_STAtomic) g:env -> x:var { None? (lookup g x) } -> c1:comp_st -> c2:comp_st {bind_comp_pre x c1 c2} -> universe_of g (comp_res c2) (comp_u c2) -> //or in the result post; free var check isn't enough; we need typability y:var { None? (lookup g y) /\ ~(y `Set.mem` freevars (comp_post c2)) } -> tot_typing (push_binding g y ppname_default (comp_res c2)) (open_term (comp_post c2) y) tm_vprop -> bind_comp g x c1 c2 (bind_comp_out c1 c2) let tr_binding (vt : var & typ) : Tot R.binding = let v, t = vt in { uniq = v; sort = elab_term t; ppname = ppname_default.name; } let tr_bindings = L.map tr_binding [@@ no_auto_projectors] noeq type comp_typing : env -> comp -> universe -> Type = | CT_Tot : g:env -> t:term -> u:universe -> universe_of g t u -> comp_typing g (C_Tot t) u | CT_ST : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_ST st) (universe_of_comp (C_ST st)) | CT_STAtomic : g:env -> inames:term -> obs:observability -> st:st_comp -> tot_typing g inames tm_inames -> st_comp_typing g st -> comp_typing g (C_STAtomic inames obs st) (universe_of_comp (C_STAtomic inames obs st)) | CT_STGhost : g:env -> st:st_comp -> st_comp_typing g st -> comp_typing g (C_STGhost st) (universe_of_comp (C_STGhost st)) let comp_typing_u (e:env) (c:comp_st) = comp_typing e c (universe_of_comp c) let subtyping_token g t1 t2 = T.subtyping_token (elab_env g) (elab_term t1) (elab_term t2) val readback_binding : R.binding -> binding let readback_binding b = assume (host_term == R.term); // fixme! expose this fact match readback_ty b.sort with | Some sort -> (b.uniq, sort) | None -> let sort : term = {t=Tm_FStar b.sort; range=T.range_of_term b.sort} in (b.uniq, sort) let non_informative (g:env) (c:comp) = my_erased (RT.non_informative (elab_env g) (elab_comp c)) let inv_disjointness (inv_p inames inv:term) = let g = Pulse.Reflection.Util.inv_disjointness_goal (elab_term inv_p) (elab_term inames) (elab_term inv) in tm_fstar g inv.range let eff_of_ctag = function | STT_Ghost -> T.E_Ghost | _ -> T.E_Total [@@ no_auto_projectors] noeq type st_typing : env -> st_term -> comp -> Type = | T_Abs: g:env -> x:var { None? (lookup g x) } -> q:option qualifier -> b:binder -> u:universe -> body:st_term {~ (x `Set.mem` freevars_st body) } -> c:comp -> tot_typing g b.binder_ty (tm_type u) -> st_typing (push_binding g x ppname_default b.binder_ty) (open_st_term_nv body (b.binder_ppname, x)) c -> st_typing g (wtag None (Tm_Abs { b; q; body; ascription=empty_ascription})) (C_Tot (tm_arrow b q (close_comp c x))) | T_STApp : g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> tot_typing g head (tm_arrow (as_binder ty) q res) -> tot_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) // // this rule requires a non-informative judgment // for C_STGhost, this will always be the case // however, when doing the soundness proof, // we cannot call into the reflection API to get the token // may be there is another way to make it so that we can get this once-and-for-all // for C_STGhost // | T_STGhostApp: g:env -> head:term -> ty:term -> q:option qualifier -> res:comp_st -> arg:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars_comp res) } -> ghost_typing g head (tm_arrow (as_binder ty) q res) -> non_informative (push_binding g x ppname_default ty) (open_comp_with res (null_var x)) -> ghost_typing g arg ty -> st_typing g (wr res (Tm_STApp {head; arg_qual=q; arg})) (open_comp_with res arg) | T_Return: g:env -> c:ctag -> use_eq:bool -> u:universe -> t:term -> e:term -> post:term -> x:var { None? (lookup g x) /\ ~ (x `Set.mem` freevars post) } -> universe_of g t u -> typing g e (eff_of_ctag c) t -> tot_typing (push_binding g x ppname_default t) (open_term post x) tm_vprop -> st_typing g (wtag (Some c) (Tm_Return { expected_type=tm_unknown; insert_eq=use_eq; term=e })) (comp_return c use_eq u t e post x) | T_Lift: g:env -> e:st_term -> c1:comp_st -> c2:comp_st -> st_typing g e c1 -> lift_comp g c1 c2 -> st_typing g e c2 | T_Bind: g:env -> e1:st_term -> e2:st_term -> c1:comp_st -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> c:comp -> st_typing g e1 c1 -> tot_typing g (comp_res c1) (tm_type (comp_u c1)) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> bind_comp g x c1 c2 c -> st_typing g (wr c (Tm_Bind { binder=b; head=e1; body=e2 })) c | T_BindFn: g:env -> e1:st_term -> e2:st_term -> c1:comp { C_Tot? c1 } -> c2:comp_st -> b:binder { b.binder_ty == comp_res c1 }-> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st e2) } -> st_typing g e1 c1 -> u:Ghost.erased universe -> tot_typing g (comp_res c1) (tm_type u) -> //type-correctness; would be nice to derive it instead st_typing (push_binding g x ppname_default (comp_res c1)) (open_st_term_nv e2 (b.binder_ppname, x)) c2 -> comp_typing_u g c2 -> st_typing g (wr c2 (Tm_Bind { binder=b; head=e1; body=e2 })) c2 | T_If: g:env -> b:term -> e1:st_term -> e2:st_term -> c:comp_st -> (* This is a little weird, we introduce a name hyp in the environment, but the branches are not allowed to use it (except perhaps in a silent way for proofs). Maybe more natural to have one free var in e1,e2 and to open it with hyp? But that's also a change to FStar.Reflection.Typing *) hyp:var { None? (lookup g hyp) /\ ~(hyp `Set.mem` (freevars_st e1 `Set.union` freevars_st e2)) } -> tot_typing g b tm_bool -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_true)) e1 c -> st_typing (push_binding g hyp ppname_default (mk_eq2 u0 tm_bool b tm_false)) e2 c -> my_erased (comp_typing_u g c) -> st_typing g (wr c (Tm_If { b; then_=e1; else_=e2; post=None })) c | T_Match : g:env -> sc_u:universe -> sc_ty:typ -> sc:term -> tot_typing g sc_ty (tm_type sc_u) -> tot_typing g sc sc_ty -> c:comp_st -> my_erased (comp_typing_u g c) -> brs:list (pattern & st_term) -> brs_typing g sc_u sc_ty sc brs c -> pats_complete g sc sc_ty (L.map (fun (p, _) -> elab_pat p) brs) -> st_typing g (wr c (Tm_Match {sc; returns_=None; brs})) c | T_Frame: g:env -> e:st_term -> c:comp_st -> frame:term -> tot_typing g frame tm_vprop -> st_typing g e c -> st_typing g e (add_frame c frame) | T_Equiv: g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_equiv g c c' -> st_typing g e c' | T_Sub : g:env -> e:st_term -> c:comp -> c':comp -> st_typing g e c -> st_sub g c c' -> st_typing g e c' | T_IntroPure: g:env -> p:term -> tot_typing g p tm_prop -> prop_validity g p -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroPure { p })) (comp_intro_pure p) | T_ElimExists: g:env -> u:universe -> t:term -> p:term -> x:var { None? (lookup g x) } -> tot_typing g t (tm_type u) -> tot_typing g (tm_exists_sl u (as_binder t) p) tm_vprop -> st_typing g (wtag (Some STT_Ghost) (Tm_ElimExists { p = tm_exists_sl u (as_binder t) p })) (comp_elim_exists u t p (v_as_nv x)) | T_IntroExists: g:env -> u:universe -> b:binder -> p:term -> e:term -> tot_typing g b.binder_ty (tm_type u) -> tot_typing g (tm_exists_sl u b p) tm_vprop -> ghost_typing g e b.binder_ty -> st_typing g (wtag (Some STT_Ghost) (Tm_IntroExists { p = tm_exists_sl u b p; witnesses= [e] })) (comp_intro_exists u b p e) | T_While: g:env -> inv:term -> cond:st_term -> body:st_term -> tot_typing g (tm_exists_sl u0 (as_binder tm_bool) inv) tm_vprop -> st_typing g cond (comp_while_cond ppname_default inv) -> st_typing g body (comp_while_body ppname_default inv) -> st_typing g (wtag (Some STT) (Tm_While { invariant = inv; condition = cond; body; condition_var = ppname_default } )) (comp_while ppname_default inv) | T_Par: g:env -> eL:st_term -> cL:comp { C_ST? cL } -> eR:st_term -> cR:comp { C_ST? cR /\ comp_u cL == comp_u cR } -> x:var { None? (lookup g x) } -> // TODO: can comp_typing come from inversion of eL : cL and eR : cR? comp_typing_u g cL -> comp_typing_u g cR -> st_typing g eL cL -> st_typing g eR cR -> st_typing g (wr cL (Tm_Par { pre1=tm_unknown; body1=eL; post1=tm_unknown; pre2=tm_unknown; body2=eR; post2=tm_unknown })) (comp_par cL cR x) | T_WithLocal: g:env -> binder_ppname:ppname -> init:term -> body:st_term -> init_t:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g init init_t -> universe_of g init_t u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_ref init_t)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_body x init_t init c) -> st_typing g (wr c (Tm_WithLocal { binder = mk_binder_ppname (mk_ref init_t) binder_ppname; initializer=init; body } )) c | T_WithLocalArray: g:env -> binder_ppname:ppname -> initializer:term -> length:term -> body:st_term -> a:term -> c:comp { C_ST? c } -> x:var { None? (lookup g x) /\ ~(x `Set.mem` freevars_st body) } -> tot_typing g initializer a -> tot_typing g length tm_szt -> universe_of g a u0 -> comp_typing_u g c -> st_typing (push_binding g x ppname_default (mk_array a)) (open_st_term_nv body (v_as_nv x)) (comp_withlocal_array_body x a initializer length c) -> st_typing g (wr c (Tm_WithLocalArray { binder = mk_binder_ppname (mk_array a) binder_ppname; initializer; length; body } )) c | T_Rewrite: g:env -> p:vprop -> q:vprop -> tot_typing g p tm_vprop -> vprop_equiv g p q -> st_typing g (wtag (Some STT_Ghost) (Tm_Rewrite { t1=p; t2=q } )) (comp_rewrite p q) | T_Admit: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> st_typing g (wtag (Some c) (Tm_Admit { ctag=c; u=s.u; typ=s.res; post=None })) (comp_admit c s) | T_Unreachable: g:env -> s:st_comp -> c:ctag -> st_comp_typing g s -> prop_validity g (tm_fstar (`False) FStar.Range.range_0) -> st_typing g (wtag (Some c) Tm_Unreachable) (comp_admit c s) (* This limits the body to be atomic, rather than also allowing unobservable *) | T_WithInv: g:env -> inv_tm : term -> inv_vprop : vprop -> inv_vprop_typing : tot_typing g inv_vprop tm_vprop -> // could be ghost inv_typing : tot_typing g inv_tm (tm_inv inv_vprop) -> body : st_term -> c : comp_st { C_STAtomic? c } -> body_typing : st_typing g body (add_frame c inv_vprop) -> inv_disjointness_token:prop_validity g (inv_disjointness inv_vprop (comp_inames c) inv_tm) -> st_typing g (wtag (Some STT_Atomic) (Tm_WithInv {name=inv_tm; body; returns_inv=None})) (add_iname_at_least_unobservable c inv_vprop inv_tm) and pats_complete : env -> term -> typ -> list R.pattern -> Type0 = // just check the elaborated term with the core tc | PC_Elab : g:env -> sc:term -> sc_ty:typ -> pats:list R.pattern -> bnds:list (list R.binding) -> RT.match_is_complete (elab_env g) (elab_term sc) (elab_term sc_ty) pats bnds -> pats_complete g sc sc_ty pats and brs_typing (g:env) (sc_u:universe) (sc_ty:typ) (sc:term) : list branch -> comp_st -> Type = | TBRS_0 : c:comp_st -> brs_typing g sc_u sc_ty sc [] c | TBRS_1 : c:comp_st -> p:pattern -> e:st_term -> br_typing g sc_u sc_ty sc p e c -> rest:list branch -> brs_typing g sc_u sc_ty sc rest c -> brs_typing g sc_u sc_ty sc ((p,e)::rest) c and br_typing : env -> universe -> typ -> term -> pattern -> st_term -> comp_st -> Type = | TBR : g:env -> sc_u : universe -> sc_ty : typ -> sc:term -> c:comp_st -> p:pattern -> e:st_term -> bs:(list R.binding){RT.bindings_ok_for_pat (fstar_env g) bs (elab_pat p)} -> _ : squash (all_fresh g (L.map readback_binding bs)) -> _ : squash (Some? (RT.elaborate_pat (elab_pat p) bs)) -> _ : squash (~(R.Tv_Unknown? (R.inspect_ln (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs)))))) -> // should be provable from defn of elaborate_pat hyp:var {freshv (push_bindings g (L.map readback_binding bs)) hyp} -> st_typing ( push_binding (push_bindings g (L.map readback_binding bs)) hyp ({name=Sealed.seal "branch equality"; range=FStar.Range.range_0}) (mk_sq_eq2 sc_u sc_ty sc (tm_fstar (fst (Some?.v (RT.elaborate_pat (elab_pat p) bs))) Range.range_0)) ) e c -> br_typing g sc_u sc_ty sc p (close_st_term_n e (L.map fst (L.map readback_binding bs))) c (* this requires some metatheory on FStar.Reflection.Typing G |- fv e : t G(fv) = t0 -> t1 G |- e : t0 G |- t1 <: t G |- e0 e1 : t ==> exists t0 t1. G |- e0 : t0 -> t1 /\ G |- e1 : t0 *) let star_typing_inversion_l (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t0 tm_vprop = admit () let star_typing_inversion_r (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : tot_typing g t1 tm_vprop = admit () let star_typing_inversion (#g:_) (#t0 #t1:term) (d:tot_typing g (tm_star t0 t1) tm_vprop) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () let vprop_eq_typing_inversion g (t0 t1:term) (token:FTB.equiv_token (elab_env g) (elab_term t0) (elab_term t1)) : GTot (tot_typing g t0 tm_vprop & tot_typing g t1 tm_vprop) = admit () (* These I can easily prove *) let star_typing (#g:_) (#t0 #t1:term) (d0:tot_typing g t0 tm_vprop) (d1:tot_typing g t1 tm_vprop) : tot_typing g (tm_star t0 t1) tm_vprop = admit () let emp_typing (#g:_) : tot_typing g tm_emp tm_vprop = admit () let fresh_wrt (x:var) (g:env) (vars:_) = None? (lookup g x) /\ ~(x `Set.mem` vars) let effect_annot_typing (g:env) (e:effect_annot) = match e with | EffectAnnotAtomic { opens } -> tot_typing g opens tm_inames | _ -> unit noeq type post_hint_t = { g:env; effect_annot:effect_annot; effect_annot_typing:effect_annot_typing g effect_annot; ret_ty:term; u:universe; ty_typing:universe_of g ret_ty u; post:term; x:(x:var { fresh_wrt x g (freevars post) }); post_typing_src:tot_typing (push_binding g x ppname_default ret_ty) (open_term post x) tm_vprop; post_typing: FStar.Ghost.erased (RT.tot_typing (elab_env g) (RT.(mk_abs (elab_term ret_ty) T.Q_Explicit (elab_term post))) (RT.mk_arrow (elab_term ret_ty) T.Q_Explicit (elab_term tm_vprop))) } let post_hint_for_env_p (g:env) (p:post_hint_t) = g `env_extends` p.g let post_hint_for_env_extends (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) (b:typ) : Lemma (requires post_hint_for_env_p g p) (ensures post_hint_for_env_p (push_binding g x ppname_default b) p) [SMTPat (post_hint_for_env_p (push_binding g x ppname_default b) p)] = env_extends_push g x ppname_default b let post_hint_for_env (g:env) = p:post_hint_t { post_hint_for_env_p g p } let post_hint_opt (g:env) = o:option post_hint_t { None? o \/ post_hint_for_env_p g (Some?.v o) } noeq type post_hint_typing_t (g:env) (p:post_hint_t) (x:var { ~ (Set.mem x (dom g)) }) = { effect_annot_typing:effect_annot_typing g p.effect_annot; ty_typing:universe_of g p.ret_ty p.u; post_typing:tot_typing (push_binding g x ppname_default p.ret_ty) (open_term p.post x) tm_vprop }
{ "checked_file": "/", "dependencies": [ "Pulse.Typing.Env.fsti.checked", "Pulse.Syntax.fst.checked", "Pulse.RuntimeUtils.fsti.checked", "Pulse.Reflection.Util.fst.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Set.fsti.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Pulse.Typing.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Typing.Env", "short_module": null }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "FTB" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Reflection.Util", "short_module": null }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "Pulse", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Pulse.Typing.Env.env -> p: Pulse.Typing.post_hint_for_env g -> x: Pulse.Syntax.Base.var {Pulse.Typing.fresh_wrt x g (Pulse.Syntax.Naming.freevars (Mkpost_hint_t?.post p))} -> Pulse.Typing.post_hint_typing_t g p x
Prims.Tot
[ "total" ]
[]
[ "Pulse.Typing.Env.env", "Pulse.Typing.post_hint_for_env", "Pulse.Syntax.Base.var", "Pulse.Typing.fresh_wrt", "Pulse.Syntax.Naming.freevars", "Pulse.Typing.__proj__Mkpost_hint_t__item__post", "Pulse.Typing.Mkpost_hint_typing_t", "Pulse.RuntimeUtils.magic", "Pulse.Typing.universe_of", "Pulse.Typing.__proj__Mkpost_hint_t__item__ret_ty", "Pulse.Typing.__proj__Mkpost_hint_t__item__u", "Pulse.Typing.tot_typing", "Pulse.Typing.Env.push_binding", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Naming.open_term", "Pulse.Syntax.Base.tm_vprop", "Pulse.Typing.effect_annot_typing", "Pulse.Typing.__proj__Mkpost_hint_t__item__effect_annot", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.tm_inames", "Pulse.Syntax.Base.effect_annot", "Pulse.Typing.post_hint_typing_t" ]
[]
false
false
false
false
false
let post_hint_typing (g: env) (p: post_hint_for_env g) (x: var{fresh_wrt x g (freevars p.post)}) : post_hint_typing_t g p x =
let effect_annot_typing:effect_annot_typing g p.effect_annot = match p.effect_annot with | EffectAnnotAtomic { opens = opens } -> let opens_typing:tot_typing g opens tm_inames = RU.magic () in opens_typing | _ -> () in { effect_annot_typing = effect_annot_typing; ty_typing = RU.magic (); post_typing = RU.magic () }
false
Benton2004.fst
Benton2004.reify_raw_computation
val reify_raw_computation (f: raw_computation) : reified_raw_computation
val reify_raw_computation (f: raw_computation) : reified_raw_computation
let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 54, "start_col": 0, "start_line": 53 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.raw_computation -> Benton2004.reified_raw_computation
Prims.Tot
[ "total" ]
[]
[ "Benton2004.raw_computation", "Prims.nat", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.bool", "FStar.Pervasives.Native.tuple2", "Benton2004.reified_raw_computation" ]
[]
false
false
false
true
false
let reify_raw_computation (f: raw_computation) : reified_raw_computation =
fun n h -> reify (f n) h
false
Benton2004.fst
Benton2004.fuel_monotonic
val fuel_monotonic (f: reified_raw_computation) : GTot Type0
val fuel_monotonic (f: reified_raw_computation) : GTot Type0
let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h )
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 36, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.reified_raw_computation -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.reified_raw_computation", "Prims.l_Forall", "Prims.nat", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.l_imp", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.tuple2", "Prims.has_type" ]
[]
false
false
false
false
true
let fuel_monotonic (f: reified_raw_computation) : GTot Type0 =
forall (fuel: nat) (fuel': nat) h. {:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} (fuel <= fuel' /\ fst (f fuel h) == true) ==> (f fuel' h == f fuel h)
false
Benton2004.fst
Benton2004.reified_exp
val reified_exp (t: Type0) : Tot Type0
val reified_exp (t: Type0) : Tot Type0
let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 120, "end_line": 69, "start_col": 0, "start_line": 69 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Pervasives.Native.tuple2", "Prims.l_True", "Prims.eq2", "FStar.Pervasives.Native.snd" ]
[]
false
false
false
true
true
let reified_exp (t: Type0) : Tot Type0 =
h: heap -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h))
false
Benton2004.fst
Benton2004.is_per
val is_per (#t: Type0) (f: rel t) : GTot Type0
val is_per (#t: Type0) (f: rel t) : GTot Type0
let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3)
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 184, "start_col": 0, "start_line": 182 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.Aux.rel t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.Aux.rel", "Prims.l_and", "Prims.l_Forall", "Prims.l_iff", "Prims.l_imp" ]
[]
false
false
false
false
true
let is_per (#t: Type0) (f: rel t) : GTot Type0 =
(forall x1 x2. f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3. (f x1 x2 /\ f x2 x3) ==> f x1 x3)
false
Benton2004.fst
Benton2004.included
val included (#t: Type0) (r1 r2: rel t) : GTot Type0
val included (#t: Type0) (r1 r2: rel t) : GTot Type0
let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 180, "start_col": 0, "start_line": 176 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r1: Benton2004.Aux.rel t -> r2: Benton2004.Aux.rel t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.Aux.rel", "Prims.l_Forall", "Prims.l_imp", "Benton2004.Aux.holds" ]
[]
false
false
false
false
true
let included (#t: Type0) (r1 r2: rel t) : GTot Type0 =
forall x y. holds r1 x y ==> holds r2 x y
false
Benton2004.fst
Benton2004.const
val const (#t: Type0) (v: t) : Tot (exp t)
val const (#t: Type0) (v: t) : Tot (exp t)
let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 75, "start_col": 0, "start_line": 75 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: t -> Benton2004.exp t
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Benton2004.exp" ]
[]
false
false
false
true
false
let const (#t: Type0) (v: t) : Tot (exp t) =
fun _ -> v
false
Benton2004.fst
Benton2004.terminates_on
val terminates_on (f: reified_computation) (h: heap) : GTot Type0
val terminates_on (f: reified_computation) (h: heap) : GTot Type0
let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 174, "start_col": 0, "start_line": 173 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.reified_computation -> h: FStar.DM4F.Heap.IntStoreFixed.heap -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.reified_computation", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.l_Exists", "Prims.nat", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.fst" ]
[]
false
false
false
false
true
let terminates_on (f: reified_computation) (h: heap) : GTot Type0 =
exists fuel. fst (f fuel h) == true
false
Benton2004.fst
Benton2004.reify_exp
val reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t)
val reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t)
let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 73, "start_col": 0, "start_line": 71 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: Benton2004.exp t -> Prims.GTot (Benton2004.reified_exp t)
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.exp", "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Pervasives.Native.tuple2", "Prims.l_and", "Prims.l_True", "Prims.l_Forall", "Prims.l_imp", "Prims.eq2", "FStar.Pervasives.Native.Mktuple2", "Benton2004.reified_exp" ]
[]
false
false
false
false
false
let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) =
let f = reify (e ()) in f
false
Benton2004.fst
Benton2004.reify_computation
val reify_computation (c: computation) : GTot reified_computation
val reify_computation (c: computation) : GTot reified_computation
let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 60, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) })
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Benton2004.computation -> Prims.GTot Benton2004.reified_computation
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.computation", "Benton2004.reify_raw_computation", "Benton2004.reified_computation" ]
[]
false
false
false
false
false
let reify_computation (c: computation) : GTot reified_computation =
reify_raw_computation c
false
Benton2004.fst
Benton2004.intersect
val intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t)
val intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t)
let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 219, "start_col": 0, "start_line": 213 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ns1: Benton2004.Aux.rel t -> ns2: Benton2004.Aux.rel t -> Prims.GTot (Benton2004.Aux.rel t)
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.Aux.rel", "Prims.unit", "FStar.Classical.forall_intro_2", "Prims.l_iff", "Benton2004.Aux.holds", "Benton2004.Aux.holds_equiv", "Prims.logical", "Prims.l_and" ]
[]
false
false
false
false
false
let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) =
let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f
false
Benton2004.fst
Benton2004.evar
val evar (x: var) : Tot (exp int)
val evar (x: var) : Tot (exp int)
let evar (x: var) : Tot (exp int) = fun _ -> read x
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 77, "start_col": 0, "start_line": 77 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Benton2004.var -> Benton2004.exp Prims.int
Prims.Tot
[ "total" ]
[]
[ "Benton2004.var", "Prims.unit", "FStar.DM4F.IntStoreFixed.read", "Prims.int", "Benton2004.exp" ]
[]
false
false
false
true
false
let evar (x: var) : Tot (exp int) =
fun _ -> read x
false
Benton2004.fst
Benton2004.skip
val skip:computation
val skip:computation
let skip : computation = let f (fuel: nat) : ISNull bool = true in f
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 68, "end_line": 62, "start_col": 0, "start_line": 62 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Benton2004.computation
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.bool" ]
[]
false
false
false
true
false
let skip:computation =
let f (fuel: nat) : ISNull bool = true in f
false
Benton2004.fst
Benton2004.while_raw
val while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel)
val while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel)
let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 129, "start_col": 0, "start_line": 120 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Benton2004.exp Prims.bool -> c: Benton2004.computation -> fuel: Prims.nat -> FStar.DM4F.IntStoreFixed.ISNull Prims.bool
FStar.DM4F.IntStoreFixed.ISNull
[ "" ]
[]
[ "Benton2004.exp", "Prims.bool", "Benton2004.computation", "Prims.nat", "Prims.op_Equality", "Prims.int", "Benton2004.while_raw", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) =
if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true
false
Benton2004.fst
Benton2004.eval_equiv_reified
val eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0
val eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0
let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s'))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 258, "start_col": 0, "start_line": 251 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> e: Benton2004.nstype t -> f: Benton2004.reified_exp t -> f': Benton2004.reified_exp t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.sttype", "Benton2004.nstype", "Benton2004.reified_exp", "Prims.l_Forall", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.l_imp", "Benton2004.Aux.holds", "FStar.Pervasives.Native.fst" ]
[]
false
false
false
false
true
let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 =
forall (s: heap) (s': heap). holds p s s' ==> holds e (fst (f s)) (fst (f' s'))
false
Benton2004.fst
Benton2004.interpolable
val interpolable (#t: Type0) (f: rel t) : GTot Type0
val interpolable (#t: Type0) (f: rel t) : GTot Type0
let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3)
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 67, "end_line": 236, "start_col": 0, "start_line": 232 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.Aux.rel t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.Aux.rel", "Prims.l_Forall", "Prims.l_imp", "Prims.l_Exists", "Prims.l_and" ]
[]
false
false
false
false
true
let interpolable (#t: Type0) (f: rel t) : GTot Type0 =
forall (x1: t) (x3: t). f x1 x3 ==> (exists x2. f x1 x2 /\ f x2 x3)
false
Benton2004.fst
Benton2004.terminates_equiv_reified
val terminates_equiv_reified (p: sttype) (f f': reified_computation) : GTot Type0
val terminates_equiv_reified (p: sttype) (f f': reified_computation) : GTot Type0
let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s')
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 77, "end_line": 274, "start_col": 0, "start_line": 270 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> f: Benton2004.reified_computation -> f': Benton2004.reified_computation -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.sttype", "Benton2004.reified_computation", "Prims.l_Forall", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.l_imp", "Benton2004.Aux.holds", "Prims.l_iff", "Benton2004.terminates_on" ]
[]
false
false
false
false
true
let terminates_equiv_reified (p: sttype) (f f': reified_computation) : GTot Type0 =
forall s s'. holds p s s' ==> (terminates_on f s <==> terminates_on f' s')
false
Benton2004.fst
Benton2004.assign
val assign (r: var) (n: exp int) : Tot computation
val assign (r: var) (n: exp int) : Tot computation
let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 85, "start_col": 0, "start_line": 79 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Benton2004.var -> n: Benton2004.exp Prims.int -> Benton2004.computation
Prims.Tot
[ "total" ]
[]
[ "Benton2004.var", "Benton2004.exp", "Prims.int", "Prims.nat", "Prims.bool", "Prims.unit", "FStar.DM4F.IntStoreFixed.write", "Benton2004.computation" ]
[]
false
false
false
true
false
let assign (r: var) (n: exp int) : Tot computation =
let g _ : ISNull bool = let n = n () in write r n; true in g
false
Benton2004.fst
Benton2004.eval_equiv
val eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0
val eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0
let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f'
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 268, "start_col": 0, "start_line": 260 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s'))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> e: Benton2004.nstype t -> f: Benton2004.exp t -> f': Benton2004.exp t -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.sttype", "Benton2004.nstype", "Benton2004.exp", "Benton2004.eval_equiv_reified", "Benton2004.reified_exp", "Benton2004.reify_exp" ]
[]
false
false
false
false
true
let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 =
let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f'
false
Benton2004.fst
Benton2004.flip
val flip (#t: Type0) (r: rel t) : Tot (rel t)
val flip (#t: Type0) (r: rel t) : Tot (rel t)
let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 304, "start_col": 0, "start_line": 302 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Benton2004.Aux.rel t -> Benton2004.Aux.rel t
Prims.Tot
[ "total" ]
[]
[ "Benton2004.Aux.rel", "Benton2004.Aux.holds" ]
[]
false
false
false
true
false
let flip (#t: Type0) (r: rel t) : Tot (rel t) =
let g x y = holds r y x in g
false
Benton2004.fst
Benton2004.exec_equiv_reified
val exec_equiv_reified (p p': sttype) (f f': reified_computation) : GTot Type0
val exec_equiv_reified (p p': sttype) (f f': reified_computation) : GTot Type0
let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s')))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 122, "end_line": 290, "start_col": 0, "start_line": 284 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> p': Benton2004.sttype -> f: Benton2004.reified_computation -> f': Benton2004.reified_computation -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.sttype", "Benton2004.reified_computation", "Prims.l_and", "Benton2004.terminates_equiv_reified", "Prims.l_Forall", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.nat", "Prims.l_imp", "Benton2004.Aux.holds", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd" ]
[]
false
false
false
false
true
let exec_equiv_reified (p p': sttype) (f f': reified_computation) : GTot Type0 =
terminates_equiv_reified p f f' /\ (forall (s: heap) (s': heap) (fuel: nat). (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s')))
false
Benton2004.fst
Benton2004.while
val while (b: exp bool) (c: computation) : Tot computation
val while (b: exp bool) (c: computation) : Tot computation
let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 169, "start_col": 0, "start_line": 165 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Benton2004.exp Prims.bool -> c: Benton2004.computation -> Benton2004.computation
Prims.Tot
[ "total" ]
[]
[ "Benton2004.exp", "Prims.bool", "Benton2004.computation", "Prims.unit", "Benton2004.fuel_monotonic_while", "Benton2004.reified_raw_computation", "Benton2004.reify_raw_computation", "Benton2004.raw_computation", "Benton2004.while_raw" ]
[]
false
false
false
true
false
let while (b: exp bool) (c: computation) : Tot computation =
let f:raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f
false
Benton2004.fst
Benton2004.exec_equiv
val exec_equiv (p p': sttype) (f f': computation) : GTot Type0
val exec_equiv (p p': sttype) (f f': computation) : GTot Type0
let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f'
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 298, "start_col": 0, "start_line": 292 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s')))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> p': Benton2004.sttype -> f: Benton2004.computation -> f': Benton2004.computation -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "Benton2004.sttype", "Benton2004.computation", "Benton2004.exec_equiv_reified", "Benton2004.reified_computation", "Benton2004.reify_computation" ]
[]
false
false
false
false
true
let exec_equiv (p p': sttype) (f f': computation) : GTot Type0 =
let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f'
false
Benton2004.fst
Benton2004.is_per_holds_sym
val is_per_holds_sym (#t: Type0) (p: rel t) (s s': t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')]
val is_per_holds_sym (#t: Type0) (p: rel t) (s s': t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')]
let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 195, "start_col": 0, "start_line": 186 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.Aux.rel t -> s: t -> s': t -> FStar.Pervasives.Lemma (requires Benton2004.is_per p) (ensures Benton2004.Aux.holds p s s' <==> Benton2004.Aux.holds p s' s) [SMTPat (Benton2004.Aux.holds p s s')]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.Aux.rel", "Benton2004.Aux.holds_equiv", "Prims.unit", "Benton2004.is_per", "Prims.squash", "Prims.l_iff", "Benton2004.Aux.holds", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let is_per_holds_sym (#t: Type0) (p: rel t) (s s': t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] =
holds_equiv p s s'; holds_equiv p s' s
false
Benton2004.fst
Benton2004.per_holds_trans
val per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [ SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)] ] ]
val per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [ SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)] ] ]
let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 211, "start_col": 0, "start_line": 197 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.Aux.rel t -> x1: t -> x2: t -> x3: t -> FStar.Pervasives.Lemma (requires Benton2004.is_per f /\ Benton2004.Aux.holds f x1 x2 /\ Benton2004.Aux.holds f x2 x3) (ensures Benton2004.Aux.holds f x1 x3) [ SMTPatOr [ [SMTPat (Benton2004.Aux.holds f x1 x2); SMTPat (Benton2004.Aux.holds f x2 x3)]; [SMTPat (Benton2004.Aux.holds f x1 x2); SMTPat (Benton2004.Aux.holds f x1 x3)]; [SMTPat (Benton2004.Aux.holds f x2 x3); SMTPat (Benton2004.Aux.holds f x1 x3)] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.Aux.rel", "Benton2004.Aux.holds_equiv", "Prims.unit", "Prims.l_and", "Benton2004.is_per", "Benton2004.Aux.holds", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "Prims.list", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [ SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)] ] ] =
holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3
false
Benton2004.fst
Benton2004.interpolable_elim
val interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2. holds f x1 x2 /\ holds f x2 x3))
val interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2. holds f x1 x2 /\ holds f x2 x3))
let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f)
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 245, "start_col": 0, "start_line": 238 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: Benton2004.Aux.rel t -> x1: t -> x3: t -> FStar.Pervasives.Lemma (requires Benton2004.interpolable f /\ Benton2004.Aux.holds f x1 x3) (ensures exists (x2: t). Benton2004.Aux.holds f x1 x2 /\ Benton2004.Aux.holds f x2 x3)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.Aux.rel", "FStar.Classical.forall_intro_2", "Prims.l_iff", "Benton2004.Aux.holds", "Benton2004.Aux.holds_equiv", "Prims.unit", "Prims.l_and", "Benton2004.interpolable", "Prims.squash", "Prims.l_Exists", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2. holds f x1 x2 /\ holds f x2 x3)) =
Classical.forall_intro_2 (holds_equiv f)
false
Benton2004.fst
Benton2004.holds_intersect
val holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)]
val holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)]
let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 228, "start_col": 0, "start_line": 221 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
ns1: Benton2004.Aux.rel t -> ns2: Benton2004.Aux.rel t -> x: t -> y: t -> FStar.Pervasives.Lemma (ensures Benton2004.Aux.holds (Benton2004.intersect ns1 ns2) x y <==> Benton2004.Aux.holds ns1 x y /\ Benton2004.Aux.holds ns2 x y) [SMTPat (Benton2004.Aux.holds (Benton2004.intersect ns1 ns2) x y)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.Aux.rel", "Benton2004.Aux.holds_equiv", "Benton2004.intersect", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Benton2004.Aux.holds", "Prims.l_and", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] =
holds_equiv (intersect ns1 ns2) x y
false
Benton2004.fst
Benton2004.holds_flip'
val holds_flip' (#t: Type0) (r: rel t) (x y: _) : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)]
val holds_flip' (#t: Type0) (r: rel t) (x y: _) : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)]
let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 313, "start_col": 0, "start_line": 310 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Benton2004.Aux.rel t -> x: t -> y: t -> FStar.Pervasives.Lemma (ensures Benton2004.Aux.holds (Benton2004.flip r) x y <==> Benton2004.Aux.holds r y x) [SMTPat (Benton2004.Aux.holds (Benton2004.flip r) x y)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.Aux.rel", "Benton2004.holds_flip", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Benton2004.Aux.holds", "Benton2004.flip", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] =
holds_flip r
false
Benton2004.fst
Benton2004.holds_flip
val holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y. holds (flip r) x y <==> holds r y x)
val holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y. holds (flip r) x y <==> holds r y x)
let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 308, "start_col": 0, "start_line": 306 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Benton2004.Aux.rel t -> FStar.Pervasives.Lemma (ensures forall (x: t) (y: t). Benton2004.Aux.holds (Benton2004.flip r) x y <==> Benton2004.Aux.holds r y x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.Aux.rel", "FStar.Classical.forall_intro_2", "Prims.l_iff", "Benton2004.Aux.holds", "Benton2004.flip", "Benton2004.Aux.holds_equiv", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_Forall", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y. holds (flip r) x y <==> holds r y x) =
Classical.forall_intro_2 (holds_equiv (flip r))
false
Benton2004.fst
Benton2004.eval_equiv_flip
val eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)]
val eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)]
let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 324, "start_col": 0, "start_line": 315 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> e: Benton2004.nstype t -> f: Benton2004.exp t -> f': Benton2004.exp t -> FStar.Pervasives.Lemma (ensures Benton2004.eval_equiv (Benton2004.flip p) (Benton2004.flip e) f' f <==> Benton2004.eval_equiv p e f f') [SMTPat (Benton2004.eval_equiv (Benton2004.flip p) (Benton2004.flip e) f' f)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.nstype", "Benton2004.exp", "Benton2004.holds_flip", "Prims.unit", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Benton2004.eval_equiv", "Benton2004.flip", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] =
holds_flip p; holds_flip e
false
Benton2004.fst
Benton2004.mention
val mention : x: a -> Prims.logical
let mention (#a:Type) (x:a) = True
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 829, "start_col": 0, "start_line": 829 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = () let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0) // NOTE: this rule is NOT a consequence of d_su1 + d_seq + d_ctr let d_su2 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq c skip) c)) [SMTPat (exec_equiv phi phi' (seq c skip) c)] = () let d_assoc (c1 c2 c3: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] = let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel) let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3 )) (ensures ( exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)) )) [SMTPatOr [ [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)]; [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; [SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; ]] = let fl = reify_computation (seq (ifthenelse b c1 c2) c3) in let fr = reify_computation (ifthenelse b (seq c1 c3) (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel); assert (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (seq (ifthenelse b c1 c2) c3)) #restart-solver let d_lu1 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (ifthenelse b (seq c (while b c)) skip) in let eb = reify_exp b in let prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); assert (fr fuel s0 == fl fuel s1) end else () in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fst (fr fuel s0) == true /\ fl (fuel + 1) s0 == fr fuel s0)) = if fst (eb s0) then begin () end else () in let prf2' (s0: heap) (fuel: nat) : Lemma (ensures (fst (fr fuel s0) == true ==> fl (fuel + 1) s0 == fr fuel s0)) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf2' #restart-solver let d_lu2 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (while b (seq c (ifthenelse b c skip))) in let eb = reify_exp b in let rec prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) (decreases fuel) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); if fst (eb s1) then begin let s2 = snd (fc (fuel - 1) s1) in assert (fl fuel s0 == fl (fuel - 2) s2); assert (fc fuel s1 == fc (fuel - 1) s1); assert (fr fuel s0 == fr (fuel - 1) s2); prf1 s2 (fuel - 2); assert (fr (fuel - 1) s2 == fr (fuel - 2) s2) end else () end else () in let rec prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fl (fuel + fuel) s0 == fr fuel s0)) (decreases fuel) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in if fst (eb s1) then begin let s2 = snd (fc fuel s1) in assert (fr fuel s0 == fr (fuel - 1) s2); prf2 s2 (fuel - 1); assert (fl ((fuel - 1) + (fuel - 1)) s2 == fr (fuel - 1) s2); assert (fl (fuel + fuel) s0 == fl ((fuel + fuel) - 1) s1); assert (fl (fuel + fuel) s0 == fl (fuel - 1 + fuel - 1) s2) end else begin assert (fl (fuel + fuel) s0 == fr fuel s0) end end else () in let prf1' (s0:heap) (fuel:nat) :Lemma (fst (fl fuel s0) == true ==> fr fuel s0 == fl fuel s0) = Classical.move_requires (prf1 s0) fuel in let prf2' (s0:heap) (fuel:nat) :Lemma (fst (fr fuel s0) == true ==> fl (fuel + fuel) s0 == fr fuel s0) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf1'; //AR: same pattern as in Pointer, see the comment there Classical.forall_intro_2 prf2' (* 3.2 Optimizing Transformations *) (* Equivalent branches for conditional *) (* FIXME: the following rule is WRONG, because the relations are not necessarily reflexive. let d_bre (c1 c2: computation) (phi phi' : sttype) (b: exp bool) : Lemma (requires (exec_equiv phi phi' c1 c2)) (ensures (exec_equiv phi phi' (ifthenelse b c1 c2) c1)) *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_True", "Prims.logical" ]
[]
false
false
false
true
true
let mention (#a: Type) (x: a) =
True
false
Hacl.Spec.SHA2.Equiv.fst
Hacl.Spec.SHA2.Equiv.load_ws_lemma_l
val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
let load_ws_lemma_l #a #m b j = let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) in let aux (i:nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(|j|) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp
{ "file_name": "code/sha2-mb/Hacl.Spec.SHA2.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 416, "start_col": 0, "start_line": 401 }
module Hacl.Spec.SHA2.Equiv open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Sequence open Lib.IntVector open Lib.IntVector.Serialize open Lib.LoopCombinators open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec module Spec = Hacl.Spec.SHA2 module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.SHA2.Lemmas #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let _Ch_lemma #a #m x y z : Lemma (vec_v (_Ch #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Ch x y z)] = LSeq.eq_intro (vec_v (_Ch #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Ch a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Maj_lemma #a #m x y z : Lemma (vec_v (_Maj #a #m x y z) == LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) [SMTPat (_Maj x y z)] = LSeq.eq_intro (vec_v (_Maj #a #m x y z)) (LSeq.createi (lanes a m) (fun i -> Spec._Maj a (vec_v x).[i] (vec_v y).[i] (vec_v z).[i])) let _Sigma0_lemma #a #m x : Lemma (vec_v (_Sigma0 #a #m x) == LSeq.map (Spec._Sigma0 a) (vec_v x)) [SMTPat (_Sigma0 x)] = LSeq.eq_intro (vec_v (_Sigma0 #a #m x)) (LSeq.map (Spec._Sigma0 a) (vec_v x)) let _Sigma1_lemma #a #m x : Lemma (vec_v (_Sigma1 #a #m x) == LSeq.map (Spec._Sigma1 a) (vec_v x)) [SMTPat (_Sigma1 x)] = LSeq.eq_intro (vec_v (_Sigma1 #a #m x)) (LSeq.map (Spec._Sigma1 a) (vec_v x)) let _sigma0_lemma #a #m x : Lemma (vec_v (_sigma0 #a #m x) == LSeq.map (Spec._sigma0 a) (vec_v x)) [SMTPat (_sigma0 x)] = LSeq.eq_intro (vec_v (_sigma0 #a #m x)) (LSeq.map (Spec._sigma0 a) (vec_v x)) let _sigma1_lemma #a #m x : Lemma (vec_v (_sigma1 #a #m x) == LSeq.map (Spec._sigma1 a) (vec_v x)) [SMTPat (_sigma1 x)] = LSeq.eq_intro (vec_v (_sigma1 #a #m x)) (LSeq.map (Spec._sigma1 a) (vec_v x)) val seq_of_list_is_create8: #a:Type -> x0:a -> x1:a -> x2:a -> x3:a -> x4:a -> x5:a -> x6:a -> x7:a -> Lemma (create8 x0 x1 x2 x3 x4 x5 x6 x7 == Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7]) let seq_of_list_is_create8 #a x0 x1 x2 x3 x4 x5 x6 x7 = let rp = Seq.seq_of_list [x0; x1; x2; x3; x4; x5; x6; x7] in assert_norm (List.length [x0; x1; x2; x3; x4; x5; x6; x7] == 8); assert (length rp == 8); let lp = create8 x0 x1 x2 x3 x4 x5 x6 x7 in let aux (i:nat{i < 8}) : Lemma (Seq.index lp i == Seq.index rp i) = assert_norm (Seq.index lp i == Seq.index rp i) in Classical.forall_intro aux; eq_intro rp lp val shuffle_core_pre_create8: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> words_state' a let shuffle_core_pre_create8 a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_pre_create8_lemma: a:sha2_alg -> k_t:word a -> ws_t:word a -> hash:words_state' a -> Lemma (Spec.shuffle_core_pre a k_t ws_t hash == shuffle_core_pre_create8 a k_t ws_t hash) let shuffle_core_pre_create8_lemma a k_t ws_t hash = let a0 = Seq.index hash 0 in let b0 = Seq.index hash 1 in let c0 = Seq.index hash 2 in let d0 = Seq.index hash 3 in let e0 = Seq.index hash 4 in let f0 = Seq.index hash 5 in let g0 = Seq.index hash 6 in let h0 = Seq.index hash 7 in let t1 = h0 +. (Spec._Sigma1 a e0) +. (Spec._Ch a e0 f0 g0) +. k_t +. ws_t in let t2 = (Spec._Sigma0 a a0) +. (Spec._Maj a a0 b0 c0) in seq_of_list_is_create8 (t1 +. t2) a0 b0 c0 (d0 +. t1) e0 f0 g0 val shuffle_core_spec_lemma_l: #a:sha2_alg -> #m:m_spec -> k_t:word a -> ws_t:element_t a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_core_spec k_t ws_t st)).[l] == Spec.shuffle_core_pre a k_t (vec_v ws_t).[l] (state_spec_v st).[l]) let shuffle_core_spec_lemma_l #a #m k_t ws_t st l = eq_intro #(word a) #(state_word_length a) (state_spec_v (shuffle_core_spec k_t ws_t st)).[l] (shuffle_core_pre_create8 a k_t (vec_v ws_t).[l] (state_spec_v st).[l]); shuffle_core_pre_create8_lemma a k_t (vec_v ws_t).[l] (state_spec_v st).[l] #push-options "--z3rlimit 100" val ws_next_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < 16} -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next_inner i ws)).[l] == Spec.ws_next_inner a i (ws_spec_v ws).[l]) let ws_next_inner_lemma_l #a #m i ws l = eq_intro #(word a) #16 (ws_spec_v (ws_next_inner i ws)).[l] (Spec.ws_next_inner a i (ws_spec_v ws).[l]) #pop-options val ws_next_lemma_loop: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((ws_spec_v (repeati n (ws_next_inner #a #m) ws)).[l] == repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l]) let rec ws_next_lemma_loop #a #m ws l n = let lp = repeati n (ws_next_inner #a #m) ws in let rp = repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] in if n = 0 then begin eq_repeati0 n (ws_next_inner #a #m) ws; eq_repeati0 n (Spec.ws_next_inner a) (ws_spec_v ws).[l]; ws_next_inner_lemma_l 0 ws l end else begin let lp0 = repeati (n - 1) (ws_next_inner #a #m) ws in let rp0 = repeati (n - 1) (Spec.ws_next_inner a) (ws_spec_v ws).[l] in ws_next_lemma_loop #a #m ws l (n - 1); //assert ((ws_spec_v lp0).[l] == rp0); unfold_repeati n (ws_next_inner #a #m) ws (n - 1); unfold_repeati n (Spec.ws_next_inner a) (ws_spec_v ws).[l] (n - 1); //assert (lp == ws_next_inner #a #m (n - 1) lp0); //assert (rp == Spec.ws_next_inner a (n - 1) rp0); ws_next_inner_lemma_l (n - 1) lp0 l; () end val ws_next_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> l:nat{l < lanes a m} -> Lemma ((ws_spec_v (ws_next #a #m ws)).[l] == Spec.ws_next a (ws_spec_v ws).[l]) let ws_next_lemma_l #a #m ws l = ws_next_lemma_loop #a #m ws l 16 val shuffle_inner_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> i:nat{i < Spec.num_rounds16 a} -> j:nat{j < 16} -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle_inner ws i j st)).[l] == Spec.shuffle_inner a (ws_spec_v ws).[l] i j (state_spec_v st).[l]) let shuffle_inner_lemma_l #a #m ws i j st l = let k_t = Seq.index (Spec.k0 a) (16 * i + j) in let ws_t = ws.[j] in shuffle_core_spec_lemma_l k_t ws_t st l val shuffle_inner_loop_lemma: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= 16} -> Lemma ((state_spec_v (repeati n (shuffle_inner ws0 i) st0)).[l] == repeati n (Spec.shuffle_inner a (ws_spec_v ws0).[l] i) (state_spec_v st0).[l]) let rec shuffle_inner_loop_lemma #a #m i ws0 st0 l n = let f_sc = Spec.shuffle_inner a (ws_spec_v ws0).[l] i in let lp = repeati n (shuffle_inner ws0 i) st0 in let rp = repeati n f_sc (state_spec_v st0).[l] in if n = 0 then begin eq_repeati0 n (shuffle_inner ws0 i) st0; eq_repeati0 n f_sc (state_spec_v st0).[l]; shuffle_inner_lemma_l #a #m ws0 i n st0 l end else begin let lp0 = repeati (n - 1) (shuffle_inner ws0 i) st0 in let rp0 = repeati (n - 1) f_sc (state_spec_v st0).[l] in shuffle_inner_loop_lemma #a #m i ws0 st0 l (n - 1); assert ((state_spec_v lp0).[l] == rp0); unfold_repeati n (shuffle_inner ws0 i) st0 (n - 1); unfold_repeati n f_sc (state_spec_v st0).[l] (n - 1); shuffle_inner_lemma_l #a #m ws0 i (n - 1) lp0 l end val shuffle_inner_loop_lemma_l: #a:sha2_alg -> #m:m_spec -> i:nat{i < Spec.num_rounds16 a} -> ws_st:tuple2 (ws_spec a m) (state_spec a m) -> l:nat{l < lanes a m} -> Lemma (let (ws1, st1) = shuffle_inner_loop i ws_st in let (ws0, st0) = ws_st in let (ws, st) = Spec.shuffle_inner_loop a i ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws1).[l] == ws /\ (state_spec_v st1).[l] == st) let shuffle_inner_loop_lemma_l #a #m i (ws0, st0) l = shuffle_inner_loop_lemma #a #m i ws0 st0 l 16; ws_next_lemma_l ws0 l val shuffle_loop_lemma: #a:sha2_alg -> #m:m_spec -> ws0:ws_spec a m -> st0:state_spec a m -> l:nat{l < lanes a m} -> n:nat{n <= Spec.num_rounds16 a} -> Lemma (let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in (ws_spec_v ws_v).[l] == ws /\ (state_spec_v st_v).[l] == st) let rec shuffle_loop_lemma #a #m ws0 st0 l n = let (ws_v, st_v) = repeati n (shuffle_inner_loop #a #m) (ws0, st0) in let acc0 = ((ws_spec_v ws0).[l], (state_spec_v st0).[l]) in let (ws, st) = repeati n (Spec.shuffle_inner_loop a) acc0 in if n = 0 then begin eq_repeati0 n (shuffle_inner_loop #a #m) (ws0, st0); eq_repeati0 n (Spec.shuffle_inner_loop a) acc0; shuffle_inner_loop_lemma_l #a #m n (ws0, st0) l end else begin let (ws_v1, st_v1) = repeati (n - 1) (shuffle_inner_loop #a #m) (ws0, st0) in let (ws1, st1) = repeati (n - 1) (Spec.shuffle_inner_loop a) acc0 in shuffle_loop_lemma #a #m ws0 st0 l (n - 1); //assert ((ws_spec_v ws_v1).[l] == ws1 /\ (state_spec_v st_v1).[l] == st1); unfold_repeati n (shuffle_inner_loop #a #m) (ws0, st0) (n - 1); unfold_repeati n (Spec.shuffle_inner_loop a) acc0 (n - 1); shuffle_inner_loop_lemma_l #a #m (n - 1) (ws_v1, st_v1) l end val shuffle_lemma_l: #a:sha2_alg -> #m:m_spec -> ws:ws_spec a m -> st:state_spec a m -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (shuffle ws st)).[l] == Spec.shuffle a (ws_spec_v ws).[l] (state_spec_v st).[l]) let shuffle_lemma_l #a #m ws st l = shuffle_loop_lemma #a #m ws st l (Spec.num_rounds16 a) val init_lemma_l: a:sha2_alg -> m:m_spec -> l:nat{l < lanes a m} -> Lemma ((state_spec_v (init a m)).[l] == Spec.init a) let init_lemma_l a m l = eq_intro #(word a) #(state_word_length a) (state_spec_v (init a m)).[l] (Spec.init a) val load_blocks_lemma_ij: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in let ind = (i / l * l + j) * word_length a in (vec_v (load_blocks b).[i]).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|i % l|) ind (ind + word_length a))) let load_blocks_lemma_ij #a #m b j i = let l = lanes a m in let idx_i = i % l in let idx_j = i / l in let blocksize = word_length a in let blocksize_l = l * blocksize in let b_j = Seq.slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) in //assert ((load_blocks b).[i] == vec_from_bytes_be (word_t a) l b_j); assert (vec_v ((load_blocks b).[i]) == BSeq.uints_from_bytes_be b_j); BSeq.index_uints_from_bytes_be #(word_t a) #SEC #(lanes a m) b_j j; assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b_j (j * blocksize) (j * blocksize + blocksize))); calc (==) { idx_j * blocksize_l + j * blocksize; (==) { Math.Lemmas.paren_mul_right idx_j l blocksize; Math.Lemmas.distributivity_add_left (idx_j * l) j blocksize } (idx_j * l + j) * blocksize; }; Seq.Properties.slice_slice b.(|idx_i|) (idx_j * blocksize_l) (idx_j * blocksize_l + blocksize_l) (j * blocksize) (j * blocksize + blocksize); assert ((vec_v ((load_blocks b).[i])).[j] == BSeq.uint_from_bytes_be (Seq.slice b.(|idx_i|) ((idx_j * l + j) * blocksize) ((idx_j * l + j) * blocksize + blocksize))) val load_blocks_lemma_ij_subst: #a:sha2_alg -> #m:m_spec -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> i:nat{i < 16} -> Lemma (let l = lanes a m in (vec_v (load_blocks b).[i / l * l + j]).[i % l] == BSeq.uint_from_bytes_be (Seq.slice b.(|j|) (i * word_length a) (i * word_length a + word_length a))) let load_blocks_lemma_ij_subst #a #m b j i = let l = lanes a m in let i_new = i / l * l + j in let j_new = i % l in load_blocks_lemma_ij #a #m b j_new i_new; //assert ( //(vec_v (load_blocks b).[i_new]).[j_new] == //BSeq.uint_from_bytes_be (sub b.(|i_new % l|) ((i_new / l * l + j_new) * word_length a) (word_length a))); calc (==) { i_new % l; (==) { } (i / l * l + j) % l; (==) { Math.Lemmas.modulo_addition_lemma j l (i / l) } j % l; (==) { Math.Lemmas.small_mod j l } j; }; calc (==) { i_new / l * l + j_new; (==) { } (i / l * l + j) / l * l + i % l; (==) { Math.Lemmas.division_addition_lemma j l (i / l) } (i / l + j / l) * l + i % l; (==) { Math.Lemmas.distributivity_add_left (i / l) (j / l) l } i / l * l + j / l * l + i % l; (==) { Math.Lemmas.euclidean_division_definition i l } i + j / l * l; (==) { Math.Lemmas.small_div j l } i; } #push-options "--z3rlimit 150" val load_ws_lemma_l: #a:sha2_alg -> #m:m_spec{is_supported a m} -> b:multiblock_spec a m -> j:nat{j < lanes a m} -> Lemma ((ws_spec_v (load_ws b)).[j] == BSeq.uints_from_bytes_be #(word_t a) #SEC #(block_word_length a) b.(|j|))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.NTuple.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.Serialize.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Lemmas.fst.checked", "Hacl.Spec.SHA2.EquivScalar.fsti.checked", "Hacl.Spec.SHA2.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.SHA2.Equiv.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Hacl.Spec.SHA2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector.Serialize", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Hacl.Spec.SHA2.Vec.multiblock_spec a m -> j: Prims.nat{j < Hacl.Spec.SHA2.Vec.lanes a m} -> FStar.Pervasives.Lemma (ensures (Hacl.Spec.SHA2.Vec.ws_spec_v (Hacl.Spec.SHA2.Vec.load_ws b)).[ j ] == Lib.ByteSequence.uints_from_bytes_be b.(| j |))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Hash.Definitions.sha2_alg", "Hacl.Spec.SHA2.Vec.m_spec", "Hacl.Spec.SHA2.Vec.is_supported", "Hacl.Spec.SHA2.Vec.multiblock_spec", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.SHA2.Vec.lanes", "Lib.Sequence.eq_intro", "Hacl.Spec.SHA2.Vec.word", "Prims.unit", "FStar.Classical.forall_intro", "Prims.eq2", "Lib.IntTypes.uint_t", "Spec.Hash.Definitions.word_t", "Lib.IntTypes.SEC", "FStar.Seq.Base.index", "Prims.l_True", "Prims.squash", "Lib.IntTypes.int_t", "Prims.Nil", "FStar.Pervasives.pattern", "Hacl.Spec.SHA2.Equiv.load_blocks_lemma_ij_subst", "Hacl.Spec.SHA2.Lemmas.transpose_ws_lemma_ij", "Hacl.Spec.SHA2.Vec.load_blocks", "Prims._assert", "Lib.Sequence.lseq", "Hacl.Spec.SHA2.Vec.ws_spec_v", "Hacl.Spec.SHA2.Vec.transpose_ws", "Lib.ByteSequence.uint_from_bytes_be", "FStar.Seq.Base.slice", "Lib.IntTypes.uint8", "Lib.NTuple.op_Lens_Access", "FStar.Seq.Properties.lseq", "Spec.Hash.Definitions.block_length", "FStar.Mul.op_Star", "Spec.Hash.Definitions.word_length", "Prims.op_Addition", "Lib.ByteSequence.index_uints_from_bytes_be", "Hacl.Spec.SHA2.Vec.lanes_t", "Lib.ByteSequence.uints_from_bytes_be", "Hacl.Spec.SHA2.Vec.load_ws" ]
[]
false
false
true
false
false
let load_ws_lemma_l #a #m b j =
let lp = Seq.index (ws_spec_v (load_ws b)) j in let rp = BSeq.uints_from_bytes_be #(word_t a) #SEC #16 b.(| j |) in let aux (i: nat{i < 16}) : Lemma (Seq.index lp i == Seq.index rp i) = let l = lanes a m in BSeq.index_uints_from_bytes_be #(word_t a) #SEC #16 b.(| j |) i; assert (Seq.index rp i == BSeq.uint_from_bytes_be (Seq.slice b.(| j |) (i * word_length a) (i * word_length a + word_length a))); assert (Seq.index lp i == Seq.index (Seq.index (ws_spec_v (transpose_ws (load_blocks b))) j) i); Lemmas.transpose_ws_lemma_ij (load_blocks b) j i; load_blocks_lemma_ij_subst #a #m b j i in Classical.forall_intro aux; eq_intro lp rp
false
Benton2004.fst
Benton2004.eop
val eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to)
val eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to)
let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ())
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 477, "start_col": 0, "start_line": 472 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
op: (_: from -> _: from -> to) -> e1: Benton2004.exp from -> e2: Benton2004.exp from -> Benton2004.exp to
Prims.Tot
[ "total" ]
[]
[ "Benton2004.exp", "Prims.unit" ]
[]
false
false
false
true
false
let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) =
fun () -> (e1 ()) `op` (e2 ())
false
Benton2004.fst
Benton2004.exec_equiv_flip
val exec_equiv_flip (p p': sttype) (f f': computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')]
val exec_equiv_flip (p p': sttype) (f f': computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')]
let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p'
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 333, "start_col": 0, "start_line": 326 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> p': Benton2004.sttype -> f: Benton2004.computation -> f': Benton2004.computation -> FStar.Pervasives.Lemma (ensures Benton2004.exec_equiv (Benton2004.flip p) (Benton2004.flip p') f f' <==> Benton2004.exec_equiv p p' f' f) [SMTPat (Benton2004.exec_equiv (Benton2004.flip p) (Benton2004.flip p') f f')]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.computation", "Benton2004.holds_flip", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Benton2004.exec_equiv", "Benton2004.flip", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let exec_equiv_flip (p p': sttype) (f f': computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] =
holds_flip p; holds_flip p'
false
Benton2004.fst
Benton2004.eval_equiv_trans
val eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3: exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3)
val eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3: exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3)
let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 69, "end_line": 376, "start_col": 0, "start_line": 357 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> e: Benton2004.nstype t -> f1: Benton2004.exp t -> f2: Benton2004.exp t -> f3: Benton2004.exp t -> FStar.Pervasives.Lemma (requires Benton2004.is_per e /\ Benton2004.interpolable p /\ Benton2004.eval_equiv p e f1 f2 /\ Benton2004.eval_equiv p e f2 f3) (ensures Benton2004.eval_equiv p e f1 f3)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.nstype", "Benton2004.exp", "FStar.Classical.forall_intro_2", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.l_imp", "Benton2004.Aux.holds", "FStar.Pervasives.Native.fst", "Benton2004.reify_exp", "FStar.Classical.move_requires", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.exists_elim", "Prims.l_and", "Prims._assert", "Benton2004.interpolable_elim", "Benton2004.is_per", "Benton2004.interpolable", "Benton2004.eval_equiv" ]
[]
false
false
true
false
false
let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3: exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) =
let lem (s1 s3: heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2: heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x))
false
Benton2004.fst
Benton2004.exec_equiv_trans
val exec_equiv_trans (p p': sttype) (c1 c2 c3: computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3)) (ensures (exec_equiv p p' c1 c3)) [ SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)] ] ]
val exec_equiv_trans (p p': sttype) (c1 c2 c3: computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3)) (ensures (exec_equiv p p' c1 c3)) [ SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)] ] ]
let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 440, "start_col": 0, "start_line": 421 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Benton2004.sttype -> p': Benton2004.sttype -> c1: Benton2004.computation -> c2: Benton2004.computation -> c3: Benton2004.computation -> FStar.Pervasives.Lemma (requires Benton2004.is_per p' /\ Benton2004.interpolable p /\ Benton2004.exec_equiv p p' c1 c2 /\ Benton2004.exec_equiv p p' c2 c3) (ensures Benton2004.exec_equiv p p' c1 c3) [ SMTPatOr [ [SMTPat (Benton2004.exec_equiv p p' c1 c2); SMTPat (Benton2004.exec_equiv p p' c2 c3)]; [SMTPat (Benton2004.exec_equiv p p' c1 c2); SMTPat (Benton2004.exec_equiv p p' c1 c3)]; [SMTPat (Benton2004.exec_equiv p p' c2 c3); SMTPat (Benton2004.exec_equiv p p' c1 c3)] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.computation", "Benton2004.exec_equiv_reified_trans", "Benton2004.reified_computation", "Benton2004.reify_computation", "Prims.unit", "Prims.l_and", "Benton2004.is_per", "FStar.DM4F.Heap.IntStoreFixed.heap", "Benton2004.interpolable", "Benton2004.exec_equiv", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "Prims.list", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let exec_equiv_trans (p p': sttype) (c1 c2 c3: computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3)) (ensures (exec_equiv p p' c1 c3)) [ SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)] ] ] =
let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3
false
Benton2004.fst
Benton2004.d_seq_terminates_recip
val d_seq_terminates_recip (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) (s0 s0': heap) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0')) (ensures (terminates_on (reify_computation (seq c01 c12)) s0))
val d_seq_terminates_recip (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) (s0 s0': heap) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0')) (ensures (terminates_on (reify_computation (seq c01 c12)) s0))
let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 73, "end_line": 582, "start_col": 0, "start_line": 567 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p0: Benton2004.sttype -> p1: Benton2004.sttype -> p2: Benton2004.sttype -> c01: Benton2004.computation -> c01': Benton2004.computation -> c12: Benton2004.computation -> c12': Benton2004.computation -> s0: FStar.DM4F.Heap.IntStoreFixed.heap -> s0': FStar.DM4F.Heap.IntStoreFixed.heap -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv p0 p1 c01 c01' /\ Benton2004.exec_equiv p1 p2 c12 c12' /\ Benton2004.Aux.holds p0 s0 s0' /\ Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.seq c01' c12')) s0') (ensures Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.seq c01 c12)) s0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.computation", "FStar.DM4F.Heap.IntStoreFixed.heap", "Benton2004.d_seq_terminates", "Benton2004.flip", "Prims.unit", "Benton2004.holds_flip'", "Prims.l_and", "Benton2004.exec_equiv", "Benton2004.Aux.holds", "Benton2004.terminates_on", "Benton2004.reify_computation", "Benton2004.seq", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let d_seq_terminates_recip (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) (s0 s0': heap) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0')) (ensures (terminates_on (reify_computation (seq c01 c12)) s0)) =
holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.vale_p
val vale_p : Prims.logical
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 84, "start_col": 0, "start_line": 84 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_and", "Prims.b2t", "Vale.X64.CPU_Features_s.adx_enabled", "Vale.X64.CPU_Features_s.bmi2_enabled" ]
[]
false
false
false
true
true
let vale_p =
let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled
false
Benton2004.fst
Benton2004.d_assoc
val d_assoc (c1 c2 c3: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
val d_assoc (c1 c2 c3: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))]
let d_assoc (c1 c2 c3: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] = let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel)
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 678, "start_col": 0, "start_line": 669 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = () let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0) // NOTE: this rule is NOT a consequence of d_su1 + d_seq + d_ctr let d_su2 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq c skip) c)) [SMTPat (exec_equiv phi phi' (seq c skip) c)] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c1: Benton2004.computation -> c2: Benton2004.computation -> c3: Benton2004.computation -> phi: Benton2004.sttype -> phi': Benton2004.sttype -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv phi phi' (Benton2004.seq (Benton2004.seq c1 c2) c3) (Benton2004.seq (Benton2004.seq c1 c2) c3)) (ensures Benton2004.exec_equiv phi phi' (Benton2004.seq (Benton2004.seq c1 c2) c3) (Benton2004.seq c1 (Benton2004.seq c2 c3))) [ SMTPat (Benton2004.exec_equiv phi phi' (Benton2004.seq (Benton2004.seq c1 c2) c3) (Benton2004.seq c1 (Benton2004.seq c2 c3))) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.computation", "Benton2004.sttype", "Prims._assert", "Prims.l_Forall", "Prims.nat", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Prims.bool", "Benton2004.reified_computation", "Benton2004.reify_computation", "Benton2004.seq", "Prims.unit", "Benton2004.exec_equiv", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
false
false
true
false
false
let d_assoc (c1 c2 c3: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] =
let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel. fl s0 fuel == fr s0 fuel)
false
Benton2004.fst
Benton2004.d_cc
val d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'': sttype) : Lemma (requires (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3)) (ensures (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))) [ SMTPatOr [ [ SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3) ]; [ SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))) ]; [ SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))) ] ] ]
val d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'': sttype) : Lemma (requires (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3)) (ensures (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))) [ SMTPatOr [ [ SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3) ]; [ SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))) ]; [ SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))) ] ] ]
let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3 )) (ensures ( exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)) )) [SMTPatOr [ [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)]; [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; [SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; ]] = let fl = reify_computation (seq (ifthenelse b c1 c2) c3) in let fr = reify_computation (ifthenelse b (seq c1 c3) (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel); assert (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (seq (ifthenelse b c1 c2) c3))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 91, "end_line": 700, "start_col": 0, "start_line": 680 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = () let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0) // NOTE: this rule is NOT a consequence of d_su1 + d_seq + d_ctr let d_su2 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq c skip) c)) [SMTPat (exec_equiv phi phi' (seq c skip) c)] = () let d_assoc (c1 c2 c3: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] = let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Benton2004.exp Prims.bool -> c1: Benton2004.computation -> c2: Benton2004.computation -> c3: Benton2004.computation -> phi: Benton2004.sttype -> phi': Benton2004.sttype -> phi'': Benton2004.sttype -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv phi phi' (Benton2004.ifthenelse b c1 c2) (Benton2004.ifthenelse b c1 c2) /\ Benton2004.exec_equiv phi' phi'' c3 c3) (ensures Benton2004.exec_equiv phi phi'' (Benton2004.seq (Benton2004.ifthenelse b c1 c2) c3) (Benton2004.ifthenelse b (Benton2004.seq c1 c3) (Benton2004.seq c2 c3))) [ SMTPatOr [ [ SMTPat (Benton2004.exec_equiv phi phi' (Benton2004.ifthenelse b c1 c2) (Benton2004.ifthenelse b c1 c2)); SMTPat (Benton2004.exec_equiv phi' phi'' c3 c3) ]; [ SMTPat (Benton2004.exec_equiv phi phi' (Benton2004.ifthenelse b c1 c2) (Benton2004.ifthenelse b c1 c2)); SMTPat (Benton2004.exec_equiv phi phi'' (Benton2004.seq (Benton2004.ifthenelse b c1 c2) c3) (Benton2004.ifthenelse b (Benton2004.seq c1 c3) (Benton2004.seq c2 c3))) ]; [ SMTPat (Benton2004.exec_equiv phi' phi'' c3 c3); SMTPat (Benton2004.exec_equiv phi phi'' (Benton2004.seq (Benton2004.ifthenelse b c1 c2) c3) (Benton2004.ifthenelse b (Benton2004.seq c1 c3) (Benton2004.seq c2 c3))) ] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.exp", "Prims.bool", "Benton2004.computation", "Benton2004.sttype", "Prims._assert", "Benton2004.exec_equiv", "Benton2004.seq", "Benton2004.ifthenelse", "Prims.unit", "Prims.l_Forall", "Prims.nat", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Benton2004.reified_computation", "Benton2004.reify_computation", "Prims.l_and", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "Prims.list", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
false
false
true
false
false
let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'': sttype) : Lemma (requires (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3)) (ensures (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))) [ SMTPatOr [ [ SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3) ]; [ SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))) ]; [ SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3))) ] ] ] =
let fl = reify_computation (seq (ifthenelse b c1 c2) c3) in let fr = reify_computation (ifthenelse b (seq c1 c3) (seq c2 c3)) in assert (forall s0 fuel. fl s0 fuel == fr s0 fuel); assert (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (seq (ifthenelse b c1 c2) c3))
false
Benton2004.fst
Benton2004.d_seq_terminates
val d_seq_terminates (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) (s0 s0': heap) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0)) (ensures (terminates_on (reify_computation (seq c01' c12')) s0'))
val d_seq_terminates (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) (s0 s0': heap) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0)) (ensures (terminates_on (reify_computation (seq c01' c12')) s0'))
let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g)
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 563, "start_col": 0, "start_line": 518 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p0: Benton2004.sttype -> p1: Benton2004.sttype -> p2: Benton2004.sttype -> c01: Benton2004.computation -> c01': Benton2004.computation -> c12: Benton2004.computation -> c12': Benton2004.computation -> s0: FStar.DM4F.Heap.IntStoreFixed.heap -> s0': FStar.DM4F.Heap.IntStoreFixed.heap -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv p0 p1 c01 c01' /\ Benton2004.exec_equiv p1 p2 c12 c12' /\ Benton2004.Aux.holds p0 s0 s0' /\ Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.seq c01 c12)) s0) (ensures Benton2004.terminates_on (Benton2004.reify_computation (Benton2004.seq c01' c12')) s0')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.computation", "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Classical.forall_intro", "Prims.nat", "Prims.l_imp", "Prims.l_and", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.fst", "Benton2004.terminates_on", "FStar.Classical.move_requires", "Prims.unit", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "Prims.op_Addition", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "Benton2004.reify_computation", "Benton2004.seq", "Benton2004.Aux.holds", "FStar.Pervasives.Native.snd", "Benton2004.reified_computation", "Benton2004.exec_equiv" ]
[]
false
false
true
false
false
let d_seq_terminates (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) (s0 s0': heap) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0)) (ensures (terminates_on (reify_computation (seq c01' c12')) s0')) =
let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel': nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g)
false
Benton2004.fst
Benton2004.d_lu1
val d_lu1 (b: exp bool) (c: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip)))
val d_lu1 (b: exp bool) (c: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip)))
let d_lu1 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (ifthenelse b (seq c (while b c)) skip) in let eb = reify_exp b in let prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); assert (fr fuel s0 == fl fuel s1) end else () in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fst (fr fuel s0) == true /\ fl (fuel + 1) s0 == fr fuel s0)) = if fst (eb s0) then begin () end else () in let prf2' (s0: heap) (fuel: nat) : Lemma (ensures (fst (fr fuel s0) == true ==> fl (fuel + 1) s0 == fr fuel s0)) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf2'
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 746, "start_col": 0, "start_line": 703 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = () let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0) // NOTE: this rule is NOT a consequence of d_su1 + d_seq + d_ctr let d_su2 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq c skip) c)) [SMTPat (exec_equiv phi phi' (seq c skip) c)] = () let d_assoc (c1 c2 c3: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] = let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel) let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3 )) (ensures ( exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)) )) [SMTPatOr [ [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)]; [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; [SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; ]] = let fl = reify_computation (seq (ifthenelse b c1 c2) c3) in let fr = reify_computation (ifthenelse b (seq c1 c3) (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel); assert (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (seq (ifthenelse b c1 c2) c3))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Benton2004.exp Prims.bool -> c: Benton2004.computation -> phi: Benton2004.sttype -> phi': Benton2004.sttype -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv phi phi' (Benton2004.while b c) (Benton2004.while b c)) (ensures Benton2004.exec_equiv phi phi' (Benton2004.while b c) (Benton2004.ifthenelse b (Benton2004.seq c (Benton2004.while b c)) Benton2004.skip))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.exp", "Prims.bool", "Benton2004.computation", "Benton2004.sttype", "FStar.Classical.forall_intro_2", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.nat", "Prims.l_imp", "Prims.eq2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.tuple2", "Prims.op_Addition", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.move_requires", "Prims.l_and", "Prims._assert", "Prims.op_Subtraction", "FStar.Pervasives.Native.snd", "Benton2004.reified_exp", "Benton2004.reify_exp", "Benton2004.reified_computation", "Benton2004.reify_computation", "Benton2004.ifthenelse", "Benton2004.seq", "Benton2004.while", "Benton2004.skip", "Benton2004.exec_equiv" ]
[]
false
false
true
false
false
let d_lu1 (b: exp bool) (c: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) =
let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (ifthenelse b (seq c (while b c)) skip) in let eb = reify_exp b in let prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) = if fst (eb s0) then let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); assert (fr fuel s0 == fl fuel s1) in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fst (fr fuel s0) == true /\ fl (fuel + 1) s0 == fr fuel s0)) = if fst (eb s0) then () in let prf2' (s0: heap) (fuel: nat) : Lemma (ensures (fst (fr fuel s0) == true ==> fl (fuel + 1) s0 == fr fuel s0)) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf2'
false
Benton2004.fst
Benton2004.d_su1'
val d_su1' (c c' c'': computation) (phi phi' phi'': sttype) : Lemma (requires (exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'')) (ensures (exec_equiv phi phi'' (seq c c') c'')) [ SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')] ] ]
val d_su1' (c c' c'': computation) (phi phi' phi'': sttype) : Lemma (requires (exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'')) (ensures (exec_equiv phi phi'' (seq c c') c'')) [ SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')] ] ]
let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0)
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "end_line": 657, "start_col": 0, "start_line": 640 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Benton2004.computation -> c': Benton2004.computation -> c'': Benton2004.computation -> phi: Benton2004.sttype -> phi': Benton2004.sttype -> phi'': Benton2004.sttype -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv phi phi' c Benton2004.skip /\ Benton2004.exec_equiv phi' phi'' c' c'') (ensures Benton2004.exec_equiv phi phi'' (Benton2004.seq c c') c'') [ SMTPatOr [ [ SMTPat (Benton2004.exec_equiv phi phi' c Benton2004.skip); SMTPat (Benton2004.exec_equiv phi phi'' (Benton2004.seq c c') c'') ]; [ SMTPat (Benton2004.exec_equiv phi' phi'' c' c''); SMTPat (Benton2004.exec_equiv phi phi'' (Benton2004.seq c c') c'') ]; [ SMTPat (Benton2004.exec_equiv phi phi' c Benton2004.skip); SMTPat (Benton2004.exec_equiv phi' phi'' c' c'') ] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.computation", "Benton2004.sttype", "Prims._assert", "Prims.l_Forall", "Prims.nat", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "Prims.bool", "Benton2004.reified_computation", "Benton2004.reify_computation", "Benton2004.seq", "Benton2004.skip", "Prims.unit", "Benton2004.exec_equiv", "Prims.l_and", "Prims.squash", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat_or", "Prims.list", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
false
false
true
false
false
let d_su1' (c c' c'': computation) (phi phi' phi'': sttype) : Lemma (requires (exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'')) (ensures (exec_equiv phi phi'' (seq c c') c'')) [ SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')] ] ] =
assert (exec_equiv phi phi'' (seq c c') (seq skip c'')); let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0. f1 fuel s0 == f2 fuel s0)
false
Benton2004.fst
Benton2004.d_seq
val d_seq (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12')) (ensures (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))) [ SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [ SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')) ]; [ SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')) ] ] ]
val d_seq (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12')) (ensures (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))) [ SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [ SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')) ]; [ SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')) ] ] ]
let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 74, "end_line": 627, "start_col": 0, "start_line": 584 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p0: Benton2004.sttype -> p1: Benton2004.sttype -> p2: Benton2004.sttype -> c01: Benton2004.computation -> c01': Benton2004.computation -> c12: Benton2004.computation -> c12': Benton2004.computation -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv p0 p1 c01 c01' /\ Benton2004.exec_equiv p1 p2 c12 c12') (ensures Benton2004.exec_equiv p0 p2 (Benton2004.seq c01 c12) (Benton2004.seq c01' c12')) [ SMTPatOr [ [ SMTPat (Benton2004.exec_equiv p0 p1 c01 c01'); SMTPat (Benton2004.exec_equiv p1 p2 c12 c12') ]; [ SMTPat (Benton2004.exec_equiv p0 p1 c01 c01'); SMTPat (Benton2004.exec_equiv p0 p2 (Benton2004.seq c01 c12) (Benton2004.seq c01' c12')) ]; [ SMTPat (Benton2004.exec_equiv p1 p2 c12 c12'); SMTPat (Benton2004.exec_equiv p0 p2 (Benton2004.seq c01 c12) (Benton2004.seq c01' c12')) ] ] ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.sttype", "Benton2004.computation", "FStar.Classical.forall_intro_3", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.nat", "Prims.l_imp", "Prims.l_and", "Benton2004.Aux.holds", "Prims.eq2", "Prims.bool", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "FStar.Classical.move_requires", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "FStar.Pervasives.Native.tuple2", "FStar.Classical.forall_intro_2", "Prims.l_iff", "Benton2004.terminates_on", "Benton2004.exec_equiv", "Benton2004.reify_computation", "Benton2004.seq", "Benton2004.d_seq_terminates_recip", "Benton2004.d_seq_terminates", "Benton2004.reified_computation", "Prims.Cons", "FStar.Pervasives.smt_pat_or", "Prims.list", "FStar.Pervasives.smt_pat" ]
[]
false
false
true
false
false
let d_seq (p0 p1 p2: sttype) (c01 c01' c12 c12': computation) : Lemma (requires (exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12')) (ensures (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))) [ SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [ SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')) ]; [ SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12')) ] ] ] =
let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0': heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y))
false
Benton2004.fst
Benton2004.d_bre
val d_bre (c1 c2 c0: computation) (phi phi': sttype) (b: exp bool) : Lemma (requires (exec_equiv phi phi' c1 c0 /\ exec_equiv phi phi' c2 c0)) (ensures (exec_equiv phi phi' (ifthenelse b c1 c2) c0)) [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) c0)]
val d_bre (c1 c2 c0: computation) (phi phi': sttype) (b: exp bool) : Lemma (requires (exec_equiv phi phi' c1 c0 /\ exec_equiv phi phi' c2 c0)) (ensures (exec_equiv phi phi' (ifthenelse b c1 c2) c0)) [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) c0)]
let d_bre (c1 c2 c0: computation) (phi phi' : sttype) (b: exp bool) : Lemma (requires ( exec_equiv phi phi' c1 c0 /\ exec_equiv phi phi' c2 c0 )) (ensures (exec_equiv phi phi' (ifthenelse b c1 c2) c0)) [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) c0)] = assert (mention (reify_exp b))
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 842, "start_col": 0, "start_line": 831 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = () let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0) // NOTE: this rule is NOT a consequence of d_su1 + d_seq + d_ctr let d_su2 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq c skip) c)) [SMTPat (exec_equiv phi phi' (seq c skip) c)] = () let d_assoc (c1 c2 c3: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] = let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel) let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3 )) (ensures ( exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)) )) [SMTPatOr [ [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)]; [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; [SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; ]] = let fl = reify_computation (seq (ifthenelse b c1 c2) c3) in let fr = reify_computation (ifthenelse b (seq c1 c3) (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel); assert (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (seq (ifthenelse b c1 c2) c3)) #restart-solver let d_lu1 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (ifthenelse b (seq c (while b c)) skip) in let eb = reify_exp b in let prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); assert (fr fuel s0 == fl fuel s1) end else () in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fst (fr fuel s0) == true /\ fl (fuel + 1) s0 == fr fuel s0)) = if fst (eb s0) then begin () end else () in let prf2' (s0: heap) (fuel: nat) : Lemma (ensures (fst (fr fuel s0) == true ==> fl (fuel + 1) s0 == fr fuel s0)) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf2' #restart-solver let d_lu2 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (while b (seq c (ifthenelse b c skip))) in let eb = reify_exp b in let rec prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) (decreases fuel) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); if fst (eb s1) then begin let s2 = snd (fc (fuel - 1) s1) in assert (fl fuel s0 == fl (fuel - 2) s2); assert (fc fuel s1 == fc (fuel - 1) s1); assert (fr fuel s0 == fr (fuel - 1) s2); prf1 s2 (fuel - 2); assert (fr (fuel - 1) s2 == fr (fuel - 2) s2) end else () end else () in let rec prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fl (fuel + fuel) s0 == fr fuel s0)) (decreases fuel) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in if fst (eb s1) then begin let s2 = snd (fc fuel s1) in assert (fr fuel s0 == fr (fuel - 1) s2); prf2 s2 (fuel - 1); assert (fl ((fuel - 1) + (fuel - 1)) s2 == fr (fuel - 1) s2); assert (fl (fuel + fuel) s0 == fl ((fuel + fuel) - 1) s1); assert (fl (fuel + fuel) s0 == fl (fuel - 1 + fuel - 1) s2) end else begin assert (fl (fuel + fuel) s0 == fr fuel s0) end end else () in let prf1' (s0:heap) (fuel:nat) :Lemma (fst (fl fuel s0) == true ==> fr fuel s0 == fl fuel s0) = Classical.move_requires (prf1 s0) fuel in let prf2' (s0:heap) (fuel:nat) :Lemma (fst (fr fuel s0) == true ==> fl (fuel + fuel) s0 == fr fuel s0) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf1'; //AR: same pattern as in Pointer, see the comment there Classical.forall_intro_2 prf2' (* 3.2 Optimizing Transformations *) (* Equivalent branches for conditional *) (* FIXME: the following rule is WRONG, because the relations are not necessarily reflexive. let d_bre (c1 c2: computation) (phi phi' : sttype) (b: exp bool) : Lemma (requires (exec_equiv phi phi' c1 c2)) (ensures (exec_equiv phi phi' (ifthenelse b c1 c2) c1)) *) let mention (#a:Type) (x:a) = True
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c1: Benton2004.computation -> c2: Benton2004.computation -> c0: Benton2004.computation -> phi: Benton2004.sttype -> phi': Benton2004.sttype -> b: Benton2004.exp Prims.bool -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv phi phi' c1 c0 /\ Benton2004.exec_equiv phi phi' c2 c0) (ensures Benton2004.exec_equiv phi phi' (Benton2004.ifthenelse b c1 c2) c0) [SMTPat (Benton2004.exec_equiv phi phi' (Benton2004.ifthenelse b c1 c2) c0)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.computation", "Benton2004.sttype", "Benton2004.exp", "Prims.bool", "Prims._assert", "Benton2004.mention", "Benton2004.reified_exp", "Benton2004.reify_exp", "Prims.unit", "Prims.l_and", "Benton2004.exec_equiv", "Prims.squash", "Benton2004.ifthenelse", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let d_bre (c1 c2 c0: computation) (phi phi': sttype) (b: exp bool) : Lemma (requires (exec_equiv phi phi' c1 c0 /\ exec_equiv phi phi' c2 c0)) (ensures (exec_equiv phi phi' (ifthenelse b c1 c2) c0)) [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) c0)] =
assert (mention (reify_exp b))
false
Hacl.Spec.K256.Scalar.Lemmas.fst
Hacl.Spec.K256.Scalar.Lemmas.qmul_shift_383_mod_2_lemma
val qmul_shift_383_mod_2_lemma : l:lseq uint64 8 -> Lemma (v l.[5] / pow2 63 = SD.bn_v l / pow2 383 % 2)
val qmul_shift_383_mod_2_lemma : l:lseq uint64 8 -> Lemma (v l.[5] / pow2 63 = SD.bn_v l / pow2 383 % 2)
let qmul_shift_383_mod_2_lemma l = calc (==) { v l.[5] / pow2 63; (==) { SD.bn_eval_index l 5 } SD.bn_v l / pow2 320 % pow2 64 / pow2 63; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 320 384 } SD.bn_v l % pow2 384 / pow2 320 / pow2 63; (==) { Math.Lemmas.division_multiplication_lemma (SD.bn_v l % pow2 384) (pow2 320) (pow2 63) } SD.bn_v l % pow2 384 / (pow2 320 * pow2 63); (==) { Math.Lemmas.pow2_plus 320 63 } SD.bn_v l % pow2 384 / pow2 383; (==) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 383 384 } SD.bn_v l / pow2 383 % pow2 1; (==) { assert_norm (pow2 1 = 2) } SD.bn_v l / pow2 383 % 2; }
{ "file_name": "code/k256/Hacl.Spec.K256.Scalar.Lemmas.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 457, "start_col": 0, "start_line": 442 }
module Hacl.Spec.K256.Scalar.Lemmas open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Hacl.Spec.K256.Scalar module S = Spec.K256 module SD = Hacl.Spec.Bignum.Definitions module SB = Hacl.Spec.Bignum module BB = Hacl.Spec.Bignum.Base #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" val qas_nat4_is_qas_nat (f:qelem_lseq) : Lemma (SD.bn_v f == qas_nat4 (f.[0], f.[1], f.[2], f.[3])) let qas_nat4_is_qas_nat f = SD.bn_eval_unfold_i f 4; SD.bn_eval_unfold_i f 3; SD.bn_eval_unfold_i f 2; SD.bn_eval_unfold_i f 1; SD.bn_eval0 f val qas_nat4_inj (f1 f2:qelem4) : Lemma (requires qas_nat4 f1 = qas_nat4 f2) (ensures (let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in a0 == b0 /\ a1 == b1 /\ a2 == b2 /\ a3 == b3)) let qas_nat4_inj f1 f2 = let (a0,a1,a2,a3) = f1 in let (b0,b1,b2,b3) = f2 in let bf1 = create4 a0 a1 a2 a3 in let bf2 = create4 b0 b1 b2 b3 in qas_nat4_is_qas_nat bf1; qas_nat4_is_qas_nat bf2; SD.bn_eval_inj 4 bf1 bf2 #push-options "--ifuel 1" val is_qelem_zero_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_zero_vartime4 f == (qas_nat4 f = 0)) let is_qelem_zero_vartime4_lemma f = () val is_qelem_lt_q_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_q_vartime4 f == (qas_nat4 f < S.q)) let is_qelem_lt_q_vartime4_lemma f = assert_norm (0xbfd25e8cd0364141 + 0xbaaedce6af48a03b * pow2 64 + 0xfffffffffffffffe * pow2 128 + 0xffffffffffffffff * pow2 192 = S.q) val is_qelem_le_q_halved_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_le_q_halved_vartime4 f == (qas_nat4 f <= S.q / 2)) let is_qelem_le_q_halved_vartime4_lemma f = assert_norm (0xdfe92f46681b20a0 + 0x5d576e7357a4501d * pow2 64 + 0xffffffffffffffff * pow2 128 + 0x7fffffffffffffff * pow2 192 = S.q / 2) val is_qelem_eq_vartime4_lemma: f1:qelem4 -> f2:qelem4 -> Lemma (is_qelem_eq_vartime4 f1 f2 == (qas_nat4 f1 = qas_nat4 f2)) let is_qelem_eq_vartime4_lemma f1 f2 = if qas_nat4 f1 = qas_nat4 f2 then qas_nat4_inj f1 f2 #pop-options val is_qelem_lt_pow2_128_vartime4_lemma: f:qelem4 -> Lemma (is_qelem_lt_pow2_128_vartime4 f == (qas_nat4 f < pow2 128)) let is_qelem_lt_pow2_128_vartime4_lemma f = let (f0, f1, f2, f3) = f in assert (qas_nat4 f == v f0 + v f1 * pow2 64 + v f2 * pow2 128 + v f3 * pow2 192); assert (v f0 + v f1 * pow2 64 < pow2 128); if v f2 = 0 && v f3 = 0 then () else begin Math.Lemmas.pow2_lt_compat 192 128; assert (pow2 128 <= qas_nat4 f) end val lemma_check_overflow: b:nat{b < pow2 256} -> Lemma (let overflow = (b + (pow2 256 - S.q)) / pow2 256 in overflow = (if b < S.q then 0 else 1)) let lemma_check_overflow b = let overflow = (b + (pow2 256 - S.q)) / pow2 256 in if b < S.q then begin assert (pow2 256 + b - S.q < pow2 256); assert (pow2 256 - S.q <= pow2 256 + b - S.q); assert_norm (0 < pow2 256 - S.q); Math.Lemmas.small_div (pow2 256 + b - S.q) (pow2 256); assert (overflow = 0) end else begin assert (pow2 256 <= pow2 256 + b - S.q); Math.Lemmas.lemma_div_le (pow2 256) (pow2 256 + b - S.q) (pow2 256); Math.Lemmas.cancel_mul_div 1 (pow2 256); assert (1 <= overflow); assert (pow2 256 + b - S.q < pow2 256 + pow2 256 - S.q); assert (pow2 256 + b - S.q <= pow2 256 + pow2 256 - S.q - 1); Math.Lemmas.lemma_div_le (pow2 256 + b - S.q) (pow2 256 + pow2 256 - S.q - 1) (pow2 256); assert_norm ((pow2 256 + pow2 256 - S.q - 1) / pow2 256 = 1); assert (overflow <= 1) end val lemma_get_carry_from_bn_add: r:nat{r < pow2 256} -> c:nat -> Lemma ((r + c * pow2 256) / pow2 256 = c) let lemma_get_carry_from_bn_add r c = Math.Lemmas.lemma_div_plus r c (pow2 256); Math.Lemmas.small_div r (pow2 256) val mod_short_lseq_lemma_aux: a:qelem_lseq -> out:qelem_lseq -> c:BB.carry U64 -> Lemma (requires v c * pow2 256 + SD.bn_v out = SD.bn_v a + pow2 256 - S.q) (ensures SD.bn_v (map2 (BB.mask_select (u64 0 -. c)) out a) == SD.bn_v a % S.q) let mod_short_lseq_lemma_aux a out c = assert_norm (pow2 256 - S.q < S.q); let mask = u64 0 -. c in let out1 = map2 (BB.mask_select mask) out a in assert (v mask = (if v c = 0 then 0 else ones_v U64)); BB.lseq_mask_select_lemma out a mask; assert (out1 == (if v c = 0 then a else out)); SD.bn_eval_bound a 4; SD.bn_eval_bound out 4; lemma_check_overflow (SD.bn_v a); lemma_get_carry_from_bn_add (SD.bn_v out) (v c); assert (v c = (if SD.bn_v a < S.q then 0 else 1)); if SD.bn_v a < S.q then begin assert (SD.bn_v out1 == SD.bn_v a); Math.Lemmas.small_mod (SD.bn_v a) S.q end else begin assert (SD.bn_v out1 == SD.bn_v a + (pow2 256 - S.q) - pow2 256); Math.Lemmas.lemma_mod_sub (SD.bn_v a) S.q 1; assert (SD.bn_v out1 % S.q == SD.bn_v a % S.q); Math.Lemmas.small_mod (SD.bn_v out1) S.q end val mod_short_lseq_lemma: a:qelem_lseq -> Lemma (SD.bn_v (mod_short_lseq a) == SD.bn_v a % S.q) let mod_short_lseq_lemma a = let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in let tmp = create4 t0 t1 t2 t3 in let c, out = SB.bn_add a tmp in SB.bn_add_lemma a tmp; assert (v c * pow2 256 + SD.bn_v out = SD.bn_v a + SD.bn_v tmp); qas_nat4_is_qas_nat tmp; assert (SD.bn_v tmp == pow2 256 - S.q); mod_short_lseq_lemma_aux a out c val mul_pow2_256_minus_q_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen} -> a:lseq uint64 len -> Lemma (let c, res = mul_pow2_256_minus_q_lseq len resLen a in v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q)) let mul_pow2_256_minus_q_lemma len resLen a = let t0 = u64 0x402da1732fc9bebf in let t1 = u64 0x4551231950b75fc4 in assert_norm (v t0 + v t1 * pow2 64 = pow2 256 - S.q - pow2 128); let t01 = create2 t0 t1 in SD.bn_eval_unfold_i t01 2; SD.bn_eval_unfold_i t01 1; SD.bn_eval0 t01; assert (SD.bn_v t01 = pow2 256 - S.q - pow2 128); let m0 = SB.bn_mul a t01 in // a * t01 SB.bn_mul_lemma a t01; assert (SD.bn_v m0 == SD.bn_v a * SD.bn_v t01); let m10 = create resLen (u64 0) in let m1 = update_sub m10 2 len a in // a * t2 * pow2 128 SD.bn_update_sub_eval m10 a 2; assert (SD.bn_v m1 = SD.bn_v m10 - SD.bn_v (sub m10 2 len) * pow2 128 + SD.bn_v a * pow2 128); SD.bn_eval_zeroes #U64 resLen resLen; eq_intro (sub m10 2 len) (create len (u64 0)); SD.bn_eval_zeroes #U64 len len; assert (SD.bn_v m1 = SD.bn_v a * pow2 128); let c, m2 = SB.bn_add m1 m0 in // a * SECP256K1_N_C SB.bn_add_lemma m1 m0; assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v m1 + SD.bn_v m0); assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * pow2 128 + SD.bn_v a * SD.bn_v t01); Math.Lemmas.distributivity_add_right (SD.bn_v a) (pow2 128) (SD.bn_v t01); assert (v c * pow2 (64 * resLen) + SD.bn_v m2 = SD.bn_v a * (pow2 256 - S.q)) val mul_pow2_256_minus_q_lt_lemma: p:nat -> a:nat{a < pow2 p} -> Lemma (a * (pow2 256 - S.q) < pow2 (p + 129)) let mul_pow2_256_minus_q_lt_lemma p a = Math.Lemmas.lemma_mult_lt_right (pow2 256 - S.q) a (pow2 p); assert_norm (pow2 256 - S.q < pow2 129); Math.Lemmas.lemma_mult_lt_left (pow2 p) (pow2 256 - S.q) (pow2 129); Math.Lemmas.pow2_plus p 129 val carry_is_zero (c d e a:nat) : Lemma (requires a < pow2 d /\ e < pow2 d /\ c * pow2 d + e = a) (ensures c = 0) let carry_is_zero c d e a = () val mul_pow2_256_minus_q_add_lemma: len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat -> a:lseq uint64 len -> e:lseq uint64 4 -> Lemma (requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen) (ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) let mul_pow2_256_minus_q_add_lemma len resLen d a e = let c0, m = mul_pow2_256_minus_q_lseq len resLen a in // a * SECP256K1_N_C mul_pow2_256_minus_q_lemma len resLen a; assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = SD.bn_v a * (pow2 256 - S.q)); mul_pow2_256_minus_q_lt_lemma d (SD.bn_v a); assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (d + 129)); Math.Lemmas.pow2_lt_compat (64 * resLen) (d + 129); assert (SD.bn_v a * (pow2 256 - S.q) < pow2 (64 * resLen)); SD.bn_eval_bound m resLen; assert (SD.bn_v m < pow2 (64 * resLen)); carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) (SD.bn_v a * (pow2 256 - S.q)); assert (v c0 = 0 /\ SD.bn_v m = SD.bn_v a * (pow2 256 - S.q)); let c1, res = SB.bn_add m e in // e + a * SECP256K1_N_C SB.bn_add_lemma m e; assert (v c1 * pow2 (64 * resLen) + SD.bn_v res == SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e); SD.bn_eval_bound e 4; assert (SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256) val mul_pow2_256_minus_q_add_lemma_carry_is_zero: len:size_nat -> resLen:size_nat{2 + len <= resLen /\ 4 <= resLen} -> d:nat -> a:lseq uint64 len -> e:lseq uint64 4 -> f:nat -> Lemma (requires SD.bn_v a < pow2 d /\ d + 129 < 64 * resLen /\ 256 <= f /\ d + 129 <= f /\ f + 1 < 64 * resLen) (ensures (let c, res = mul_pow2_256_minus_q_lseq_add len resLen a e in v c * pow2 (64 * resLen) + SD.bn_v res = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e /\ v c = 0 /\ SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e < pow2 (d + 129) + pow2 256)) let mul_pow2_256_minus_q_add_lemma_carry_is_zero len resLen d a e f = let c0, m = mul_pow2_256_minus_q_lseq_add len resLen a e in mul_pow2_256_minus_q_add_lemma len resLen d a e; let rhs_m = SD.bn_v a * (pow2 256 - S.q) + SD.bn_v e in assert (v c0 * pow2 (64 * resLen) + SD.bn_v m = rhs_m); assert (rhs_m < pow2 (d + 129) + pow2 256); Math.Lemmas.pow2_le_compat f 256; Math.Lemmas.pow2_le_compat f (d + 129); Math.Lemmas.pow2_double_sum f; assert (rhs_m < pow2 (f + 1)); Math.Lemmas.pow2_lt_compat (64 * resLen) (f + 1); carry_is_zero (v c0) (64 * resLen) (SD.bn_v m) rhs_m; assert (v c0 = 0 /\ SD.bn_v m = rhs_m) val lemma_m_bound: m:lseq uint64 7 -> Lemma (requires SD.bn_v m < pow2 385 + pow2 256) (ensures SD.bn_v (sub m 4 3) < pow2 130) let lemma_m_bound m = Math.Lemmas.pow2_lt_compat 385 256; Math.Lemmas.pow2_double_sum 385; SD.bn_eval_split_i m 4; assert (SD.bn_v m - SD.bn_v (sub m 0 4) = pow2 256 * SD.bn_v (sub m 4 3)); Math.Lemmas.cancel_mul_div (SD.bn_v (sub m 4 3)) (pow2 256); Math.Lemmas.lemma_div_lt (SD.bn_v m - SD.bn_v (sub m 0 4)) 386 256; assert (SD.bn_v (sub m 4 3) < pow2 130) val lemma_p_bound: p:lseq uint64 5 -> Lemma (requires SD.bn_v p < pow2 259 + pow2 256) (ensures SD.bn_v (sub p 4 1) < pow2 4) let lemma_p_bound p = Math.Lemmas.pow2_lt_compat 259 256; Math.Lemmas.pow2_double_sum 259; SD.bn_eval_split_i p 4; assert (SD.bn_v p - SD.bn_v (sub p 0 4) = pow2 256 * SD.bn_v (sub p 4 1)); Math.Lemmas.cancel_mul_div (SD.bn_v (sub p 4 1)) (pow2 256); Math.Lemmas.lemma_div_lt (SD.bn_v p - SD.bn_v (sub p 0 4)) 260 256; assert (SD.bn_v (sub p 4 1) < pow2 4) val mod_lseq_before_final_lemma_aux: a:lseq uint64 8 -> Lemma (let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in v c0 = 0 /\ SD.bn_v m = rhs_a /\ v c1 = 0 /\ SD.bn_v p = rhs_m /\ v c2 * pow2 256 + SD.bn_v r = rhs_p /\ rhs_p < pow2 133 + pow2 256) let mod_lseq_before_final_lemma_aux a = let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in SD.bn_eval_bound (sub a 4 4) 4; mul_pow2_256_minus_q_add_lemma_carry_is_zero 4 7 256 (sub a 4 4) (sub a 0 4) 385; assert (v c0 = 0 /\ SD.bn_v m = rhs_a /\ rhs_a < pow2 385 + pow2 256); let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in lemma_m_bound m; mul_pow2_256_minus_q_add_lemma_carry_is_zero 3 5 130 (sub m 4 3) (sub m 0 4) 259; assert (v c1 = 0 /\ SD.bn_v p = rhs_m); ///\ rhs_m < pow2 259 + pow2 256); let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C lemma_p_bound p; mul_pow2_256_minus_q_add_lemma 1 4 4 (sub p 4 1) (sub p 0 4); let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in assert (v c2 * pow2 256 + SD.bn_v r = rhs_p); assert (rhs_p < pow2 133 + pow2 256) val lemma_b_pow2_256_plus_a_modq (a b: nat) : Lemma ((b * pow2 256 + a) % S.q = (b * (pow2 256 - S.q) + a) % S.q) let lemma_b_pow2_256_plus_a_modq a b = calc (==) { (b * (pow2 256 - S.q) + a) % S.q; (==) { Math.Lemmas.distributivity_sub_right b (pow2 256) S.q } (b * pow2 256 - b * S.q + a) % S.q; (==) { Math.Lemmas.lemma_mod_sub (b * pow2 256 + a) S.q b } (b * pow2 256 + a) % S.q; } val lemma_b_pow2_256_plus_a_modq_lseq: len:size_nat{4 <= len} -> a:lseq uint64 len -> Lemma (SD.bn_v a % S.q == (SD.bn_v (sub a 4 (len - 4)) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4)) % S.q) let lemma_b_pow2_256_plus_a_modq_lseq len a = lemma_b_pow2_256_plus_a_modq (SD.bn_v (sub a 0 4)) (SD.bn_v (sub a 4 (len - 4))); SD.bn_eval_split_i a 4 val mod_lseq_before_final_lemma: a:lseq uint64 8 -> Lemma (let (c, res) = mod_lseq_before_final a in v c * pow2 256 + SD.bn_v res < pow2 133 + pow2 256 /\ (v c * pow2 256 + SD.bn_v res) % S.q == SD.bn_v a % S.q) let mod_lseq_before_final_lemma a = let c0, m = mul_pow2_256_minus_q_lseq_add 4 7 (sub a 4 4) (sub a 0 4) in // a[0..3] + a[4..7] * SECP256K1_N_C let c1, p = mul_pow2_256_minus_q_lseq_add 3 5 (sub m 4 3) (sub m 0 4) in // m[0..3] + m[4..6] * SECP256K1_N_C let c2, r = mul_pow2_256_minus_q_lseq_add 1 4 (sub p 4 1) (sub p 0 4) in // p[0..3] + p[4] * SECP256K1_N_C let rhs_a = SD.bn_v (sub a 4 4) * (pow2 256 - S.q) + SD.bn_v (sub a 0 4) in let rhs_m = SD.bn_v (sub m 4 3) * (pow2 256 - S.q) + SD.bn_v (sub m 0 4) in let rhs_p = SD.bn_v (sub p 4 1) * (pow2 256 - S.q) + SD.bn_v (sub p 0 4) in mod_lseq_before_final_lemma_aux a; assert (v c0 = 0 /\ SD.bn_v m = rhs_a); assert (v c1 = 0 /\ SD.bn_v p = rhs_m); assert (v c2 * pow2 256 + SD.bn_v r = rhs_p); assert (rhs_p < pow2 133 + pow2 256); calc (==) { //(v c2 * pow2 256 + SD.bn_v r) % S.q; rhs_p % S.q; (==) { lemma_b_pow2_256_plus_a_modq_lseq 5 p } SD.bn_v p % S.q; (==) { } rhs_m % S.q; (==) { lemma_b_pow2_256_plus_a_modq_lseq 7 m } SD.bn_v m % S.q; (==) { } rhs_a % S.q; (==) { lemma_b_pow2_256_plus_a_modq_lseq 8 a } SD.bn_v a % S.q; } val mod_lseq_lemma: a:lseq uint64 8 -> Lemma (SD.bn_v (mod_lseq a) == SD.bn_v a % S.q) let mod_lseq_lemma a = let c0, r = mod_lseq_before_final a in mod_lseq_before_final_lemma a; assert ((v c0 * pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q); assert (v c0 * pow2 256 + SD.bn_v r < pow2 256 + pow2 133); let (t0,t1,t2,t3) = make_pow2_256_minus_order_k256 () in let tmp = create4 t0 t1 t2 t3 in qas_nat4_is_qas_nat tmp; assert (SD.bn_v tmp = pow2 256 - S.q); let c1, out = SB.bn_add r tmp in SB.bn_add_lemma r tmp; assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q); Math.Lemmas.small_mod (v c0 + v c1) (pow2 64); assert (v (c0 +. c1) == v c0 + v c1); let mask = u64 0 -. (c0 +. c1) in //let mask = u64 0 -. c1 in let res = map2 (BB.mask_select mask) out r in SD.bn_eval_bound r 4; SD.bn_eval_bound out 4; lemma_check_overflow (SD.bn_v r); lemma_get_carry_from_bn_add (SD.bn_v out) (v c1); assert (v c1 = (if SD.bn_v r < S.q then 0 else 1)); if v c0 = 0 then begin assert (SD.bn_v r % S.q == SD.bn_v a % S.q); assert (res == mod_short_lseq r); mod_short_lseq_lemma r; assert (SD.bn_v res == SD.bn_v a % S.q) end else begin // v c0 = 1 ==> v c1 = 0 assert ((pow2 256 + SD.bn_v r) % S.q == SD.bn_v a % S.q); assert (v c1 * pow2 256 + SD.bn_v out = SD.bn_v r + pow2 256 - S.q); assert (SD.bn_v r < pow2 133); assert_norm (pow2 256 - S.q < pow2 129); Math.Lemmas.pow2_lt_compat 133 129; Math.Lemmas.pow2_double_sum 133; assert (SD.bn_v r + pow2 256 - S.q < pow2 134); Math.Lemmas.pow2_lt_compat 256 134; carry_is_zero (v c1) 256 (SD.bn_v out) (SD.bn_v r + pow2 256 - S.q); assert (v c1 = 0); assert_norm (pow2 134 < S.q); assert (SD.bn_v r + pow2 256 - S.q < S.q); BB.lseq_mask_select_lemma out r mask; assert (SD.bn_v res == SD.bn_v r + pow2 256 - S.q); Math.Lemmas.lemma_mod_sub (pow2 256 + SD.bn_v r) S.q 1; assert (SD.bn_v res % S.q == SD.bn_v a % S.q); Math.Lemmas.small_mod (SD.bn_v res) S.q end val qmul_shift_383_mod_2_lemma : l:lseq uint64 8 ->
{ "checked_file": "/", "dependencies": [ "Spec.K256.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.K256.Scalar.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "Hacl.Spec.Bignum.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.K256.Scalar.Lemmas.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Spec.K256", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.K256.Scalar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Lib.Sequence.lseq Lib.IntTypes.uint64 8 -> FStar.Pervasives.Lemma (ensures Lib.IntTypes.v l.[ 5 ] / Prims.pow2 63 = Hacl.Spec.Bignum.Definitions.bn_v l / Prims.pow2 383 % 2)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.Sequence.lseq", "Lib.IntTypes.uint64", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Sequence.op_String_Access", "Prims.pow2", "Prims.op_Modulus", "Hacl.Spec.Bignum.Definitions.bn_v", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_index", "Prims.squash", "FStar.Math.Lemmas.pow2_modulo_division_lemma_1", "FStar.Math.Lemmas.division_multiplication_lemma", "FStar.Math.Lemmas.pow2_plus", "FStar.Pervasives.assert_norm", "Prims.b2t", "Prims.op_Equality" ]
[]
false
false
true
false
false
let qmul_shift_383_mod_2_lemma l =
calc ( == ) { v l.[ 5 ] / pow2 63; ( == ) { SD.bn_eval_index l 5 } SD.bn_v l / pow2 320 % pow2 64 / pow2 63; ( == ) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 320 384 } SD.bn_v l % pow2 384 / pow2 320 / pow2 63; ( == ) { Math.Lemmas.division_multiplication_lemma (SD.bn_v l % pow2 384) (pow2 320) (pow2 63) } SD.bn_v l % pow2 384 / (pow2 320 * pow2 63); ( == ) { Math.Lemmas.pow2_plus 320 63 } SD.bn_v l % pow2 384 / pow2 383; ( == ) { Math.Lemmas.pow2_modulo_division_lemma_1 (SD.bn_v l) 383 384 } SD.bn_v l / pow2 383 % pow2 1; ( == ) { assert_norm (pow2 1 = 2) } SD.bn_v l / pow2 383 % 2; }
false
FStar.Order.fst
FStar.Order.ne
val ne : order -> bool
val ne : order -> bool
let ne o = o <> Eq
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 28, "start_col": 0, "start_line": 28 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Order.order -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_disEquality", "FStar.Order.Eq", "Prims.bool" ]
[]
false
false
false
true
false
let ne o =
o <> Eq
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.nsize_public
val nsize_public : a: Spec.Agile.DH.algorithm -> FStar.UInt32.t
let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 26, "start_col": 0, "start_line": 23 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> FStar.UInt32.t
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "FStar.UInt32.__uint_to_t", "FStar.UInt32.t" ]
[]
false
false
false
true
false
let nsize_public (a: DH.algorithm) =
match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul
false
FStar.Order.fst
FStar.Order.ge
val ge : order -> bool
val ge : order -> bool
let ge o = o <> Lt
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 22, "start_col": 0, "start_line": 22 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Order.order -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_disEquality", "FStar.Order.Lt", "Prims.bool" ]
[]
false
false
false
true
false
let ge o =
o <> Lt
false
FStar.Order.fst
FStar.Order.le
val le : order -> bool
val le : order -> bool
let le o = o <> Gt
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 25, "start_col": 0, "start_line": 25 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Order.order -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_disEquality", "FStar.Order.Gt", "Prims.bool" ]
[]
false
false
false
true
false
let le o =
o <> Gt
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.nsize_key
val nsize_key : a: Spec.Agile.DH.algorithm -> FStar.UInt32.t
let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 20, "start_col": 0, "start_line": 17 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1"
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> FStar.UInt32.t
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "FStar.UInt32.__uint_to_t", "FStar.UInt32.t" ]
[]
false
false
false
true
false
let nsize_key (a: DH.algorithm) =
match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul
false
FStar.Order.fst
FStar.Order.order_from_int
val order_from_int : int -> order
val order_from_int : int -> order
let order_from_int i = if i < 0 then Lt else if i = 0 then Eq else Gt
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 52, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt val eq : order -> bool let eq o = o = Eq // Lexicographical combination, thunked to be lazy val lex : order -> (unit -> order) -> order let lex o1 o2 = match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> FStar.Order.order
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.op_LessThan", "FStar.Order.Lt", "Prims.bool", "Prims.op_Equality", "FStar.Order.Eq", "FStar.Order.Gt", "FStar.Order.order" ]
[]
false
false
false
true
false
let order_from_int i =
if i < 0 then Lt else if i = 0 then Eq else Gt
false
FStar.Order.fst
FStar.Order.gt
val gt : order -> bool
val gt : order -> bool
let gt o = o = Gt
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 32, "start_col": 0, "start_line": 32 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency...
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Order.order -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_Equality", "FStar.Order.Gt", "Prims.bool" ]
[]
false
false
false
true
false
let gt o =
o = Gt
false
FStar.Order.fst
FStar.Order.compare_int
val compare_int : int -> int -> order
val compare_int : int -> int -> order
let compare_int i j = order_from_int (i - j)
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 61, "start_col": 0, "start_line": 61 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt val eq : order -> bool let eq o = o = Eq // Lexicographical combination, thunked to be lazy val lex : order -> (unit -> order) -> order let lex o1 o2 = match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt val order_from_int : int -> order let order_from_int i = if i < 0 then Lt else if i = 0 then Eq else Gt val int_of_order : order -> int let int_of_order = function | Lt -> (-1) | Eq -> 0 | Gt -> 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.int -> j: Prims.int -> FStar.Order.order
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "FStar.Order.order_from_int", "Prims.op_Subtraction", "FStar.Order.order" ]
[]
false
false
false
true
false
let compare_int i j =
order_from_int (i - j)
false
FStar.Order.fst
FStar.Order.lex
val lex : order -> (unit -> order) -> order
val lex : order -> (unit -> order) -> order
let lex o1 o2 = match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 14, "end_line": 46, "start_col": 0, "start_line": 42 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt val eq : order -> bool let eq o = o = Eq // Lexicographical combination, thunked to be lazy
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o1: FStar.Order.order -> o2: (_: Prims.unit -> FStar.Order.order) -> FStar.Order.order
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.unit", "FStar.Order.Lt", "FStar.Order.Gt" ]
[]
false
false
false
true
false
let lex o1 o2 =
match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt
false
FStar.Order.fst
FStar.Order.lt
val lt : order -> bool
val lt : order -> bool
let lt o = o = Lt
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 35, "start_col": 0, "start_line": 35 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Order.order -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_Equality", "FStar.Order.Lt", "Prims.bool" ]
[]
false
false
false
true
false
let lt o =
o = Lt
false
FStar.Order.fst
FStar.Order.eq
val eq : order -> bool
val eq : order -> bool
let eq o = o = Eq
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 38, "start_col": 0, "start_line": 38 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: FStar.Order.order -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_Equality", "FStar.Order.Eq", "Prims.bool" ]
[]
false
false
false
true
false
let eq o =
o = Eq
false
FStar.Order.fst
FStar.Order.compare_option
val compare_option : ('a -> 'a -> order) -> option 'a -> option 'a -> order
val compare_option : ('a -> 'a -> order) -> option 'a -> option 'a -> order
let compare_option f x y = match x, y with | None , None -> Eq | None , Some _ -> Lt | Some _ , None -> Gt | Some x , Some y -> f x y
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 85, "start_col": 0, "start_line": 80 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt val eq : order -> bool let eq o = o = Eq // Lexicographical combination, thunked to be lazy val lex : order -> (unit -> order) -> order let lex o1 o2 = match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt val order_from_int : int -> order let order_from_int i = if i < 0 then Lt else if i = 0 then Eq else Gt val int_of_order : order -> int let int_of_order = function | Lt -> (-1) | Eq -> 0 | Gt -> 1 val compare_int : int -> int -> order let compare_int i j = order_from_int (i - j) (* * It promises to call the comparator in strictly smaller elements * Useful when writing a comparator for an inductive type, * that contains the list of itself as an argument to one of its * data constructors *) let rec compare_list (#a:Type) (l1 l2:list a) (f:(x:a{x << l1} -> y:a{y << l2} -> order)) : order = match l1, l2 with | [], [] -> Eq | [], _ -> Lt | _, [] -> Gt | x::xs, y::ys -> lex (f x y) (fun _ -> compare_list xs ys f)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: 'a -> _: 'a -> FStar.Order.order) -> x: FStar.Pervasives.Native.option 'a -> y: FStar.Pervasives.Native.option 'a -> FStar.Order.order
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Mktuple2", "FStar.Order.Eq", "FStar.Order.Lt", "FStar.Order.Gt" ]
[]
false
false
false
true
false
let compare_option f x y =
match x, y with | None, None -> Eq | None, Some _ -> Lt | Some _, None -> Gt | Some x, Some y -> f x y
false
FStar.Order.fst
FStar.Order.compare_list
val compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order)) : order
val compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order)) : order
let rec compare_list (#a:Type) (l1 l2:list a) (f:(x:a{x << l1} -> y:a{y << l2} -> order)) : order = match l1, l2 with | [], [] -> Eq | [], _ -> Lt | _, [] -> Gt | x::xs, y::ys -> lex (f x y) (fun _ -> compare_list xs ys f)
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 65, "end_line": 77, "start_col": 0, "start_line": 69 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt val eq : order -> bool let eq o = o = Eq // Lexicographical combination, thunked to be lazy val lex : order -> (unit -> order) -> order let lex o1 o2 = match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt val order_from_int : int -> order let order_from_int i = if i < 0 then Lt else if i = 0 then Eq else Gt val int_of_order : order -> int let int_of_order = function | Lt -> (-1) | Eq -> 0 | Gt -> 1 val compare_int : int -> int -> order let compare_int i j = order_from_int (i - j) (* * It promises to call the comparator in strictly smaller elements * Useful when writing a comparator for an inductive type, * that contains the list of itself as an argument to one of its * data constructors
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: Prims.list a -> l2: Prims.list a -> f: (x: a{x << l1} -> y: a{y << l2} -> FStar.Order.order) -> FStar.Order.order
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Prims.precedes", "FStar.Order.order", "FStar.Pervasives.Native.Mktuple2", "FStar.Order.Eq", "FStar.Order.Lt", "FStar.Order.Gt", "FStar.Order.lex", "Prims.unit", "FStar.Order.compare_list" ]
[ "recursion" ]
false
false
false
false
false
let rec compare_list (#a: Type) (l1 l2: list a) (f: (x: a{x << l1} -> y: a{y << l2} -> order)) : order =
match l1, l2 with | [], [] -> Eq | [], _ -> Lt | _, [] -> Gt | x :: xs, y :: ys -> lex (f x y) (fun _ -> compare_list xs ys f)
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.dh_st
val dh_st : a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0
let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False))
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 43, "start_col": 0, "start_line": 29 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Spec.Agile.DH.serialized_point", "FStar.Seq.Base.equal", "Lib.Buffer.as_seq", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Pervasives.Native.uu___is_None", "Prims.l_False", "Prims.logical", "FStar.Pervasives.Native.option", "Spec.Agile.DH.dh" ]
[]
false
false
false
true
true
let dh_st (a: DH.algorithm) (p: Type0) =
o: lbuffer uint8 (nsize_public a) -> k: lbuffer uint8 (nsize_key a) -> i: lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ (as_seq h1 o) `Seq.equal` (Some?.v output) | 1ul -> None? output | _ -> False))
false
FStar.Order.fst
FStar.Order.int_of_order
val int_of_order : order -> int
val int_of_order : order -> int
let int_of_order = function | Lt -> (-1) | Eq -> 0 | Gt -> 1
{ "file_name": "ulib/FStar.Order.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 13, "end_line": 58, "start_col": 0, "start_line": 55 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Order type order = | Lt | Eq | Gt // Some derived checks val ge : order -> bool let ge o = o <> Lt val le : order -> bool let le o = o <> Gt val ne : order -> bool let ne o = o <> Eq // Just for completeness and consistency... val gt : order -> bool let gt o = o = Gt val lt : order -> bool let lt o = o = Lt val eq : order -> bool let eq o = o = Eq // Lexicographical combination, thunked to be lazy val lex : order -> (unit -> order) -> order let lex o1 o2 = match o1 with | Lt -> Lt | Eq -> o2 () | Gt -> Gt val order_from_int : int -> order let order_from_int i = if i < 0 then Lt else if i = 0 then Eq else Gt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Order.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: FStar.Order.order -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.Order.order", "Prims.op_Minus", "Prims.int" ]
[]
false
false
false
true
false
let int_of_order =
function | Lt -> (- 1) | Eq -> 0 | Gt -> 1
false
IfcMonitor.fst
IfcMonitor.interpret_exp
val interpret_exp (h: heap) (env: label_fun) (e: exp) : Tot (int * label)
val interpret_exp (h: heap) (env: label_fun) (e: exp) : Tot (int * label)
let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 106, "end_line": 92, "start_col": 0, "start_line": 92 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.DM4F.Heap.IntStoreFixed.heap -> env: IfcMonitor.label_fun -> e: IfcMonitor.exp -> Prims.int * Label.label
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.label_fun", "IfcMonitor.exp", "IfcMonitor.interpret_exp_st", "FStar.Pervasives.Native.tuple2", "Prims.int", "Label.label" ]
[]
false
false
false
true
false
let interpret_exp (h: heap) (env: label_fun) (e: exp) : Tot (int * label) =
reify (interpret_exp_st env e) h
false
IfcMonitor.fst
IfcMonitor.decr_while
val decr_while : heap -> com -> GTot nat
val decr_while : heap -> com -> GTot nat
let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 103, "start_col": 0, "start_line": 100 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *)
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.DM4F.Heap.IntStoreFixed.heap -> c: IfcMonitor.com -> Prims.GTot Prims.nat
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.com", "IfcMonitor.exp", "IfcMonitor.metric", "IfcMonitor.interpret_exp'", "Prims.nat" ]
[]
false
false
false
false
false
let decr_while h c =
match c with | While c b v -> interpret_exp' h v | _ -> 0
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.secret_to_public_st
val secret_to_public_st : a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0
let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False))
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 20, "end_line": 58, "start_col": 0, "start_line": 46 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False))
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> p: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Spec.Agile.DH.serialized_point", "FStar.Seq.Base.equal", "Lib.Buffer.as_seq", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Pervasives.Native.uu___is_None", "Prims.l_False", "Prims.logical", "FStar.Pervasives.Native.option", "Spec.Agile.DH.secret_to_public" ]
[]
false
false
false
true
true
let secret_to_public_st (a: DH.algorithm) (p: Type0) =
o: lbuffer uint8 (nsize_public a) -> i: lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ (as_seq h1 o) `Seq.equal` (Some?.v output) | 1ul -> None? output | _ -> False))
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.secret_to_public_c51
val secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True
val secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True
let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 73, "start_col": 0, "start_line": 71 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.DH.secret_to_public_st Spec.Agile.DH.DH_Curve25519 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Spec.Agile.DH.DH_Curve25519", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.__uint_to_t", "FStar.UInt32.t", "Prims.unit", "Hacl.Curve25519_51.secret_to_public" ]
[]
false
false
false
true
false
let secret_to_public_c51:secret_to_public_st (DH.DH_Curve25519) True =
fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul
false
IfcMonitor.fst
IfcMonitor.interpret_exp_st
val interpret_exp_st (env: label_fun) (e: exp) : ISFR.ISRNull (int * label)
val interpret_exp_st (env: label_fun) (e: exp) : ISFR.ISRNull (int * label)
let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 88, "start_col": 0, "start_line": 78 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *)
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
env: IfcMonitor.label_fun -> e: IfcMonitor.exp -> FStar.DM4F.IntStoreFixedReader.ISRNull (Prims.int * Label.label)
FStar.DM4F.IntStoreFixedReader.ISRNull
[]
[]
[ "IfcMonitor.label_fun", "IfcMonitor.exp", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "Label.label", "Label.Low", "FStar.Pervasives.Native.tuple2", "FStar.DM4F.Heap.IntStoreFixed.id", "FStar.DM4F.IntStoreFixedReader.read", "IfcMonitor.binop", "IfcMonitor.interpret_binop", "Label.join", "IfcMonitor.interpret_exp_st" ]
[ "recursion" ]
false
true
false
false
false
let rec interpret_exp_st (env: label_fun) (e: exp) : ISFR.ISRNull (int * label) =
match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a, l1 = interpret_exp_st env e1 in let b, l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2
false
IfcMonitor.fst
IfcMonitor.interpret_binop
val interpret_binop : o:binop -> a:int -> b:int -> Tot int
val interpret_binop : o:binop -> a:int -> b:int -> Tot int
let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 38, "start_col": 0, "start_line": 33 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
o: IfcMonitor.binop -> a: Prims.int -> b: Prims.int -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "IfcMonitor.binop", "Prims.int", "Prims.op_Addition", "Prims.op_Subtraction", "Prims.op_Multiply", "Prims.op_GreaterThanOrEqual", "Prims.bool" ]
[]
false
false
false
true
false
let interpret_binop o a b =
match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a
false
IfcMonitor.fst
IfcMonitor.interpret_exp'
val interpret_exp' (h: heap) (e: exp) : Tot nat
val interpret_exp' (h: heap) (e: exp) : Tot nat
let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 96, "start_col": 0, "start_line": 94 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.DM4F.Heap.IntStoreFixed.heap -> e: IfcMonitor.exp -> Prims.nat
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.exp", "Prims.int", "Label.label", "Prims.op_GreaterThan", "Prims.bool", "Prims.nat", "FStar.Pervasives.Native.tuple2", "IfcMonitor.interpret_exp", "FStar.DM4F.Heap.IntStoreFixed.id", "Label.Low" ]
[]
false
false
false
true
false
let interpret_exp' (h: heap) (e: exp) : Tot nat =
let n, _ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n
false
IfcMonitor.fst
IfcMonitor.interpret_com
val interpret_com (h0: heap) (c: com) (env: label_fun) (pc: label) : Tot (option heap)
val interpret_com (h0: heap) (c: com) (env: label_fun) (pc: label) : Tot (option heap)
let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 166, "start_col": 0, "start_line": 162 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *)
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h0: FStar.DM4F.Heap.IntStoreFixed.heap -> c: IfcMonitor.com -> env: IfcMonitor.label_fun -> pc: Label.label -> FStar.Pervasives.Native.option FStar.DM4F.Heap.IntStoreFixed.heap
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.com", "IfcMonitor.label_fun", "Label.label", "IfcMonitor.interpret_com_st", "Prims.unit", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let interpret_com (h0: heap) (c: com) (env: label_fun) (pc: label) : Tot (option heap) =
match (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None
false
Benton2004.fst
Benton2004.d_lu2
val d_lu2 (b: exp bool) (c: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip)))))
val d_lu2 (b: exp bool) (c: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip)))))
let d_lu2 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (while b (seq c (ifthenelse b c skip))) in let eb = reify_exp b in let rec prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) (decreases fuel) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); if fst (eb s1) then begin let s2 = snd (fc (fuel - 1) s1) in assert (fl fuel s0 == fl (fuel - 2) s2); assert (fc fuel s1 == fc (fuel - 1) s1); assert (fr fuel s0 == fr (fuel - 1) s2); prf1 s2 (fuel - 2); assert (fr (fuel - 1) s2 == fr (fuel - 2) s2) end else () end else () in let rec prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fl (fuel + fuel) s0 == fr fuel s0)) (decreases fuel) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in if fst (eb s1) then begin let s2 = snd (fc fuel s1) in assert (fr fuel s0 == fr (fuel - 1) s2); prf2 s2 (fuel - 1); assert (fl ((fuel - 1) + (fuel - 1)) s2 == fr (fuel - 1) s2); assert (fl (fuel + fuel) s0 == fl ((fuel + fuel) - 1) s1); assert (fl (fuel + fuel) s0 == fl (fuel - 1 + fuel - 1) s2) end else begin assert (fl (fuel + fuel) s0 == fr fuel s0) end end else () in let prf1' (s0:heap) (fuel:nat) :Lemma (fst (fl fuel s0) == true ==> fr fuel s0 == fl fuel s0) = Classical.move_requires (prf1 s0) fuel in let prf2' (s0:heap) (fuel:nat) :Lemma (fst (fr fuel s0) == true ==> fl (fuel + fuel) s0 == fr fuel s0) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf1'; //AR: same pattern as in Pointer, see the comment there Classical.forall_intro_2 prf2'
{ "file_name": "examples/rel/Benton2004.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 813, "start_col": 0, "start_line": 749 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Benton2004 include Benton2004.Aux include FStar.DM4F.Heap.IntStoreFixed include FStar.DM4F.IntStoreFixed type reified_raw_computation = (nat -> heap -> GTot (bool * heap) ) let fuel_monotonic (f: reified_raw_computation) : GTot Type0 = forall (fuel fuel' : nat) h .{:pattern has_type fuel nat; has_type fuel' nat; has_type h heap} ( fuel <= fuel' /\ fst (f fuel h) == true ) ==> ( f fuel' h == f fuel h ) type reified_computation = (f: reified_raw_computation { fuel_monotonic f } ) let reified_computation_elim (f: reified_computation) (fuel fuel' : nat) (h: _) : Lemma (requires (fuel <= fuel' /\ fst (f fuel h) == true)) (ensures (f fuel' h == f fuel h)) = () type raw_computation = (fuel: nat) -> ISNull bool let reify_raw_computation (f : raw_computation) : reified_raw_computation = fun n h -> reify (f n) h type computation = (f: raw_computation { fuel_monotonic (reify_raw_computation f) }) let reify_computation (c: computation) : GTot reified_computation = reify_raw_computation c let skip : computation = let f (fuel: nat) : ISNull bool = true in f type var = id #set-options "--z3rlimit 128 --max_fuel 8 --max_ifuel 8" type exp (t: Type0) : Type0 = unit -> IntStore t (requires (fun _ -> True)) (ensures (fun h _ h' -> h' == h)) let reified_exp (t: Type0) : Tot Type0 = (h: heap) -> Ghost (t * heap) (requires True) (ensures (fun rh -> snd rh == h)) let reify_exp (#t: Type0) (e: exp t) : GTot (reified_exp t) = let f = reify (e ()) in f let const (#t: Type0) (v: t) : Tot (exp t) = fun _ -> v let evar (x: var) : Tot (exp int) = fun _ -> read x let assign (r: var) (n: exp int) : Tot computation = let g _ : ISNull bool = let n = n () in write r n; true in g let ifthenelse (b: exp bool) (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if b () then c1 fuel else c2 fuel in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in let e = reify_exp b in ( (forall fuel h . fst (e h) == true ==> f fuel h == f1 fuel h) /\ (forall fuel h . fst (e h) == false ==> f fuel h == f2 fuel h) )); g let seq (c1 c2: computation) : Tot computation = let g (fuel: nat) : ISNull bool = if c1 fuel then c2 fuel else false in admit (); assert ( let f : reified_raw_computation = let h fuel = reify (g fuel) in h in let f1 = reify_computation c1 in let f2 = reify_computation c2 in (forall fuel h . fst (f fuel h) == true <==> (fst (f1 fuel h) == true /\ fst (f2 fuel (snd (f1 fuel h))) == true)) /\ (forall fuel h . fst (f fuel h) == true ==> f fuel h == f2 fuel (snd (f1 fuel h))) ); g let rec while_raw (b: exp bool) (c: computation) (fuel: nat) : ISNull bool (decreases fuel) = if b () then if c fuel then if fuel = 0 then false else while_raw b c (fuel - 1) else false else true let fuel_monotonic_while (b: exp bool) (c: computation) (f: reified_raw_computation) : Lemma (requires (forall fuel h . f fuel h == reify (while_raw b c fuel) h)) (ensures ( fuel_monotonic f )) = admit (); let f (fuel: nat) = reify (while_raw b c fuel) in let fb = reify_exp b in let fc = reify_computation c in let rec prf (fuel fuel' : nat) (h: heap) : Lemma (requires ( fuel <= fuel' /\ fst (f fuel h) == true )) (ensures (f fuel' h == f fuel h)) (decreases fuel) = let (_, h1) = f fuel h in let (_, h1') = f fuel' h in let (b0, _) = fb h in if b0 then begin let (_, h') = fc fuel h in prf (fuel - 1) (fuel' - 1) h' end else () in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf x y)) let while (b: exp bool) (c: computation) : Tot computation = let f : raw_computation = while_raw b c in let g = reify_raw_computation f in fuel_monotonic_while b c g; f (* Termination *) let terminates_on (f: reified_computation) (h: heap) : GTot Type0 = exists fuel . fst (f fuel h) == true let included (#t: Type0) (r1 r2: rel t) : GTot Type0 = forall x y . holds r1 x y ==> holds r2 x y let is_per (#t: Type0) (f: rel t) : GTot Type0 = (forall x1 x2 . f x1 x2 <==> f x2 x1) /\ (forall x1 x2 x3 . (f x1 x2 /\ f x2 x3) ==> f x1 x3) let is_per_holds_sym (#t: Type0) (p: rel t) (s s' : t) : Lemma (requires (is_per p)) (ensures (holds p s s' <==> holds p s' s)) [SMTPat (holds p s s')] = holds_equiv p s s'; holds_equiv p s' s let per_holds_trans (#t: Type0) (f: rel t) (x1 x2 x3: t) : Lemma (requires (is_per f /\ holds f x1 x2 /\ holds f x2 x3)) (ensures (holds f x1 x3)) [SMTPatOr [ [SMTPat (holds f x1 x2); SMTPat (holds f x2 x3)]; [SMTPat (holds f x1 x2); SMTPat (holds f x1 x3)]; [SMTPat (holds f x2 x3); SMTPat (holds f x1 x3)]; ]] = holds_equiv f x1 x2; holds_equiv f x2 x3; holds_equiv f x1 x3 let intersect (#t: Type0) (ns1 ns2: rel t) : GTot (rel t) = let f x y = holds ns1 x y /\ holds ns2 x y in Classical.forall_intro_2 (holds_equiv f); f let holds_intersect (#t: Type0) (ns1 ns2: rel t) (x y: t) : Lemma (holds (intersect ns1 ns2) x y <==> (holds ns1 x y /\ holds ns2 x y)) [SMTPat (holds (intersect ns1 ns2) x y)] = holds_equiv (intersect ns1 ns2) x y type nstype (t: Type0) = rel t let interpolable (#t: Type0) (f: rel t) : GTot Type0 = forall (x1 x3 : t) . f x1 x3 ==> (exists x2 . f x1 x2 /\ f x2 x3) let interpolable_elim (#t: Type0) (f: rel t) (x1 x3: t) : Lemma (requires (interpolable f /\ holds f x1 x3)) (ensures (exists x2 . holds f x1 x2 /\ holds f x2 x3)) = Classical.forall_intro_2 (holds_equiv f) type sttype = rel heap (* 3.1.3. Judgements *) let eval_equiv_reified (#t: Type0) (p: sttype) (e: nstype t) (f f': reified_exp t) : GTot Type0 = forall (s s' : heap) . holds p s s' ==> holds e (fst (f s)) (fst (f' s')) let eval_equiv (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : GTot Type0 = let f = reify_exp f in let f' = reify_exp f' in eval_equiv_reified p e f f' let terminates_equiv_reified (p : sttype) (f f' : reified_computation) : GTot Type0 = forall s s' . holds p s s' ==> (terminates_on f s <==> terminates_on f' s') let terminates_equiv_reified_sym (p : sttype) (f f' : reified_computation) : Lemma (requires (terminates_equiv_reified p f f' /\ is_per p)) (ensures (terminates_equiv_reified p f' f)) = () let exec_equiv_reified (p p' : sttype) (f f' : reified_computation) : GTot Type0 = terminates_equiv_reified p f f' /\ (forall (s s' : heap) (fuel: nat) . (holds p s s' /\ fst (f fuel s) == true /\ fst (f' fuel s') == true) ==> holds p' (snd (f fuel s)) (snd (f' fuel s'))) let exec_equiv (p p' : sttype) (f f' : computation) : GTot Type0 = let f = reify_computation f in let f' = reify_computation f' in exec_equiv_reified p p' f f' (* Flipping a relation *) let flip (#t: Type0) (r: rel t) : Tot (rel t) = let g x y = holds r y x in g let holds_flip (#t: Type0) (r: rel t) : Lemma (forall x y . holds (flip r) x y <==> holds r y x) = Classical.forall_intro_2 (holds_equiv (flip r)) let holds_flip' (#t: Type0) (r: rel t) x y : Lemma (ensures (holds (flip r) x y <==> holds r y x)) [SMTPat (holds (flip r) x y)] = holds_flip r let eval_equiv_flip (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (eval_equiv (flip p) (flip e) f' f <==> eval_equiv p e f f') [SMTPat (eval_equiv (flip p) (flip e) f' f)] = holds_flip p; holds_flip e let exec_equiv_flip (p p': sttype) (f f' : computation) : Lemma (exec_equiv (flip p) (flip p') f f' <==> exec_equiv p p' f' f) [SMTPat (exec_equiv (flip p) (flip p') f f')] = holds_flip p; holds_flip p' (* Lemma 2 *) let eval_equiv_sym (#t: Type0) (p: sttype) (e: nstype t) (f f': exp t) : Lemma (requires (is_per p /\ is_per e /\ eval_equiv p e f f')) (ensures (eval_equiv p e f' f)) = () let exec_equiv_sym (p p': sttype) (f f' : computation) : Lemma (requires (is_per p /\ is_per p')) (ensures (exec_equiv p p' f f' <==> exec_equiv p p' f' f)) [SMTPat (exec_equiv p p' f f')] = () #push-options "--z3rlimit 5 --max_fuel 0 --max_ifuel 0" let eval_equiv_trans (#t: Type0) (p: sttype) (e: nstype t) (f1 f2 f3 : exp t) : Lemma (requires (is_per e /\ interpolable p /\ eval_equiv p e f1 f2 /\ eval_equiv p e f2 f3)) (ensures eval_equiv p e f1 f3) = let lem (s1 s3:heap) : Lemma (requires holds p s1 s3) (ensures (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3)))) = let w = interpolable_elim p s1 s3 in Classical.exists_elim (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f3 s3))) w (fun (s2:heap{holds p s1 s2 /\ holds p s2 s3}) -> assert (holds e (fst (reify_exp f1 s1)) (fst (reify_exp f2 s2))); assert (holds e (fst (reify_exp f2 s2)) (fst (reify_exp f3 s3)))) in Classical.forall_intro_2 (fun x -> Classical.move_requires (lem x)) #pop-options let exec_equiv_reified_trans (p p': sttype) (f1 f2 f3 : reified_computation) : Lemma (requires (is_per p' /\ interpolable p /\ exec_equiv_reified p p' f1 f2 /\ exec_equiv_reified p p' f2 f3)) (ensures (exec_equiv_reified p p' f1 f3)) = let prf1 (s1 s3 : heap) : Lemma (requires (holds p s1 s3)) (ensures (terminates_on f1 s1 <==> terminates_on f3 s3)) = interpolable_elim p s1 s3 in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s1 s3: heap) (fuel: nat) : Lemma (requires (holds p s1 s3 /\ fst (f1 fuel s1) == true /\ fst (f3 fuel s3) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = interpolable_elim p s1 s3; let g (s2: heap) : Lemma (requires (holds p s1 s2 /\ holds p s2 s3)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = let g' (fuel' : nat) : Lemma (requires (fst (f2 fuel' s2) == true)) (ensures (holds p' (snd (f1 fuel s1)) (snd (f3 fuel s3)))) = assert (f1 (fuel + fuel') s1 == f1 fuel s1); assert (f2 (fuel + fuel') s2 == f2 fuel' s2); assert (f3 (fuel + fuel') s3 == f3 fuel s3); assert (holds p' (snd (f1 (fuel + fuel') s1)) (snd (f2 (fuel + fuel') s2))) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) let exec_equiv_trans (p p' : sttype) (c1 c2 c3 : computation) : Lemma (requires ( is_per p' /\ interpolable p /\ exec_equiv p p' c1 c2 /\ exec_equiv p p' c2 c3 )) (ensures (exec_equiv p p' c1 c3)) [SMTPatOr [ [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c2 c3)]; [SMTPat (exec_equiv p p' c1 c2); SMTPat (exec_equiv p p' c1 c3)]; [SMTPat (exec_equiv p p' c2 c3); SMTPat (exec_equiv p p' c1 c3)]; ]] = let z1 = reify_computation c1 in let z2 = reify_computation c2 in let z3 = reify_computation c3 in exec_equiv_reified_trans p p' z1 z2 z3 (* Figure 2. Theorem 1. *) let d_esub (#t: Type0) (f f' : exp t) (ph ph': sttype) (p p': nstype t) : Lemma (requires ( eval_equiv ph p f f' /\ included ph' ph /\ included p p' )) (ensures (eval_equiv ph' p' f f')) [SMTPat (eval_equiv ph' p' f f'); SMTPat (eval_equiv ph p f f')] = () let d_csub (p1 p2 p1' p2' : sttype) (f f' : computation) : Lemma (requires ( exec_equiv p1 p2 f f' /\ included p1' p1 /\ included p2 p2' )) (ensures (exec_equiv p1' p2' f f')) [SMTPat (exec_equiv p1' p2' f f'); SMTPat (exec_equiv p1 p2 f f')] = () let eop (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e2: exp from) : Tot (exp to) = fun () -> (e1 ()) `op` (e2 ()) (* Definition 1 *) let op_abs (#from #to: Type0) (op: (from -> from -> Tot to)) (ns1 ns2: nstype from) (ns: nstype to) : GTot Type0 = forall x x' y y' . (holds ns1 x x' /\ holds ns2 y y') ==> holds ns (op x y) (op x' y') let d_op (#from #to: Type0) (op: (from -> from -> Tot to)) (e1 e1' e2 e2': exp from) (ns1 ns2: nstype from) (ns: nstype to) (phi: sttype) : Lemma (requires ( eval_equiv phi ns1 e1 e1' /\ eval_equiv phi ns2 e2 e2' /\ op_abs op ns1 ns2 ns )) (ensures (eval_equiv phi ns (eop op e1 e2) (eop op e1' e2'))) = () (* Commands *) let d_skip (p: sttype) : Lemma (exec_equiv p p skip skip) [SMTPat (exec_equiv p p skip skip)] = () #set-options "--z3rlimit 1024" let d_seq_terminates (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01 c12)) s0 )) (ensures ( terminates_on (reify_computation (seq c01' c12')) s0' )) = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let g (fuel: nat) : Lemma (requires (fst (f01 fuel s0) == true /\ fst (f01' fuel s0') == true)) (ensures (terminates_on f' s0')) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1'); assert (reify_computation (seq c01' c12') fuel s0' == (reify_computation c12') fuel s1'); assert (terminates_on f12' s1'); let g' (fuel' : nat) : Lemma (requires (fst (f12' fuel' s1') == true)) (ensures (terminates_on f' s0')) = assert (f01' (fuel + fuel') s0' == (true, s1')); assert (f12' (fuel + fuel') s1' == f12' fuel' s1'); assert (f' (fuel + fuel') s0' == f12' (fuel + fuel') s1'); assert (fst (f' (fuel + fuel') s0') == true) in Classical.forall_intro (Classical.move_requires g') in Classical.forall_intro (Classical.move_requires g) (* We now need to prove the converse, too, because p is not necessarily a PER. *) let d_seq_terminates_recip (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) (s0 s0': heap) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' /\ holds p0 s0 s0' /\ terminates_on (reify_computation (seq c01' c12')) s0' )) (ensures ( terminates_on (reify_computation (seq c01 c12)) s0 )) = holds_flip' p0 s0' s0; d_seq_terminates (flip p0) (flip p1) (flip p2) c01' c01 c12' c12 s0' s0 let d_seq (p0 p1 p2 : sttype) (c01 c01' c12 c12' : computation) : Lemma (requires ( exec_equiv p0 p1 c01 c01' /\ exec_equiv p1 p2 c12 c12' )) (ensures ( exec_equiv p0 p2 (seq c01 c12) (seq c01' c12') )) [SMTPatOr [ [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p1 p2 c12 c12')]; [SMTPat (exec_equiv p0 p1 c01 c01'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; [SMTPat (exec_equiv p1 p2 c12 c12'); SMTPat (exec_equiv p0 p2 (seq c01 c12) (seq c01' c12'))]; ]] = let f01 = reify_computation c01 in let f01' = reify_computation c01' in let f12 = reify_computation c12 in let f12' = reify_computation c12' in let f = reify_computation (seq c01 c12) in let f' = reify_computation (seq c01' c12') in let prf1 (s0 s0' : heap) : Lemma (requires (holds p0 s0 s0')) (ensures (terminates_on f s0 <==> terminates_on f' s0')) = Classical.move_requires (d_seq_terminates p0 p1 p2 c01 c01' c12 c12' s0) s0'; Classical.move_requires (d_seq_terminates_recip p0 p1 p2 c01 c01' c12 c12' s0) s0' in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0 s0': heap) (fuel: nat) : Lemma (requires (holds p0 s0 s0' /\ fst (f fuel s0) == true /\ fst (f' fuel s0') == true)) (ensures (holds p2 (snd (f fuel s0)) (snd (f' fuel s0')))) = let k01 = f01 fuel s0 in let k01' = f01' fuel s0' in let s1 = snd k01 in let s1' = snd k01' in assert (holds p1 s1 s1') in Classical.forall_intro_3 (fun x y -> Classical.move_requires (prf2 x y)) (* 3.1 Basic equations *) let d_su1 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq skip c) c)) [SMTPat (exec_equiv phi phi' (seq skip c) c)] = () let d_su1' (c c' c'' : computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' c skip /\ exec_equiv phi' phi'' c' c'' )) (ensures (exec_equiv phi phi'' (seq c c') c'')) [SMTPatOr [ [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi' phi'' c' c''); SMTPat (exec_equiv phi phi'' (seq c c') c'')]; [SMTPat (exec_equiv phi phi' c skip); SMTPat (exec_equiv phi' phi'' c' c'')]; ]] = assert (exec_equiv phi phi'' (seq c c') (seq skip c'')) ; let f1 = reify_computation (seq skip c'') in let f2 = reify_computation c'' in assert (forall fuel s0 . f1 fuel s0 == f2 fuel s0) // NOTE: this rule is NOT a consequence of d_su1 + d_seq + d_ctr let d_su2 (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' c c)) (ensures (exec_equiv phi phi' (seq c skip) c)) [SMTPat (exec_equiv phi phi' (seq c skip) c)] = () let d_assoc (c1 c2 c3: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq (seq c1 c2) c3))) (ensures (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))) [SMTPat (exec_equiv phi phi' (seq (seq c1 c2) c3) (seq c1 (seq c2 c3)))] = let fl = reify_computation (seq (seq c1 c2) c3) in let fr = reify_computation (seq c1 (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel) let d_cc (b: exp bool) (c1 c2 c3: computation) (phi phi' phi'' : sttype) : Lemma (requires ( exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2) /\ exec_equiv phi' phi'' c3 c3 )) (ensures ( exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)) )) [SMTPatOr [ [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi' phi'' c3 c3)]; [SMTPat (exec_equiv phi phi' (ifthenelse b c1 c2) (ifthenelse b c1 c2)); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; [SMTPat (exec_equiv phi' phi'' c3 c3); SMTPat (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (ifthenelse b (seq c1 c3) (seq c2 c3)))]; ]] = let fl = reify_computation (seq (ifthenelse b c1 c2) c3) in let fr = reify_computation (ifthenelse b (seq c1 c3) (seq c2 c3)) in assert (forall s0 fuel . fl s0 fuel == fr s0 fuel); assert (exec_equiv phi phi'' (seq (ifthenelse b c1 c2) c3) (seq (ifthenelse b c1 c2) c3)) #restart-solver let d_lu1 (b: exp bool) (c: computation) (phi phi' : sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (ifthenelse b (seq c (while b c)) skip))) = let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (ifthenelse b (seq c (while b c)) skip) in let eb = reify_exp b in let prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) = if fst (eb s0) then begin let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); assert (fr fuel s0 == fl fuel s1) end else () in Classical.forall_intro_2 (fun x -> Classical.move_requires (prf1 x)); let prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fst (fr fuel s0) == true /\ fl (fuel + 1) s0 == fr fuel s0)) = if fst (eb s0) then begin () end else () in let prf2' (s0: heap) (fuel: nat) : Lemma (ensures (fst (fr fuel s0) == true ==> fl (fuel + 1) s0 == fr fuel s0)) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf2'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked", "FStar.Classical.fsti.checked", "Benton2004.Aux.fsti.checked" ], "interface_file": false, "source_file": "Benton2004.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Benton2004.Aux", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 8, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 1024, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Benton2004.exp Prims.bool -> c: Benton2004.computation -> phi: Benton2004.sttype -> phi': Benton2004.sttype -> FStar.Pervasives.Lemma (requires Benton2004.exec_equiv phi phi' (Benton2004.while b c) (Benton2004.while b c)) (ensures Benton2004.exec_equiv phi phi' (Benton2004.while b c) (Benton2004.while b (Benton2004.seq c (Benton2004.ifthenelse b c Benton2004.skip))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Benton2004.exp", "Prims.bool", "Benton2004.computation", "Benton2004.sttype", "FStar.Classical.forall_intro_2", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.nat", "Prims.l_imp", "Prims.eq2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.tuple2", "Prims.op_Addition", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.move_requires", "Prims._assert", "Prims.op_Subtraction", "FStar.Pervasives.Native.snd", "Benton2004.reified_exp", "Benton2004.reify_exp", "Benton2004.reified_computation", "Benton2004.reify_computation", "Benton2004.while", "Benton2004.seq", "Benton2004.ifthenelse", "Benton2004.skip", "Benton2004.exec_equiv" ]
[]
false
false
true
false
false
let d_lu2 (b: exp bool) (c: computation) (phi phi': sttype) : Lemma (requires (exec_equiv phi phi' (while b c) (while b c))) (ensures (exec_equiv phi phi' (while b c) (while b (seq c (ifthenelse b c skip))))) =
let fc = reify_computation c in let fl = reify_computation (while b c) in let fr = reify_computation (while b (seq c (ifthenelse b c skip))) in let eb = reify_exp b in let rec prf1 (s0: heap) (fuel: nat) : Lemma (requires (fst (fl fuel s0) == true)) (ensures (fr fuel s0 == fl fuel s0)) (decreases fuel) = if fst (eb s0) then let s1 = snd (fc fuel s0) in assert (fl fuel s0 == fl (fuel - 1) s1); if fst (eb s1) then let s2 = snd (fc (fuel - 1) s1) in assert (fl fuel s0 == fl (fuel - 2) s2); assert (fc fuel s1 == fc (fuel - 1) s1); assert (fr fuel s0 == fr (fuel - 1) s2); prf1 s2 (fuel - 2); assert (fr (fuel - 1) s2 == fr (fuel - 2) s2) in let rec prf2 (s0: heap) (fuel: nat) : Lemma (requires (fst (fr fuel s0) == true)) (ensures (fl (fuel + fuel) s0 == fr fuel s0)) (decreases fuel) = if fst (eb s0) then let s1 = snd (fc fuel s0) in if fst (eb s1) then let s2 = snd (fc fuel s1) in assert (fr fuel s0 == fr (fuel - 1) s2); prf2 s2 (fuel - 1); assert (fl ((fuel - 1) + (fuel - 1)) s2 == fr (fuel - 1) s2); assert (fl (fuel + fuel) s0 == fl ((fuel + fuel) - 1) s1); assert (fl (fuel + fuel) s0 == fl (fuel - 1 + fuel - 1) s2) else assert (fl (fuel + fuel) s0 == fr fuel s0) in let prf1' (s0: heap) (fuel: nat) : Lemma (fst (fl fuel s0) == true ==> fr fuel s0 == fl fuel s0) = Classical.move_requires (prf1 s0) fuel in let prf2' (s0: heap) (fuel: nat) : Lemma (fst (fr fuel s0) == true ==> fl (fuel + fuel) s0 == fr fuel s0) = Classical.move_requires (prf2 s0) fuel in Classical.forall_intro_2 prf1'; Classical.forall_intro_2 prf2'
false
IfcMonitor.fst
IfcMonitor.interpret_com_st
val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c])
val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c])
let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 156, "start_col": 0, "start_line": 112 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0))
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: IfcMonitor.com -> h0: FStar.DM4F.Heap.IntStoreFixed.heap -> env: IfcMonitor.label_fun -> pc: Label.label -> FStar.DM4F.IntStoreExcFixed.IntStoreExc Prims.unit
FStar.DM4F.IntStoreExcFixed.IntStoreExc
[ "" ]
[]
[ "IfcMonitor.com", "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.label_fun", "Label.label", "Prims.unit", "FStar.DM4F.Heap.IntStoreFixed.id", "IfcMonitor.exp", "Prims.int", "Label.op_Less_Equals", "Label.join", "FStar.DM4F.IntStoreExcFixed.write", "Prims.bool", "FStar.DM4F.IntStoreExcFixed.raise_", "FStar.Pervasives.Native.tuple2", "IfcMonitor.interpret_exp_st", "IfcMonitor.interpret_com_st", "FStar.DM4F.IntStoreFixed.get", "Prims.op_Equality", "IfcMonitor.metric", "Prims.op_disEquality", "Prims.op_GreaterThan", "Prims.nat", "IfcMonitor.interpret_exp'" ]
[ "recursion" ]
false
true
false
false
false
let rec interpret_com_st c h0 env pc =
match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then write x v else raise_ () | Seq c1 c2 -> let h1 = (X.get ()) in interpret_com_st c1 h1 env pc; let h2 = (X.get ()) in interpret_com_st c2 h2 env pc | If e ct cf -> let v, l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get ()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get () in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ ()
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.change_error_code
val change_error_code (r: uint64) : Pure UInt32.t (requires v r = 0 \/ v r = pow2 64 - 1) (ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
val change_error_code (r: uint64) : Pure UInt32.t (requires v r = 0 \/ v r = pow2 64 - 1) (ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0))
let change_error_code (r:uint64) : Pure UInt32.t (requires v r = 0 \/ v r = pow2 64 - 1) (ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) = let r' = logand r (u64 1) in logand_mask r (u64 1) 1; let r' = cast U32 SEC r' in Lib.RawIntTypes.u32_to_UInt32 r'
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 107, "start_col": 0, "start_line": 101 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res inline_for_extraction noextract let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) inline_for_extraction noextract let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i -> Hacl.Curve25519_64.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_64.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res // TODO: After unification of error codes, this should be removed
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Lib.IntTypes.uint64 -> Prims.Pure FStar.UInt32.t
Prims.Pure
[]
[]
[ "Lib.IntTypes.uint64", "Lib.RawIntTypes.u32_to_UInt32", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.SEC", "Prims.eq2", "Prims.int", "Lib.IntTypes.v", "Lib.IntTypes.op_At_Percent_Dot", "Lib.IntTypes.U64", "Lib.IntTypes.cast", "Prims.unit", "Lib.IntTypes.logand_mask", "Lib.IntTypes.u64", "Lib.IntTypes.logand", "FStar.UInt32.t", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Prims.op_Subtraction", "Prims.pow2", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "Prims.l_iff" ]
[]
false
false
false
false
false
let change_error_code (r: uint64) : Pure UInt32.t (requires v r = 0 \/ v r = pow2 64 - 1) (ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) =
let r' = logand r (u64 1) in logand_mask r (u64 1) 1; let r' = cast U32 SEC r' in Lib.RawIntTypes.u32_to_UInt32 r'
false
IfcMonitor.fst
IfcMonitor.dyn_ifc_exp
val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in lr = ll /\ (Low? lr ==> vl = vr)))
val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in lr = ll /\ (Low? lr ==> vl = vr)))
let rec dyn_ifc_exp e h env = match e with | AInt _ -> () | AVar _ -> () | AOp _ e1 e2 -> dyn_ifc_exp e1 h env; dyn_ifc_exp e2 h env
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 61, "end_line": 333, "start_col": 0, "start_line": 329 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc)) let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h) #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c]) let rec high_pc c h env pc = match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then begin let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then begin high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'' end end | While e body v -> let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin high_pc c h' env pc end end end end; high_pc_while e body v h env pc #reset-options #set-options "--z3rlimit 15 " val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 15, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: IfcMonitor.exp -> h: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap -> env: IfcMonitor.label_fun -> FStar.Pervasives.Lemma (requires IfcMonitor.low_equiv env h) (ensures (let _ = IfcMonitor.interpret_exp (R?.l h) env e in (let FStar.Pervasives.Native.Mktuple2 #_ #_ vl ll = _ in let _ = IfcMonitor.interpret_exp (R?.r h) env e in (let FStar.Pervasives.Native.Mktuple2 #_ #_ vr lr = _ in lr = ll /\ (Low? lr ==> vl = vr)) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "IfcMonitor.exp", "Rel.rel", "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.label_fun", "Prims.int", "FStar.DM4F.Heap.IntStoreFixed.id", "IfcMonitor.binop", "IfcMonitor.dyn_ifc_exp", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec dyn_ifc_exp e h env =
match e with | AInt _ -> () | AVar _ -> () | AOp _ e1 e2 -> dyn_ifc_exp e1 h env; dyn_ifc_exp e2 h env
false
IfcMonitor.fst
IfcMonitor.dyn_ifc_assign
val dyn_ifc_assign : (x:id) -> (e:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type (Assign x e) env pc h))
val dyn_ifc_assign : (x:id) -> (e:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type (Assign x e) env pc h))
let dyn_ifc_assign x e env pc h = dyn_ifc_exp e h env
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 355, "start_col": 0, "start_line": 355 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc)) let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h) #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c]) let rec high_pc c h env pc = match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then begin let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then begin high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'' end end | While e body v -> let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin high_pc c h' env pc end end end end; high_pc_while e body v h env pc #reset-options #set-options "--z3rlimit 15 " val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in lr = ll /\ (Low? lr ==> vl = vr))) let rec dyn_ifc_exp e h env = match e with | AInt _ -> () | AVar _ -> () | AOp _ e1 e2 -> dyn_ifc_exp e1 h env; dyn_ifc_exp e2 h env type ifc_type (c:com) (env:label_fun) (pc:label) (h:rel heap) = begin let ol = (interpret_com (R?.l h) c env pc) in let or = (interpret_com (R?.r h) c env pc) in if (Some? ol && Some? or) then begin let h' = R (Some?.v ol) (Some?.v or) in low_equiv env h' end else True end #set-options "--z3rlimit 30 " val dyn_ifc_assign : (x:id) -> (e:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h))
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.DM4F.Heap.IntStoreFixed.id -> e: IfcMonitor.exp -> env: IfcMonitor.label_fun -> pc: Label.label -> h: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap -> FStar.Pervasives.Lemma (requires IfcMonitor.low_equiv env h) (ensures IfcMonitor.ifc_type (IfcMonitor.Assign x e) env pc h)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.id", "IfcMonitor.exp", "IfcMonitor.label_fun", "Label.label", "Rel.rel", "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.dyn_ifc_exp", "Prims.unit" ]
[]
true
false
true
false
false
let dyn_ifc_assign x e env pc h =
dyn_ifc_exp e h env
false
IfcMonitor.fst
IfcMonitor.dyn_ifc
val dyn_ifc : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures ((fun r1 r2 -> (Some? r1 /\ Some? r2) ==> (fun hl hr -> (low_equiv env (R hl hr))) (Some?.v r1) (Some?.v r2)) (interpret_com (R?.l h) c env pc) (interpret_com (R?.r h) c env pc)))
val dyn_ifc : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures ((fun r1 r2 -> (Some? r1 /\ Some? r2) ==> (fun hl hr -> (low_equiv env (R hl hr))) (Some?.v r1) (Some?.v r2)) (interpret_com (R?.l h) c env pc) (interpret_com (R?.r h) c env pc)))
let dyn_ifc c env pc h = dyn_ifc' c env pc h; high_pc c (R?.l h) env pc
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 587, "start_col": 0, "start_line": 585 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc)) let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h) #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c]) let rec high_pc c h env pc = match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then begin let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then begin high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'' end end | While e body v -> let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin high_pc c h' env pc end end end end; high_pc_while e body v h env pc #reset-options #set-options "--z3rlimit 15 " val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in lr = ll /\ (Low? lr ==> vl = vr))) let rec dyn_ifc_exp e h env = match e with | AInt _ -> () | AVar _ -> () | AOp _ e1 e2 -> dyn_ifc_exp e1 h env; dyn_ifc_exp e2 h env type ifc_type (c:com) (env:label_fun) (pc:label) (h:rel heap) = begin let ol = (interpret_com (R?.l h) c env pc) in let or = (interpret_com (R?.r h) c env pc) in if (Some? ol && Some? or) then begin let h' = R (Some?.v ol) (Some?.v or) in low_equiv env h' end else True end #set-options "--z3rlimit 30 " val dyn_ifc_assign : (x:id) -> (e:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type (Assign x e) env pc h)) let dyn_ifc_assign x e env pc h = dyn_ifc_exp e h env #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 2 " val dyn_ifc_while : (e:exp) -> (body:com) -> (v:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h /\ begin let R hl hr = h in let c = While e body v in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin ifc_type body env (join ll pc) h /\ begin let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then ifc_type c env pc (R hl' hr') else True end end else True | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then ifc_type c env pc (R hl' hr) else True end else True | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then ifc_type c env pc (R hl hr') else True end else True | false, false -> True end)) (ensures (ifc_type (While e body v) env pc h)) let dyn_ifc_while e body v env pc h = let R hl hr = h in let c = While e body v in let rl = interpret_com hl c env pc in let rr = interpret_com hr c env pc in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in dyn_ifc_exp e h env; match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc) in let or = interpret_com hr body env (join lr pc) in if (Some? ol && Some? or) then begin begin cut (ifc_type body env (join ll pc) h); let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then begin cut (ifc_type c env pc (R hl' hr')); cut (rl = interpret_com hl' c env pc); cut (rr = interpret_com hr' c env pc) end end end | true, false -> cut (High? ll); let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then begin cut (ifc_type c env pc (R hl' hr)); cut (rl = interpret_com hl' c env pc) end end | false, true -> cut (High? lr); let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then begin cut (ifc_type c env pc (R hl hr')); cut (rr = interpret_com hr' c env pc) end end | false, false -> () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val dyn_ifc' : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type c env pc h)) (decreases %[c; decr_while (R?.l h) c + decr_while (R?.r h) c]) let rec dyn_ifc' c env pc h = let (R hl hr) = h in if Low? pc then begin match c with | Skip -> () | Assign x e -> dyn_ifc_assign x e env pc h | If e ct cf -> dyn_ifc_exp e h env; (match interpret_exp hl env e, interpret_exp hr env e with | (0, ll) , (0, lr) -> dyn_ifc' cf env (join ll pc) h | (0, ll) , (_, lr) -> cut (High? ll); high_pc cf hl env High; high_pc ct hr env High | (_, ll) , (0, lr) -> cut (High? ll); high_pc ct hl env High; high_pc cf hr env High | (_, ll) , (_, lr) -> dyn_ifc' ct env (join ll pc) h) | Seq c1 c2 -> let ol = interpret_com hl c1 env pc in let or = interpret_com hr c1 env pc in if (Some? ol && Some? or) then begin dyn_ifc' c1 env pc h; let hl' = Some?.v ol in let hr' = Some?.v or in dyn_ifc' c2 env pc (R hl' hr') end | While e body v -> dyn_ifc_exp e h env; let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in (match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin dyn_ifc' body env (join ll pc) h; let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then dyn_ifc' c env pc (R hl' hr') end | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then begin dyn_ifc' c env pc (R hl' hr) end end | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then begin dyn_ifc' c env pc (R hl hr') end end | false, false -> ()); dyn_ifc_while e body v env pc h end else begin high_pc c hl env pc; high_pc c hr env pc end #reset-options val dyn_ifc : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures ((fun r1 r2 -> (Some? r1 /\ Some? r2) ==> (fun hl hr -> (low_equiv env (R hl hr))) (Some?.v r1) (Some?.v r2)) (interpret_com (R?.l h) c env pc)
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: IfcMonitor.com -> env: IfcMonitor.label_fun -> pc: Label.label -> h: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap -> FStar.Pervasives.Lemma (requires IfcMonitor.low_equiv env h) (ensures Some? (IfcMonitor.interpret_com (R?.l h) c env pc) /\ Some? (IfcMonitor.interpret_com (R?.r h) c env pc) ==> IfcMonitor.low_equiv env (Rel.R (Some?.v (IfcMonitor.interpret_com (R?.l h) c env pc)) (Some?.v (IfcMonitor.interpret_com (R?.r h) c env pc))))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "IfcMonitor.com", "IfcMonitor.label_fun", "Label.label", "Rel.rel", "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.high_pc", "Rel.__proj__R__item__l", "Prims.unit", "IfcMonitor.dyn_ifc'" ]
[]
true
false
true
false
false
let dyn_ifc c env pc h =
dyn_ifc' c env pc h; high_pc c (R?.l h) env pc
false
IfcMonitor.fst
IfcMonitor.high_pc_while
val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc))
val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc))
let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h)
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 259, "start_col": 0, "start_line": 226 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True))
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: IfcMonitor.exp -> body: IfcMonitor.com -> v: IfcMonitor.exp -> h: FStar.DM4F.Heap.IntStoreFixed.heap -> env: IfcMonitor.label_fun -> pc: Label.label -> FStar.Pervasives.Lemma (requires (let c = IfcMonitor.While e body v in let _ = IfcMonitor.interpret_exp h env e in (let FStar.Pervasives.Native.Mktuple2 #_ #_ v0 l = _ in (match v0 <> 0 with | true -> let o = IfcMonitor.interpret_com h body env (Label.join l pc) in (match Some? o with | true -> let h' = Some?.v o in IfcMonitor.high_pc_type body h env (Label.join l pc) /\ (let m0 = IfcMonitor.interpret_exp' h v in let m1 = IfcMonitor.interpret_exp' h' v in (match m0 > m1 with | true -> let o2 = IfcMonitor.interpret_com h' c env pc in (match Some? o2 with | true -> let h'' = Some?.v o2 in IfcMonitor.high_pc_type c h' env pc | _ -> Prims.l_True) <: Prims.logical | _ -> Prims.l_True) <: Prims.logical) | _ -> Prims.l_True) <: Type0 | _ -> Prims.l_True) <: Type0) <: Type0)) (ensures IfcMonitor.high_pc_type (IfcMonitor.While e body v) h env pc)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "IfcMonitor.exp", "IfcMonitor.com", "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.label_fun", "Label.label", "Prims.int", "Prims.op_disEquality", "FStar.Pervasives.Native.uu___is_Some", "Prims.op_GreaterThan", "IfcMonitor.no_sens_trans", "Label.join", "Prims.unit", "Prims.cut", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "FStar.Pervasives.Native.__proj__Some__item__v", "IfcMonitor.high_pc_type", "Prims.bool", "FStar.Pervasives.Native.uu___is_None", "FStar.Pervasives.Native.option", "IfcMonitor.interpret_com", "Prims.nat", "IfcMonitor.interpret_exp'", "FStar.Pervasives.Native.tuple2", "IfcMonitor.interpret_exp", "IfcMonitor.While" ]
[]
false
false
true
false
false
let high_pc_while e body v h env pc =
let c = While e body v in let r = interpret_com h c env pc in let v0, l = interpret_exp h env e in if v0 <> 0 then let o = interpret_com h body env (join l pc) in if Some? o then let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then let o2 = interpret_com h' c env pc in if Some? o2 then let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' else cut (None? r) else cut (None? r) else cut (None? r) else cut (Some? r /\ Some?.v r = h)
false
IfcMonitor.fst
IfcMonitor.high_pc
val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c])
val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c])
let rec high_pc c h env pc = match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then begin let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then begin high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'' end end | While e body v -> let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin high_pc c h' env pc end end end end; high_pc_while e body v h env pc
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 316, "start_col": 0, "start_line": 269 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc)) let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h) #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc)
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: IfcMonitor.com -> h: FStar.DM4F.Heap.IntStoreFixed.heap -> env: IfcMonitor.label_fun -> pc: Label.label -> FStar.Pervasives.Lemma (ensures IfcMonitor.high_pc_type c h env pc) (decreases %[c;IfcMonitor.decr_while h c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "IfcMonitor.com", "FStar.DM4F.Heap.IntStoreFixed.heap", "IfcMonitor.label_fun", "Label.label", "FStar.DM4F.Heap.IntStoreFixed.id", "IfcMonitor.exp", "IfcMonitor.high_pc_assign", "Prims.int", "Prims.op_AmpAmp", "Label.uu___is_Low", "Label.uu___is_High", "IfcMonitor.no_sens_upd_pc", "Prims.bool", "Prims.unit", "Prims.op_disEquality", "IfcMonitor.high_pc", "Label.join", "FStar.Pervasives.Native.tuple2", "IfcMonitor.interpret_exp", "FStar.Pervasives.Native.uu___is_Some", "IfcMonitor.no_sens_trans", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Pervasives.Native.option", "IfcMonitor.interpret_com", "IfcMonitor.metric", "IfcMonitor.high_pc_while", "Prims.op_GreaterThan", "Prims.nat", "IfcMonitor.interpret_exp'" ]
[ "recursion" ]
false
false
true
false
false
let rec high_pc c h env pc =
match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then (high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'') | While e body v -> let v0, l = interpret_exp h env e in if v0 <> 0 then (let o = interpret_com h body env (join l pc) in if Some? o then let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then let o2 = interpret_com h' c env pc in if Some? o2 then high_pc c h' env pc); high_pc_while e body v h env pc
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.secret_to_public_c64
val secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p
val secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p
let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i -> Hacl.Curve25519_64.secret_to_public o i; 0ul
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 89, "start_col": 0, "start_line": 87 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res inline_for_extraction noextract let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.DH.secret_to_public_st Spec.Agile.DH.DH_Curve25519 Hacl.HPKE.Interface.DH.vale_p
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Spec.Agile.DH.DH_Curve25519", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.__uint_to_t", "FStar.UInt32.t", "Prims.unit", "Hacl.Curve25519_64.secret_to_public" ]
[]
false
false
false
true
false
let secret_to_public_c64:secret_to_public_st (DH.DH_Curve25519) vale_p =
fun o i -> Hacl.Curve25519_64.secret_to_public o i; 0ul
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.nat_from_bytes_le_zero_is_zero
val nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n) : Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0))) (ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
val nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n) : Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0))) (ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
let rec nat_from_bytes_le_zero_is_zero (n:size_nat{n >= 1}) (s:Lib.ByteSequence.lbytes n) : Lemma (requires s `Seq.equal` Lib.Sequence.create n (u8 0)) (ensures Lib.ByteSequence.nat_from_bytes_le s == 0) = let open Lib.Sequence in let open Lib.ByteSequence in if n = 1 then nat_from_intseq_le_lemma0 s else ( nat_from_intseq_le_slice_lemma s 1; nat_from_bytes_le_zero_is_zero (n-1) (slice s 1 n); nat_from_intseq_le_lemma0 (slice s 0 1) )
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 4, "end_line": 125, "start_col": 0, "start_line": 115 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res inline_for_extraction noextract let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) inline_for_extraction noextract let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i -> Hacl.Curve25519_64.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_64.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res // TODO: After unification of error codes, this should be removed inline_for_extraction noextract let change_error_code (r:uint64) : Pure UInt32.t (requires v r = 0 \/ v r = pow2 64 - 1) (ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) = let r' = logand r (u64 1) in logand_mask r (u64 1) 1; let r' = cast U32 SEC r' in Lib.RawIntTypes.u32_to_UInt32 r' inline_for_extraction noextract let secret_to_public_p256 : secret_to_public_st (DH.DH_P256) True = fun o i -> let res = Hacl.Impl.P256.DH.ecp256dh_i o i in if res then 0ul else 1ul (* change_error_code res *)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Lib.IntTypes.size_nat{n >= 1} -> s: Lib.ByteSequence.lbytes n -> FStar.Pervasives.Lemma (requires FStar.Seq.Base.equal s (Lib.Sequence.create n (Lib.IntTypes.u8 0))) (ensures Lib.ByteSequence.nat_from_bytes_le s == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.IntTypes.size_nat", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Lib.ByteSequence.lbytes", "Prims.op_Equality", "Prims.int", "Lib.ByteSequence.nat_from_intseq_le_lemma0", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.bool", "Lib.Sequence.slice", "Lib.IntTypes.uint_t", "Prims.unit", "Hacl.HPKE.Interface.DH.nat_from_bytes_le_zero_is_zero", "Prims.op_Subtraction", "Lib.ByteSequence.nat_from_intseq_le_slice_lemma", "FStar.Seq.Base.equal", "Lib.Sequence.create", "Lib.IntTypes.u8", "Prims.squash", "Prims.eq2", "Lib.ByteSequence.nat_from_bytes_le", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec nat_from_bytes_le_zero_is_zero (n: size_nat{n >= 1}) (s: Lib.ByteSequence.lbytes n) : Lemma (requires s `Seq.equal` (Lib.Sequence.create n (u8 0))) (ensures Lib.ByteSequence.nat_from_bytes_le s == 0) =
let open Lib.Sequence in let open Lib.ByteSequence in if n = 1 then nat_from_intseq_le_lemma0 s else (nat_from_intseq_le_slice_lemma s 1; nat_from_bytes_le_zero_is_zero (n - 1) (slice s 1 n); nat_from_intseq_le_lemma0 (slice s 0 1))
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.secret_to_public_p256
val secret_to_public_p256:secret_to_public_st (DH.DH_P256) True
val secret_to_public_p256:secret_to_public_st (DH.DH_P256) True
let secret_to_public_p256 : secret_to_public_st (DH.DH_P256) True = fun o i -> let res = Hacl.Impl.P256.DH.ecp256dh_i o i in if res then 0ul else 1ul
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 112, "start_col": 0, "start_line": 110 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res inline_for_extraction noextract let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) inline_for_extraction noextract let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i -> Hacl.Curve25519_64.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_64.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res // TODO: After unification of error codes, this should be removed inline_for_extraction noextract let change_error_code (r:uint64) : Pure UInt32.t (requires v r = 0 \/ v r = pow2 64 - 1) (ensures fun r' -> UInt32.v r' <= 1 /\ (UInt32.v r' = 0 <==> v r = 0)) = let r' = logand r (u64 1) in logand_mask r (u64 1) 1; let r' = cast U32 SEC r' in Lib.RawIntTypes.u32_to_UInt32 r'
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.DH.secret_to_public_st Spec.Agile.DH.DH_P256 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Spec.Agile.DH.DH_P256", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.__uint_to_t", "Prims.bool", "FStar.UInt32.t", "Hacl.Impl.P256.DH.ecp256dh_i" ]
[]
false
false
false
true
false
let secret_to_public_p256:secret_to_public_st (DH.DH_P256) True =
fun o i -> let res = Hacl.Impl.P256.DH.ecp256dh_i o i in if res then 0ul else 1ul
false
IfcMonitor.fst
IfcMonitor.dyn_ifc'
val dyn_ifc' : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type c env pc h)) (decreases %[c; decr_while (R?.l h) c + decr_while (R?.r h) c])
val dyn_ifc' : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type c env pc h)) (decreases %[c; decr_while (R?.l h) c + decr_while (R?.r h) c])
let rec dyn_ifc' c env pc h = let (R hl hr) = h in if Low? pc then begin match c with | Skip -> () | Assign x e -> dyn_ifc_assign x e env pc h | If e ct cf -> dyn_ifc_exp e h env; (match interpret_exp hl env e, interpret_exp hr env e with | (0, ll) , (0, lr) -> dyn_ifc' cf env (join ll pc) h | (0, ll) , (_, lr) -> cut (High? ll); high_pc cf hl env High; high_pc ct hr env High | (_, ll) , (0, lr) -> cut (High? ll); high_pc ct hl env High; high_pc cf hr env High | (_, ll) , (_, lr) -> dyn_ifc' ct env (join ll pc) h) | Seq c1 c2 -> let ol = interpret_com hl c1 env pc in let or = interpret_com hr c1 env pc in if (Some? ol && Some? or) then begin dyn_ifc' c1 env pc h; let hl' = Some?.v ol in let hr' = Some?.v or in dyn_ifc' c2 env pc (R hl' hr') end | While e body v -> dyn_ifc_exp e h env; let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in (match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin dyn_ifc' body env (join ll pc) h; let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then dyn_ifc' c env pc (R hl' hr') end | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then begin dyn_ifc' c env pc (R hl' hr) end end | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then begin dyn_ifc' c env pc (R hl hr') end end | false, false -> ()); dyn_ifc_while e body v env pc h end else begin high_pc c hl env pc; high_pc c hr env pc end
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 571, "start_col": 0, "start_line": 485 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc)) let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h) #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c]) let rec high_pc c h env pc = match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then begin let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then begin high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'' end end | While e body v -> let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin high_pc c h' env pc end end end end; high_pc_while e body v h env pc #reset-options #set-options "--z3rlimit 15 " val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in lr = ll /\ (Low? lr ==> vl = vr))) let rec dyn_ifc_exp e h env = match e with | AInt _ -> () | AVar _ -> () | AOp _ e1 e2 -> dyn_ifc_exp e1 h env; dyn_ifc_exp e2 h env type ifc_type (c:com) (env:label_fun) (pc:label) (h:rel heap) = begin let ol = (interpret_com (R?.l h) c env pc) in let or = (interpret_com (R?.r h) c env pc) in if (Some? ol && Some? or) then begin let h' = R (Some?.v ol) (Some?.v or) in low_equiv env h' end else True end #set-options "--z3rlimit 30 " val dyn_ifc_assign : (x:id) -> (e:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type (Assign x e) env pc h)) let dyn_ifc_assign x e env pc h = dyn_ifc_exp e h env #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 2 " val dyn_ifc_while : (e:exp) -> (body:com) -> (v:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h /\ begin let R hl hr = h in let c = While e body v in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin ifc_type body env (join ll pc) h /\ begin let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then ifc_type c env pc (R hl' hr') else True end end else True | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then ifc_type c env pc (R hl' hr) else True end else True | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then ifc_type c env pc (R hl hr') else True end else True | false, false -> True end)) (ensures (ifc_type (While e body v) env pc h)) let dyn_ifc_while e body v env pc h = let R hl hr = h in let c = While e body v in let rl = interpret_com hl c env pc in let rr = interpret_com hr c env pc in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in dyn_ifc_exp e h env; match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc) in let or = interpret_com hr body env (join lr pc) in if (Some? ol && Some? or) then begin begin cut (ifc_type body env (join ll pc) h); let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then begin cut (ifc_type c env pc (R hl' hr')); cut (rl = interpret_com hl' c env pc); cut (rr = interpret_com hr' c env pc) end end end | true, false -> cut (High? ll); let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then begin cut (ifc_type c env pc (R hl' hr)); cut (rl = interpret_com hl' c env pc) end end | false, true -> cut (High? lr); let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then begin cut (ifc_type c env pc (R hl hr')); cut (rr = interpret_com hr' c env pc) end end | false, false -> () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val dyn_ifc' : (c:com) -> (env:label_fun) -> (pc:label) -> (h:(rel heap)) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type c env pc h))
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: IfcMonitor.com -> env: IfcMonitor.label_fun -> pc: Label.label -> h: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap -> FStar.Pervasives.Lemma (requires IfcMonitor.low_equiv env h) (ensures IfcMonitor.ifc_type c env pc h) (decreases %[c;IfcMonitor.decr_while (R?.l h) c + IfcMonitor.decr_while (R?.r h) c])
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "IfcMonitor.com", "IfcMonitor.label_fun", "Label.label", "Rel.rel", "FStar.DM4F.Heap.IntStoreFixed.heap", "Label.uu___is_Low", "FStar.DM4F.Heap.IntStoreFixed.id", "IfcMonitor.exp", "IfcMonitor.dyn_ifc_assign", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2", "Prims.int", "IfcMonitor.interpret_exp", "IfcMonitor.dyn_ifc'", "Label.join", "IfcMonitor.high_pc", "Label.High", "Prims.unit", "Prims.cut", "Prims.b2t", "Label.uu___is_High", "IfcMonitor.dyn_ifc_exp", "Prims.op_AmpAmp", "FStar.Pervasives.Native.uu___is_Some", "Rel.R", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.bool", "FStar.Pervasives.Native.option", "IfcMonitor.interpret_com", "IfcMonitor.metric", "IfcMonitor.dyn_ifc_while", "Prims.op_disEquality", "Prims.op_GreaterThan", "Prims.nat", "IfcMonitor.interpret_exp'" ]
[ "recursion" ]
false
false
true
false
false
let rec dyn_ifc' c env pc h =
let R hl hr = h in if Low? pc then match c with | Skip -> () | Assign x e -> dyn_ifc_assign x e env pc h | If e ct cf -> dyn_ifc_exp e h env; (match interpret_exp hl env e, interpret_exp hr env e with | (0, ll), (0, lr) -> dyn_ifc' cf env (join ll pc) h | (0, ll), (_, lr) -> cut (High? ll); high_pc cf hl env High; high_pc ct hr env High | (_, ll), (0, lr) -> cut (High? ll); high_pc ct hl env High; high_pc cf hr env High | (_, ll), (_, lr) -> dyn_ifc' ct env (join ll pc) h) | Seq c1 c2 -> let ol = interpret_com hl c1 env pc in let or = interpret_com hr c1 env pc in if (Some? ol && Some? or) then (dyn_ifc' c1 env pc h; let hl' = Some?.v ol in let hr' = Some?.v or in dyn_ifc' c2 env pc (R hl' hr')) | While e body v -> dyn_ifc_exp e h env; let v0l, ll = interpret_exp hl env e in let v0r, lr = interpret_exp hr env e in (match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc) in let or = interpret_com hr body env (join lr pc) in if (Some? ol && Some? or) then (dyn_ifc' body env (join ll pc) h; let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then dyn_ifc' c env pc (R hl' hr')) | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then dyn_ifc' c env pc (R hl' hr) | false, true -> let or = interpret_com hr body env High in if (Some? or) then let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then dyn_ifc' c env pc (R hl hr') | false, false -> ()); dyn_ifc_while e body v env pc h else (high_pc c hl env pc; high_pc c hr env pc)
false
IfcMonitor.fst
IfcMonitor.dyn_ifc_while
val dyn_ifc_while : (e:exp) -> (body:com) -> (v:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h /\ begin let R hl hr = h in let c = While e body v in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin ifc_type body env (join ll pc) h /\ begin let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then ifc_type c env pc (R hl' hr') else True end end else True | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then ifc_type c env pc (R hl' hr) else True end else True | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then ifc_type c env pc (R hl hr') else True end else True | false, false -> True end)) (ensures (ifc_type (While e body v) env pc h))
val dyn_ifc_while : (e:exp) -> (body:com) -> (v:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h /\ begin let R hl hr = h in let c = While e body v in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin ifc_type body env (join ll pc) h /\ begin let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then ifc_type c env pc (R hl' hr') else True end end else True | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then ifc_type c env pc (R hl' hr) else True end else True | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then ifc_type c env pc (R hl hr') else True end else True | false, false -> True end)) (ensures (ifc_type (While e body v) env pc h))
let dyn_ifc_while e body v env pc h = let R hl hr = h in let c = While e body v in let rl = interpret_com hl c env pc in let rr = interpret_com hr c env pc in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in dyn_ifc_exp e h env; match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc) in let or = interpret_com hr body env (join lr pc) in if (Some? ol && Some? or) then begin begin cut (ifc_type body env (join ll pc) h); let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then begin cut (ifc_type c env pc (R hl' hr')); cut (rl = interpret_com hl' c env pc); cut (rr = interpret_com hr' c env pc) end end end | true, false -> cut (High? ll); let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then begin cut (ifc_type c env pc (R hl' hr)); cut (rl = interpret_com hl' c env pc) end end | false, true -> cut (High? lr); let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then begin cut (ifc_type c env pc (R hl hr')); cut (rr = interpret_com hr' c env pc) end end | false, false -> ()
{ "file_name": "examples/rel/IfcMonitor.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 475, "start_col": 0, "start_line": 415 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module IfcMonitor open Rel open Label open FStar.DM4F.Heap.IntStoreFixed open FStar.DM4F.IntStoreExcFixed module ISFR = FStar.DM4F.IntStoreFixedReader module X = FStar.DM4F.IntStoreFixed type binop = | Plus | Minus | Times | Max val interpret_binop : o:binop -> a:int -> b:int -> Tot int let interpret_binop o a b = match o with | Plus -> a + b | Minus -> a - b | Times -> op_Multiply a b | Max -> if b >= a then b else a type exp = | AInt : int -> exp | AVar : id -> exp | AOp : binop -> exp -> exp -> exp (* CH: This is a termination metric (natural number expression) for showing termination of while. Decreasingness and positivity of this termination metric _dynamically_ checked. *) type metric = exp (* Commands -- loops are annotated with metrics *) type com = | Skip : com | Assign : var:id -> term:exp -> com | Seq : first:com -> second:com -> com | If : cond:exp -> then_branch:com -> else_branch:com -> com | While : cond:exp -> body:com -> metric:metric -> com type label_fun = id -> Tot label type low_equiv (env:label_fun) (h1:rel heap) = (forall (x:id). env x = Low ==> index (R?.l h1) x = index (R?.r h1) x) type no_sensitive_upd (h:heap) (env:label_fun) (pc:label) (h':heap) = forall (x:id). env x < pc ==> (index h x) = (index h' x) (* TODO : This function is total and does not use exceptions *) (* as such it wouldn't be that surprising that writing it in a *) (* exception free effect helps proving properties about it *) (* The problem is that we then need reifiable lifts from the *) (* exceptionless effect to the exceptionfull one and this not covered yet *) (* by the F* implementation. *) (* val interpret_exp_st : e:exp -> INT_STORE_EXC int (fun s0 p -> forall opt. p (opt, s0)) *) let rec interpret_exp_st (env:label_fun) (e:exp) (* : INT_STORE_EXC int (fun s0 p -> forall x. p (Some x, s0)) *) : ISFR.ISRNull (int * label) = match e with | AInt i -> i, Low | AVar x -> ISFR.read x, env x | AOp o e1 e2 -> let a,l1 = interpret_exp_st env e1 in let b,l2 = interpret_exp_st env e2 in interpret_binop o a b, join l1 l2 (* unfold *) let interpret_exp (h:heap) (env:label_fun) (e:exp) : Tot (int * label) = reify (interpret_exp_st env e) h let interpret_exp' (h:heap) (e:exp) : Tot nat = let n,_ = interpret_exp h (fun _ -> Low) e in if 0 > n then 0 else n (* function used for the decreases clause *) val decr_while : heap -> com -> GTot nat let decr_while h c = match c with | While c b v -> interpret_exp' h v | _ -> 0 exception OutOfFuel exception IfcViolation val interpret_com_st : c:com -> h0:heap -> env:label_fun -> pc:label -> IntStoreExc unit (requires (fun h -> h == h0)) (ensures (fun h _ ho -> h == h0)) (decreases %[c; decr_while h0 c]) let rec interpret_com_st c h0 env pc = match c with | Skip -> () | Assign x e -> let v, le = interpret_exp_st env e in let lx = env x in if join le pc <= lx then begin write x v end else raise_ () (* IfcViolation *) | Seq c1 c2 -> begin let h1 = (X.get()) in interpret_com_st c1 h1 env pc; let h2 = (X.get()) in interpret_com_st c2 h2 env pc end | If e ct cf -> let v,l = interpret_exp_st env e in let c = if v = 0 then cf else ct in let h = (X.get()) in interpret_com_st c h env (join l pc) | While e body v -> let v0, l = interpret_exp_st env e in if v0 <> 0 then begin (* let m0 = interpret_exp_st v in *) (* let h = X.get () in *) (* interpret_com_st body h; *) (* let m1 = interpret_exp_st v in *) (* proving recursive terminating relies of interpret_exp not *) (* changing the state? somehow F* can't prove this although *) (* interpret_exp_st has that in the spec! *) let m0 = interpret_exp' h0 v in let h1 = X.get () in interpret_com_st body h1 env (join l pc); let h2 = X.get() in let m1 = interpret_exp' h2 v in if m0 > m1 then interpret_com_st c h2 env pc else raise_ () (* OutOfFuel *) end (* TODO : Normalization does not play very well with ensures clauses... *) (* But there is no problem when replacing normalize_term by foobar where *) (* abstract let foobar (#a:Type) (x:a) : a = x *) (* unfold *) let interpret_com (h0:heap) (c:com) (env:label_fun) (pc:label) : Tot (option heap) = match (* normalize_term *) (reify (interpret_com_st c h0 env pc) h0) with | Some (), h -> Some h | None, _ -> None (* Proofs *) val no_sens_trans : (env:label_fun) -> (pc:label) -> (pc2:label) -> (h1:heap) -> (h2:heap) -> (h3:heap) -> Lemma (requires (no_sensitive_upd h1 env pc h2 /\ no_sensitive_upd h2 env pc2 h3)) (ensures (no_sensitive_upd h1 env (meet pc pc2) h3)) let no_sens_trans env pc pc2 h1 h2 h3 = () val no_sens_upd_pc : unit -> Lemma (forall env h h'. no_sensitive_upd h env High h' ==> no_sensitive_upd h env Low h') let no_sens_upd_pc () = () type high_pc_type (c:com) (h:heap) (env:label_fun) (pc:label) = begin let o = (interpret_com h c env pc) in (Some? o ==> no_sensitive_upd h env pc (Some?.v o)) end #set-options "--z3rlimit 10 " val high_pc_assign : (x:id) -> (e:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (high_pc_type (Assign x e) h env pc) let high_pc_assign x e h env pc = () #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc_while : (e:exp) -> (body:com) -> (v:exp) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires ( let c = While e body v in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc_type body h env (join l pc) /\ begin let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in high_pc_type c h' env pc end else True end else True end end else True end else True)) (ensures (high_pc_type (While e body v) h env pc)) let high_pc_while e body v h env pc = let c = While e body v in let r = interpret_com h c env pc in let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc) in if Some? o then begin let h' = Some?.v o in cut (high_pc_type body h env (join l pc)); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin let h'' = Some?.v o2 in cut (high_pc_type c h' env pc); cut (Some? r /\ Some?.v r = h''); no_sens_trans env (join l pc) pc h h' h'' end else cut(None? r) end else cut(None? r) end else cut(None? r) end else cut (Some? r /\ Some?.v r = h) #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val high_pc : (c:com) -> (h:heap) -> (env:label_fun) -> (pc:label) -> Lemma (requires True) (ensures high_pc_type c h env pc) (decreases %[c; decr_while h c]) let rec high_pc c h env pc = match c with | Skip -> () | Assign x e -> high_pc_assign x e h env pc | If e ct cf -> let v0, l = interpret_exp h env e in if v0 <> 0 then high_pc ct h env (join l pc) else high_pc cf h env (join l pc); if (Low? pc && High? l) then no_sens_upd_pc () | Seq c1 c2 -> let o = interpret_com h c1 env pc in if Some? o then begin let h' = Some?.v o in high_pc c1 h env pc; let o2 = interpret_com h' c2 env pc in if Some? o2 then begin high_pc c2 h' env pc; let h'' = Some?.v o2 in no_sens_trans env pc pc h h' h'' end end | While e body v -> let v0,l = interpret_exp h env e in if v0 <> 0 then begin let o = interpret_com h body env (join l pc)in if Some? o then begin let h' = Some?.v o in high_pc body h env (join l pc); let m0 = interpret_exp' h v in let m1 = interpret_exp' h' v in if m0 > m1 then begin let o2 = interpret_com h' c env pc in if Some? o2 then begin high_pc c h' env pc end end end end; high_pc_while e body v h env pc #reset-options #set-options "--z3rlimit 15 " val dyn_ifc_exp : (e:exp) -> (h:(rel heap)) -> (env:label_fun) -> Lemma (requires (low_equiv env h)) (ensures ( let vl,ll = interpret_exp (R?.l h) env e in let vr,lr = interpret_exp (R?.r h) env e in lr = ll /\ (Low? lr ==> vl = vr))) let rec dyn_ifc_exp e h env = match e with | AInt _ -> () | AVar _ -> () | AOp _ e1 e2 -> dyn_ifc_exp e1 h env; dyn_ifc_exp e2 h env type ifc_type (c:com) (env:label_fun) (pc:label) (h:rel heap) = begin let ol = (interpret_com (R?.l h) c env pc) in let or = (interpret_com (R?.r h) c env pc) in if (Some? ol && Some? or) then begin let h' = R (Some?.v ol) (Some?.v or) in low_equiv env h' end else True end #set-options "--z3rlimit 30 " val dyn_ifc_assign : (x:id) -> (e:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h)) (ensures (ifc_type (Assign x e) env pc h)) let dyn_ifc_assign x e env pc h = dyn_ifc_exp e h env #reset-options #set-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 2 " val dyn_ifc_while : (e:exp) -> (body:com) -> (v:exp) -> (env:label_fun) -> (pc:label) -> (h:rel heap) -> Lemma (requires (low_equiv env h /\ begin let R hl hr = h in let c = While e body v in let v0l,ll = interpret_exp hl env e in let v0r,lr = interpret_exp hr env e in match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc)in let or = interpret_com hr body env (join lr pc)in if (Some? ol && Some? or) then begin ifc_type body env (join ll pc) h /\ begin let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then ifc_type c env pc (R hl' hr') else True end end else True | true, false -> let ol = interpret_com hl body env High in if (Some? ol) then begin let hl' = Some?.v ol in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then ifc_type c env pc (R hl' hr) else True end else True | false, true -> let or = interpret_com hr body env High in if (Some? or) then begin let hr' = Some?.v or in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then ifc_type c env pc (R hl hr') else True end else True | false, false -> True end))
{ "checked_file": "/", "dependencies": [ "Rel.fst.checked", "prims.fst.checked", "label.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixedReader.fst.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.IntStoreExcFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "IfcMonitor.fst" }
[ { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixed", "short_module": "X" }, { "abbrev": true, "full_module": "FStar.DM4F.IntStoreFixedReader", "short_module": "ISFR" }, { "abbrev": false, "full_module": "FStar.DM4F.IntStoreExcFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "Label", "short_module": null }, { "abbrev": false, "full_module": "Rel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: IfcMonitor.exp -> body: IfcMonitor.com -> v: IfcMonitor.exp -> env: IfcMonitor.label_fun -> pc: Label.label -> h: Rel.rel FStar.DM4F.Heap.IntStoreFixed.heap -> FStar.Pervasives.Lemma (requires IfcMonitor.low_equiv env h /\ (let _ = h in (let Rel.R #_ hl hr = _ in let c = IfcMonitor.While e body v in let _ = IfcMonitor.interpret_exp hl env e in (let FStar.Pervasives.Native.Mktuple2 #_ #_ v0l ll = _ in let _ = IfcMonitor.interpret_exp hr env e in (let FStar.Pervasives.Native.Mktuple2 #_ #_ v0r lr = _ in (match v0l <> 0, v0r <> 0 with | FStar.Pervasives.Native.Mktuple2 #_ #_ true true -> let ol = IfcMonitor.interpret_com hl body env (Label.join ll pc) in let or = IfcMonitor.interpret_com hr body env (Label.join lr pc) in (match Some? ol && Some? or with | true -> IfcMonitor.ifc_type body env (Label.join ll pc) h /\ (let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = IfcMonitor.interpret_exp' hl v in let m1l = IfcMonitor.interpret_exp' hl' v in let m0r = IfcMonitor.interpret_exp' hr v in let m1r = IfcMonitor.interpret_exp' hr' v in (match m0l > m1l && m0r > m1r with | true -> IfcMonitor.ifc_type c env pc (Rel.R hl' hr') | _ -> Prims.l_True) <: Prims.logical) | _ -> Prims.l_True) <: Prims.logical | FStar.Pervasives.Native.Mktuple2 #_ #_ true false -> let ol = IfcMonitor.interpret_com hl body env Label.High in (match Some? ol with | true -> let hl' = Some?.v ol in let m0l = IfcMonitor.interpret_exp' hl v in let m1l = IfcMonitor.interpret_exp' hl' v in (match m0l > m1l with | true -> IfcMonitor.ifc_type c env pc (Rel.R hl' hr) | _ -> Prims.l_True) <: Prims.logical | _ -> Prims.l_True) <: Prims.logical | FStar.Pervasives.Native.Mktuple2 #_ #_ false true -> let or = IfcMonitor.interpret_com hr body env Label.High in (match Some? or with | true -> let hr' = Some?.v or in let m0r = IfcMonitor.interpret_exp' hr v in let m1r = IfcMonitor.interpret_exp' hr' v in (match m0r > m1r with | true -> IfcMonitor.ifc_type c env pc (Rel.R hl hr') | _ -> Prims.l_True) <: Prims.logical | _ -> Prims.l_True) <: Prims.logical | FStar.Pervasives.Native.Mktuple2 #_ #_ false false -> Prims.l_True) <: Prims.logical) <: Prims.logical) <: Prims.logical) <: Prims.logical)) (ensures IfcMonitor.ifc_type (IfcMonitor.While e body v) env pc h)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "IfcMonitor.exp", "IfcMonitor.com", "IfcMonitor.label_fun", "Label.label", "Rel.rel", "FStar.DM4F.Heap.IntStoreFixed.heap", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "Prims.bool", "Prims.op_disEquality", "Prims.op_AmpAmp", "FStar.Pervasives.Native.uu___is_Some", "Prims.op_GreaterThan", "Prims.cut", "Prims.b2t", "Prims.op_Equality", "FStar.Pervasives.Native.option", "IfcMonitor.interpret_com", "Prims.unit", "IfcMonitor.ifc_type", "Rel.R", "Prims.nat", "IfcMonitor.interpret_exp'", "FStar.Pervasives.Native.__proj__Some__item__v", "Label.join", "IfcMonitor.high_pc", "Label.High", "Label.uu___is_High", "IfcMonitor.dyn_ifc_exp", "FStar.Pervasives.Native.tuple2", "IfcMonitor.interpret_exp", "IfcMonitor.While" ]
[]
false
false
true
false
false
let dyn_ifc_while e body v env pc h =
let R hl hr = h in let c = While e body v in let rl = interpret_com hl c env pc in let rr = interpret_com hr c env pc in let v0l, ll = interpret_exp hl env e in let v0r, lr = interpret_exp hr env e in dyn_ifc_exp e h env; match v0l <> 0, v0r <> 0 with | true, true -> let ol = interpret_com hl body env (join ll pc) in let or = interpret_com hr body env (join lr pc) in if (Some? ol && Some? or) then (cut (ifc_type body env (join ll pc) h); let hl' = Some?.v ol in let hr' = Some?.v or in let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0l > m1l && m0r > m1r then (cut (ifc_type c env pc (R hl' hr')); cut (rl = interpret_com hl' c env pc); cut (rr = interpret_com hr' c env pc))) | true, false -> cut (High? ll); let ol = interpret_com hl body env High in if (Some? ol) then let hl' = Some?.v ol in high_pc body hl env High; let m0l = interpret_exp' hl v in let m1l = interpret_exp' hl' v in if m0l > m1l then (cut (ifc_type c env pc (R hl' hr)); cut (rl = interpret_com hl' c env pc)) | false, true -> cut (High? lr); let or = interpret_com hr body env High in if (Some? or) then let hr' = Some?.v or in high_pc body hr env High; let m0r = interpret_exp' hr v in let m1r = interpret_exp' hr' v in if m0r > m1r then (cut (ifc_type c env pc (R hl hr')); cut (rr = interpret_com hr' c env pc)) | false, false -> ()
false
Hacl.Spec.Chacha20.Equiv.fst
Hacl.Spec.Chacha20.Equiv.chacha20_map_blocks_multi_vec_equiv_pre_k
val chacha20_map_blocks_multi_vec_equiv_pre_k: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> hi_fv:nat // n == hi_fv == len / (w * blocksize) -> hi_f:size_nat{w * hi_fv <= hi_f} -> i:nat{i < hi_fv} -> b_v:lseq uint8 (w * blocksize) -> j:nat{j < w * blocksize} -> Lemma (let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in let f_v = chacha20_encrypt_block st_v0 in let f = Scalar.chacha20_encrypt_block st0 in VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
val chacha20_map_blocks_multi_vec_equiv_pre_k: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> hi_fv:nat // n == hi_fv == len / (w * blocksize) -> hi_f:size_nat{w * hi_fv <= hi_f} -> i:nat{i < hi_fv} -> b_v:lseq uint8 (w * blocksize) -> j:nat{j < w * blocksize} -> Lemma (let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in let f_v = chacha20_encrypt_block st_v0 in let f = Scalar.chacha20_encrypt_block st0 in VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j = encrypt_block_lemma_bs_i #w k n c0 i b_v j
{ "file_name": "code/chacha20/Hacl.Spec.Chacha20.Equiv.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 569, "start_col": 0, "start_line": 568 }
module Hacl.Spec.Chacha20.Equiv open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence open Lib.IntVector module Scalar = Spec.Chacha20 module Lemmas = Hacl.Spec.Chacha20.Lemmas module VecLemmas = Lib.Vec.Lemmas module SeqLemmas = Lib.Sequence.Lemmas open Hacl.Spec.Chacha20.Vec #reset-options "--z3rlimit 100 --max_fuel 0 --max_ifuel 0" let blocksize = size_block /// /// Scalar-related lemmas /// val chacha20_init_scalar_lemma: k:key -> n:nonce -> c0:counter -> Lemma (let uc = map secret chacha20_constants in let uk = uints_from_bytes_le #U32 #SEC #8 k in let uctr = create 1 (u32 c0) in let un = uints_from_bytes_le #U32 #SEC #3 n in Scalar.chacha20_init k n c0 == uc @| uk @| uctr @| un) let chacha20_init_scalar_lemma k n c0 = let uc = map secret chacha20_constants in let uk = uints_from_bytes_le #U32 #SEC #8 k in let uctr = create 1 (u32 c0) in let un = uints_from_bytes_le #U32 #SEC #3 n in let res = uc @| uk @| uctr @| un in assert (res == concat uc (concat uk (concat uctr un))); eq_intro res (concat (concat (concat uc uk) uctr) un); let len0 = 4 in let len1 = 8 in let len2 = 1 in let len3 = 3 in let res = concat (concat (concat uc uk) uctr) un in let st = create 16 (u32 0) in let st = update_sub st 0 4 (map secret chacha20_constants) in let st = update_sub st 4 8 (uints_from_bytes_le #U32 #SEC #8 k) in eq_intro (sub st 0 4) uc; let st = st.[12] <- u32 c0 in eq_intro (sub st 0 4) uc; eq_intro (sub st 4 8) uk; let res1 = update_sub st 13 3 (uints_from_bytes_le #U32 #SEC #3 n) in eq_intro (sub res1 0 4) uc; eq_intro (sub res1 4 8) uk; eq_intro (sub res1 12 1) uctr; eq_intro (sub res1 13 3) un; Seq.Properties.lemma_split (sub res 0 (len0 + len1)) len0; Seq.Properties.lemma_split (sub res1 0 (len0 + len1)) len0; Seq.Properties.lemma_split (sub res 0 (len0 + len1 + len2)) (len0 + len1); Seq.Properties.lemma_split (sub res1 0 (len0 + len1 + len2)) (len0 + len1); Seq.Properties.lemma_split res (len0 + len1 + len2); Seq.Properties.lemma_split res1 (len0 + len1 + len2) val add_counter_lemma_aux: w:lanes -> c0:counter -> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t} -> i:nat{i < w} -> b:uint32 -> Lemma (b +. u32 c0 +. u32 (w * c + i) == b +. u32 (c0 + i) +. u32 (w * c)) let add_counter_lemma_aux w c0 c i b = let lp = b +. u32 c0 +. u32 (w * c + i) in let rp = b +. u32 (c0 + i) +. u32 (w * c) in assert (v lp == ((v b + c0) % modulus U32 + (w * c + i)) % modulus U32); assert (v rp == ((v b + c0 + i) % modulus U32 + (w * c)) % modulus U32); Math.Lemmas.lemma_mod_plus_distr_l (v b + c0) (w * c + i) (modulus U32); Math.Lemmas.lemma_mod_plus_distr_l (v b + c0 + i) (w * c) (modulus U32) val chacha20_core_scalar_lemma: w:lanes -> st1:Scalar.state -> st2:Scalar.state -> c0:counter -> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t} -> i:nat{i < w} -> Lemma (requires (forall (j:nat). j < 16 /\ j <> 12 ==> st1.[j] == st2.[j] /\ st1.[12] == u32 c0 /\ st2.[12] == u32 (c0 + i))) (ensures Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) let chacha20_core_scalar_lemma w st1 st2 c0 c i = let k1 = Scalar.chacha20_add_counter st1 (w * c + i) in assert (k1.[12] == u32 c0 +. u32 (w * c + i)); let k2 = Scalar.chacha20_add_counter st2 (w * c) in assert (k2.[12] == u32 (c0 + i) +. u32 (w * c)); assert (v k1.[12] == v k2.[12]); eq_intro k1 k2; let k = Scalar.rounds k1 in let k1 = Scalar.sum_state k st1 in assert (k1.[12] == k.[12] +. u32 c0); let k2 = Scalar.sum_state k st2 in assert (k2.[12] == k.[12] +. u32 (c0 + i)); assert (forall (j:nat). j < 16 /\ j <> 12 ==> k1.[j] == k2.[j]); let k1 = Scalar.chacha20_add_counter k1 (w * c + i) in assert (k1.[12] == k.[12] +. u32 c0 +. u32 (w * c + i)); let k2 = Scalar.chacha20_add_counter k2 (w * c) in assert (k2.[12] == k.[12] +. u32 (c0 + i) +. u32 (w * c)); add_counter_lemma_aux w c0 c i k.[12]; eq_intro k1 k2 val kb_equiv_lemma: #w:lanes -> k:key -> n:nonce -> c0:counter -> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t} -> i:nat{i < w} -> Lemma (let st1 = Scalar.chacha20_init k n c0 in let st2 = Scalar.chacha20_init k n (c0 + i) in Scalar.chacha20_core (w * c + i) st1 `Seq.equal` Scalar.chacha20_core (w * c) st2) let kb_equiv_lemma #w k n c0 c i = let st1 = Scalar.chacha20_init k n c0 in let st2 = Scalar.chacha20_init k n (c0 + i) in chacha20_init_scalar_lemma k n c0; chacha20_init_scalar_lemma k n (c0 + i); chacha20_core_scalar_lemma w st1 st2 c0 c i /// /// Vectorised-related lemmas /// val line_lemma_i: #w:lanes -> a:idx -> b:idx -> d:idx -> s:rotval U32 -> m:state w -> i:nat{i < w} -> Lemma ((transpose_state (line #w a b d s m)).[i] `Seq.equal` Scalar.line a b d s (transpose_state #w m).[i]) let line_lemma_i #w a b d s m0 i = let m0_s = (transpose_state #w m0).[i] in let m1 = m0.[a] <- m0.[a] +| m0.[b] in let m1_s = m0_s.[a] <- m0_s.[a] +. m0_s.[b] in eq_intro (transpose_state m1).[i] m1_s; let m2 = m1.[d] <- (m1.[d] ^| m1.[a]) <<<| s in let m2_s = m1_s.[d] <- (m1_s.[d] ^. m1_s.[a]) <<<. s in eq_intro (transpose_state m2).[i] m2_s val quarter_round_lemma_i: #w:lanes -> a:idx -> b:idx -> c:idx -> d:idx -> m:state w -> i:nat{i < w} -> Lemma ((transpose_state (quarter_round #w a b c d m)).[i] `Seq.equal` Scalar.quarter_round a b c d (transpose_state m).[i]) let quarter_round_lemma_i #w a b c d m i = let lp0 = line a b d (size 16) m in let lp1 = line c d b (size 12) lp0 in let lp2 = line a b d (size 8) lp1 in let lp3 = line c d b (size 7) lp2 in assert (quarter_round #w a b c d m == lp3); line_lemma_i a b d (size 16) m i; line_lemma_i c d b (size 12) lp0 i; line_lemma_i a b d (size 8) lp1 i; line_lemma_i c d b (size 7) lp2 i; eq_intro (transpose_state (quarter_round #w a b c d m)).[i] (Scalar.quarter_round a b c d (transpose_state m).[i]) val column_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} -> Lemma ((transpose_state (column_round #w m)).[i] `Seq.equal` Scalar.column_round (transpose_state m).[i]) let column_round_lemma_i #w m i = let lp0 = quarter_round 0 4 8 12 m in let lp1 = quarter_round 1 5 9 13 lp0 in let lp2 = quarter_round 2 6 10 14 lp1 in let lp3 = quarter_round 3 7 11 15 lp2 in assert (column_round #w m == lp3); quarter_round_lemma_i 0 4 8 12 m i; quarter_round_lemma_i 1 5 9 13 lp0 i; quarter_round_lemma_i 2 6 10 14 lp1 i; quarter_round_lemma_i 3 7 11 15 lp2 i; eq_intro (transpose_state (column_round #w m)).[i] (Scalar.column_round (transpose_state m).[i]) val diagonal_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} -> Lemma ((transpose_state (diagonal_round #w m)).[i] `Seq.equal` Scalar.diagonal_round (transpose_state m).[i]) let diagonal_round_lemma_i #w m i = let lp0 = quarter_round 0 5 10 15 m in let lp1 = quarter_round 1 6 11 12 lp0 in let lp2 = quarter_round 2 7 8 13 lp1 in let lp3 = quarter_round 3 4 9 14 lp2 in assert (diagonal_round #w m == lp3); quarter_round_lemma_i 0 5 10 15 m i; quarter_round_lemma_i 1 6 11 12 lp0 i; quarter_round_lemma_i 2 7 8 13 lp1 i; quarter_round_lemma_i 3 4 9 14 lp2 i; eq_intro (transpose_state (diagonal_round #w m)).[i] (Scalar.diagonal_round (transpose_state m).[i]) val double_round_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} -> Lemma ((transpose_state (double_round #w m)).[i] `Seq.equal` Scalar.double_round (transpose_state m).[i]) let double_round_lemma_i #w m i = let m1 = column_round m in let m2 = diagonal_round m1 in column_round_lemma_i m i; diagonal_round_lemma_i m1 i noextract let scalar_rounds (m:Scalar.state) : Scalar.state = Scalar.double_round (Scalar.double_round ( Scalar.double_round (Scalar.double_round ( Scalar.double_round (Scalar.double_round ( Scalar.double_round (Scalar.double_round ( Scalar.double_round (Scalar.double_round m))))))))) val scalar_rounds_unroll_lemma: m:Scalar.state -> Lemma (scalar_rounds m `Seq.equal` Scalar.rounds m) let scalar_rounds_unroll_lemma m = let open Lib.LoopCombinators in eq_repeat0 Scalar.double_round m; unfold_repeat 10 Scalar.double_round m 0; unfold_repeat 10 Scalar.double_round m 1; unfold_repeat 10 Scalar.double_round m 2; unfold_repeat 10 Scalar.double_round m 3; unfold_repeat 10 Scalar.double_round m 4; unfold_repeat 10 Scalar.double_round m 5; unfold_repeat 10 Scalar.double_round m 6; unfold_repeat 10 Scalar.double_round m 7; unfold_repeat 10 Scalar.double_round m 8; unfold_repeat 10 Scalar.double_round m 9 val rounds_lemma_i: #w:lanes -> m:state w -> i:nat{i < w} -> Lemma ((transpose_state (rounds #w m)).[i] `Seq.equal` Scalar.rounds (transpose_state m).[i]) let rounds_lemma_i #w m i = let ms = (transpose_state m).[i] in let m1 = double_round m in let m2 = double_round m1 in let m3 = double_round m2 in let m4 = double_round m3 in let m5 = double_round m4 in let m6 = double_round m5 in let m7 = double_round m6 in let m8 = double_round m7 in let m9 = double_round m8 in let m10 = double_round m9 in assert (rounds m == m10); double_round_lemma_i #w m i; double_round_lemma_i #w m1 i; double_round_lemma_i #w m2 i; double_round_lemma_i #w m3 i; double_round_lemma_i #w m4 i; double_round_lemma_i #w m5 i; double_round_lemma_i #w m6 i; double_round_lemma_i #w m7 i; double_round_lemma_i #w m8 i; double_round_lemma_i #w m9 i; assert ((transpose_state m10).[i] == scalar_rounds ms); scalar_rounds_unroll_lemma ms val sum_state_lemma_i: #w:lanes -> st1:state w -> st2:state w -> i:nat{i < w} -> Lemma ((transpose_state (sum_state st1 st2)).[i] `Seq.equal` Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i]) let sum_state_lemma_i #w st1 st2 i = eq_intro (transpose_state (sum_state st1 st2)).[i] (Scalar.sum_state (transpose_state st1).[i] (transpose_state st2).[i]) val add_counter_lemma_i: #w:lanes -> st:state w -> c:counter{w * c <= max_size_t} -> i:nat{i < w} -> Lemma ((transpose_state (add_counter #w c st)).[i] `Seq.equal` Scalar.chacha20_add_counter (transpose_state st).[i] (w * c)) let add_counter_lemma_i #w st c i = Math.Lemmas.modulo_lemma (w * c) (pow2 32); assert (v (u32 w *! u32 c) == v (u32 (w * c))); eq_intro (transpose_state (add_counter #w c st)).[i] (Scalar.chacha20_add_counter (transpose_state st).[i] (w * c)) //kb_v_i val chacha20_core_lemma_i: #w:lanes -> c:counter{w * c <= max_size_t} -> st_v0:state w -> i:nat{i < w} -> Lemma ((transpose_state (chacha20_core c st_v0)).[i] `Seq.equal` Scalar.chacha20_core (w * c) (transpose_state st_v0).[i]) let chacha20_core_lemma_i #w c st_v0 i = let k0 = add_counter c st_v0 in add_counter_lemma_i st_v0 c i; let k1 = rounds k0 in rounds_lemma_i k0 i; let k2 = sum_state k1 st_v0 in sum_state_lemma_i k1 st_v0 i; let k3 = add_counter c k2 in add_counter_lemma_i k2 c i //init_v_i val chacha20_init_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> i:nat{i < w} -> Lemma ((transpose_state (chacha20_init #w k n c0)).[i] `Seq.equal` Scalar.chacha20_init k n (c0 + i)) let chacha20_init_lemma_i #w k n c0 i = let st1 = setup1 k n c0 in assert (st1 == Scalar.chacha20_init k n c0); assert (st1.[12] == u32 c0); let st = map (vec_load_i w) st1 in eq_intro (transpose_state st).[i] st1; assert ((transpose_state st).[i] == st1); let c = vec_counter U32 w in assert ((vec_v c).[i] == u32 i); let res = st.[12] <- st.[12] +| c in let res1 = st1.[12] <- st1.[12] +. u32 i in eq_intro (transpose_state res).[i] res1; assert ((transpose_state res).[i] == res1); assert (res1.[12] == u32 c0 +. u32 i); assert (v (u32 c0 +. u32 i) == v (u32 (c0 + i))); assert (res1.[12] == u32 (c0 + i)); let res2 = Scalar.chacha20_init k n (c0 + i) in chacha20_init_scalar_lemma k n c0; chacha20_init_scalar_lemma k n (c0 + i); eq_intro res1 res2 /// /// XOR-related lemmas /// val lemma_i_div_w4: w:pos -> i:nat{i < w * blocksize} -> Lemma (let bs = w * 4 in i / bs * bs + i % bs / 4 * 4 == i / 4 * 4) let lemma_i_div_w4 w i = let bs = w * 4 in calc (==) { i / bs * bs + i % bs / 4 * 4; (==) { Math.Lemmas.euclidean_division_definition (i % bs) 4 } i / bs * bs + i % bs - i % bs % 4; (==) { Math.Lemmas.euclidean_division_definition i bs } i - i % bs % 4; (==) { Math.Lemmas.modulo_modulo_lemma i 4 w } i - i % 4; (==) { Math.Lemmas.euclidean_division_definition i 4 } i / 4 * 4; } val lemma_i_div_blocksize: w:pos -> i:nat{i < w * blocksize} -> Lemma (i / blocksize * blocksize + i % blocksize / 4 * 4 == i / 4 * 4) let lemma_i_div_blocksize w i = calc (==) { i / blocksize * blocksize + i % blocksize / 4 * 4; (==) { Math.Lemmas.euclidean_division_definition (i % blocksize) 4 } i / blocksize * blocksize + i % blocksize - i % blocksize % 4; (==) { Math.Lemmas.modulo_modulo_lemma i 4 16 } i / blocksize * blocksize + i % blocksize - i % 4; (==) { Math.Lemmas.euclidean_division_definition i blocksize } i - i % 4; (==) { Math.Lemmas.euclidean_division_definition i 4 } i / 4 * 4; } val xor_block_vec_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma (let bs = w * 4 in let j = i / bs in let block = sub b (i / 4 * 4) 4 in Seq.index (xor_block k b) i == Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v k.[j]) (i % bs / 4)))) (i % 4)) let xor_block_vec_lemma_i #w k b i = let bs = w * 4 in let j = i / bs in let kb_j = vec_v k.[j] in let b_j = sub b (i / bs * bs) bs in let b_i = sub b_j (i % bs / 4 * 4) 4 in let block = sub b (i / 4 * 4) 4 in let ob = map2 (^.) (uints_from_bytes_le b_j) kb_j in calc (==) { Seq.index (xor_block k b) i; (==) { index_map_blocks_multi (w * 4) 16 16 b (xor_block_f #w k) i } Seq.index (uints_to_bytes_le ob) (i % bs); (==) { index_uints_to_bytes_le ob (i % bs) } Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % bs % 4); (==) { Math.Lemmas.modulo_modulo_lemma i 4 w } Seq.index (uint_to_bytes_le ob.[i % bs / 4]) (i % 4); (==) { (* def of xor *) } Seq.index (uint_to_bytes_le ((uints_from_bytes_le #U32 #SEC #w b_j).[i % bs / 4] ^. kb_j.[i % bs / 4])) (i % 4); (==) { index_uints_from_bytes_le #U32 #SEC #w b_j (i % bs / 4) } Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. kb_j.[i % bs / 4])) (i % 4); (==) { lemma_i_div_w4 w i; Seq.slice_slice b (j * bs) (j * bs + bs) (i % bs / 4 * 4) (i % bs / 4 * 4 + 4) } Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. kb_j.[i % bs / 4])) (i % 4); } val xor_block_scalar_lemma_i: k:Scalar.state -> b:Scalar.block -> i:nat{i < blocksize} -> Lemma ((Scalar.xor_block k b).[i] == (uint_to_bytes_le ((uint_from_bytes_le (sub b (i / 4 * 4) 4)) ^. k.[i / 4])).[i % 4]) let xor_block_scalar_lemma_i k b i = let ib = uints_from_bytes_le b in let ob = map2 (^.) ib k in let b_i = sub b (i / 4 * 4) 4 in calc (==) { Seq.index (uints_to_bytes_le ob) i; (==) { index_uints_to_bytes_le ob i } Seq.index (uint_to_bytes_le ob.[i / 4]) (i % 4); (==) { (* def of xor *) } Seq.index (uint_to_bytes_le (ib.[i / 4] ^. k.[i / 4])) (i % 4); (==) { index_uints_from_bytes_le #U32 #SEC #16 b (i / 4) } Seq.index (uint_to_bytes_le ((uint_from_bytes_le b_i) ^. k.[i / 4])) (i % 4); } val transpose_lemma_i: #w:lanes -> k:state w -> i:nat{i < w * blocksize} -> Lemma (Seq.index (vec_v (Seq.index (transpose k) (i / (w * 4)))) (i % (w * 4) / 4) == Seq.index (Seq.index (transpose_state k) (i / blocksize)) (i % blocksize / 4)) let transpose_lemma_i #w k i = let bs = w * 4 in let j = i / bs in let ki = (transpose_state k).[i / blocksize] in calc (==) { Seq.index (vec_v (Seq.index (transpose k) j)) (i % bs / 4); (==) { Math.Lemmas.modulo_division_lemma i 4 w } Seq.index (vec_v (Seq.index (transpose k) j)) (i / 4 % w); (==) { Math.Lemmas.division_multiplication_lemma i 4 w } Seq.index (vec_v (Seq.index (transpose k) (i / 4 / w))) (i / 4 % w); (==) { Lemmas.transpose_lemma_index #w k (i / 4); Math.Lemmas.division_multiplication_lemma i 4 16 } Seq.index ki (i / 4 % 16); (==) { Math.Lemmas.modulo_division_lemma i 4 16 } Seq.index ki (i % blocksize / 4); } val xor_block_lemma_i: #w:lanes -> k:state w -> b:blocks w -> i:nat{i < w * blocksize} -> Lemma (let k_i = (transpose_state k).[i / blocksize] in let b_i = sub b (i / blocksize * blocksize) blocksize in (xor_block (transpose k) b).[i] == (Scalar.xor_block k_i b_i).[i % blocksize]) let xor_block_lemma_i #w k b i = let bs = w * 4 in let j = i / bs in let ki = (transpose_state k).[i / blocksize] in let b_i = sub b (i / blocksize * blocksize) blocksize in let block = sub b (i / 4 * 4) 4 in calc (==) { Seq.index (xor_block (transpose k) b) i; (==) { xor_block_vec_lemma_i #w (transpose k) b i } Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index (vec_v (transpose k).[j]) (i % bs / 4)))) (i % 4); (==) { transpose_lemma_i #w k i } Seq.index (uint_to_bytes_le ((uint_from_bytes_le block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4); }; calc (==) { Seq.index (Scalar.xor_block ki b_i) (i % blocksize); (==) { xor_block_scalar_lemma_i ki b_i (i % blocksize); Math.Lemmas.modulo_modulo_lemma i 4 16 } Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC (sub b_i (i % blocksize / 4 * 4) 4)) ^. ki.[i % blocksize / 4])) (i % 4); (==) { lemma_i_div_blocksize w i; Seq.Properties.slice_slice b (i / blocksize * blocksize) (i / blocksize * blocksize + blocksize) (i % blocksize / 4 * 4) (i % blocksize / 4 * 4 + 4) } Seq.index (uint_to_bytes_le ((uint_from_bytes_le #U32 #SEC block) ^. (Seq.index ki (i % blocksize / 4)))) (i % 4); } /// /// map_blocks_vec /// val encrypt_block_scalar_lemma_i: #w:lanes -> k:key -> n:nonce -> c0:counter -> c:counter{w * c <= max_size_t /\ c0 + w <= max_size_t} -> b_i:Scalar.block -> i:nat{i < w} -> Lemma (let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in Scalar.chacha20_encrypt_block st0 (w * c + i) b_i `Seq.equal` Scalar.chacha20_encrypt_block (transpose_state st_v0).[i] (w * c) b_i) let encrypt_block_scalar_lemma_i #w k n c0 c b i = let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in chacha20_init_lemma_i #w k n c0 i; assert ((transpose_state st_v0).[i] == Scalar.chacha20_init k n (c0 + i)); kb_equiv_lemma #w k n c0 c i val encrypt_block_lemma_st0_i: #w:lanes -> st_v0:state w -> c:counter{w * c <= max_size_t} -> b_v:blocks w -> j:nat{j < w * blocksize} -> Lemma (Math.Lemmas.cancel_mul_div w blocksize; let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in div_mul_lt blocksize j w; (chacha20_encrypt_block st_v0 c b_v).[j] == (Scalar.chacha20_encrypt_block (transpose_state st_v0).[j / blocksize] (w * c) b).[j % blocksize]) let encrypt_block_lemma_st0_i #w st_v0 c b_v j = let k = chacha20_core c st_v0 in chacha20_core_lemma_i #w c st_v0 (j / blocksize); xor_block_lemma_i #w k b_v j val encrypt_block_lemma_bs_i: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> c:counter{w * c <= max_size_t} -> b_v:blocks w -> j:nat{j < w * blocksize} -> Lemma (let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in Math.Lemmas.cancel_mul_div w blocksize; let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in div_mul_lt blocksize j w; (chacha20_encrypt_block st_v0 c b_v).[j] == (Scalar.chacha20_encrypt_block st0 (w * c + j / blocksize) b).[j % blocksize]) let encrypt_block_lemma_bs_i #w k n c0 c b_v j = let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in Math.Lemmas.cancel_mul_div w blocksize; let b = SeqLemmas.get_block_s #uint8 #(w * blocksize) blocksize b_v j in encrypt_block_lemma_st0_i #w st_v0 c b_v j; div_mul_lt blocksize j w; encrypt_block_scalar_lemma_i #w k n c0 c b (j / blocksize) val chacha20_map_blocks_multi_vec_equiv_pre_k: #w:lanes -> k:key -> n:nonce -> c0:counter{c0 + w <= max_size_t} -> hi_fv:nat // n == hi_fv == len / (w * blocksize) -> hi_f:size_nat{w * hi_fv <= hi_f} -> i:nat{i < hi_fv} -> b_v:lseq uint8 (w * blocksize) -> j:nat{j < w * blocksize} -> Lemma (let st_v0 = chacha20_init #w k n c0 in let st0 = Scalar.chacha20_init k n c0 in let f_v = chacha20_encrypt_block st_v0 in let f = Scalar.chacha20_encrypt_block st0 in VecLemmas.map_blocks_multi_vec_equiv_pre_k w blocksize hi_fv hi_f f f_v i b_v j)
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "prims.fst.checked", "Lib.Vec.Lemmas.fsti.checked", "Lib.Sequence.Lemmas.fsti.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntVector.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Chacha20.Vec.fst.checked", "Hacl.Spec.Chacha20.Lemmas.fst.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Chacha20.Equiv.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Chacha20.Vec", "short_module": null }, { "abbrev": true, "full_module": "Lib.Sequence.Lemmas", "short_module": "SeqLemmas" }, { "abbrev": true, "full_module": "Lib.Vec.Lemmas", "short_module": "VecLemmas" }, { "abbrev": true, "full_module": "Hacl.Spec.Chacha20.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Spec.Chacha20", "short_module": "Scalar" }, { "abbrev": false, "full_module": "Lib.IntVector", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Chacha20", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: Hacl.Spec.Chacha20.Vec.key -> n: Hacl.Spec.Chacha20.Vec.nonce -> c0: Hacl.Spec.Chacha20.Vec.counter{c0 + w <= Lib.IntTypes.max_size_t} -> hi_fv: Prims.nat -> hi_f: Lib.IntTypes.size_nat{w * hi_fv <= hi_f} -> i: Prims.nat{i < hi_fv} -> b_v: Lib.Sequence.lseq Lib.IntTypes.uint8 (w * Hacl.Spec.Chacha20.Equiv.blocksize) -> j: Prims.nat{j < w * Hacl.Spec.Chacha20.Equiv.blocksize} -> FStar.Pervasives.Lemma (ensures (let st_v0 = Hacl.Spec.Chacha20.Vec.chacha20_init k n c0 in let st0 = Spec.Chacha20.chacha20_init k n c0 in let f_v = Hacl.Spec.Chacha20.Vec.chacha20_encrypt_block st_v0 in let f = Spec.Chacha20.chacha20_encrypt_block st0 in Lib.Vec.Lemmas.map_blocks_multi_vec_equiv_pre_k w Hacl.Spec.Chacha20.Equiv.blocksize hi_fv hi_f f f_v i b_v j))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Chacha20.Vec.lanes", "Hacl.Spec.Chacha20.Vec.key", "Hacl.Spec.Chacha20.Vec.nonce", "Hacl.Spec.Chacha20.Vec.counter", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "Lib.IntTypes.max_size_t", "Prims.nat", "Lib.IntTypes.size_nat", "FStar.Mul.op_Star", "Prims.op_LessThan", "Lib.Sequence.lseq", "Lib.IntTypes.uint8", "Hacl.Spec.Chacha20.Equiv.blocksize", "Hacl.Spec.Chacha20.Equiv.encrypt_block_lemma_bs_i", "Prims.unit" ]
[]
true
false
true
false
false
let chacha20_map_blocks_multi_vec_equiv_pre_k #w k n c0 hi_fv hi_f i b_v j =
encrypt_block_lemma_bs_i #w k n c0 i b_v j
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.dh_c64
val dh_c64:dh_st (DH.DH_Curve25519) vale_p
val dh_c64:dh_st (DH.DH_Curve25519) vale_p
let dh_c64 : dh_st (DH.DH_Curve25519) vale_p = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_64.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 97, "start_col": 0, "start_line": 91 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul inline_for_extraction noextract let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res inline_for_extraction noextract let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled) inline_for_extraction noextract let secret_to_public_c64 : secret_to_public_st (DH.DH_Curve25519) vale_p = fun o i -> Hacl.Curve25519_64.secret_to_public o i; 0ul
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.DH.dh_st Spec.Agile.DH.DH_Curve25519 Hacl.HPKE.Interface.DH.vale_p
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Spec.Agile.DH.DH_Curve25519", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.t", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "FStar.UInt32.__uint_to_t", "Prims.bool", "Lib.ByteBuffer.lbytes_eq", "Hacl.Curve25519_64.scalarmult", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "Lib.Buffer.create", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame" ]
[]
false
false
false
true
false
let dh_c64:dh_st (DH.DH_Curve25519) vale_p =
fun o k i -> push_frame (); let zeros = create 32ul (u8 0) in Hacl.Curve25519_64.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame (); res
false
Hacl.HPKE.Interface.DH.fst
Hacl.HPKE.Interface.DH.dh_c51
val dh_c51:dh_st (DH.DH_Curve25519) True
val dh_c51:dh_st (DH.DH_Curve25519) True
let dh_c51 : dh_st (DH.DH_Curve25519) True = fun o k i -> push_frame(); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame(); res
{ "file_name": "code/hpke/Hacl.HPKE.Interface.DH.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 81, "start_col": 0, "start_line": 75 }
module Hacl.HPKE.Interface.DH open FStar.HyperStack open FStar.HyperStack.All module HST = FStar.HyperStack.ST open Lib.Buffer open Lib.IntTypes open Lib.ByteBuffer module DH = Spec.Agile.DH module S = Spec.Agile.HPKE #reset-options "--z3rlimit 20 --fuel 0 --ifuel 1" unfold noextract let nsize_key (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 32ul unfold noextract let nsize_public (a:DH.algorithm) = match a with | DH.DH_Curve25519 -> 32ul | DH.DH_P256 -> 64ul inline_for_extraction noextract let dh_st (a:DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> k:lbuffer uint8 (nsize_key a) -> i:lbuffer uint8 (nsize_public a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 k /\ live h0 i /\ disjoint o i /\ disjoint o k) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ ( let output = DH.dh a (as_seq h0 k) (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output // DH succeeded | 1ul -> None? output | _ -> False)) inline_for_extraction noextract let secret_to_public_st (a: DH.algorithm) (p:Type0) = o:lbuffer uint8 (nsize_public a) -> i:lbuffer uint8 (nsize_key a) -> Stack UInt32.t (requires fun h0 -> p /\ live h0 o /\ live h0 i /\ disjoint o i) (ensures fun h0 result h1 -> modifies (loc o) h0 h1 /\ (let output = DH.secret_to_public a (as_seq h0 i) in match result with | 0ul -> Some? output /\ as_seq h1 o `Seq.equal` Some?.v output | 1ul -> None? output | _ -> False)) [@ Meta.Attribute.specialize] noextract assume val dh: #a:S.ciphersuite -> dh_st (S.kem_dh_of_cs a) True [@ Meta.Attribute.specialize] noextract assume val secret_to_public: #a:S.ciphersuite -> secret_to_public_st (S.kem_dh_of_cs a) True (** Instantiations for Curve25519 **) inline_for_extraction noextract let secret_to_public_c51 : secret_to_public_st (DH.DH_Curve25519) True = fun o i -> Hacl.Curve25519_51.secret_to_public o i; 0ul
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.DH.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.RawIntTypes.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.P256.DH.fsti.checked", "Hacl.Curve25519_64.fsti.checked", "Hacl.Curve25519_51.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Interface.DH.fst" }
[ { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE.Interface", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.HPKE.Interface.DH.dh_st Spec.Agile.DH.DH_Curve25519 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "Hacl.HPKE.Interface.DH.nsize_public", "Spec.Agile.DH.DH_Curve25519", "Hacl.HPKE.Interface.DH.nsize_key", "FStar.UInt32.t", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "FStar.UInt32.__uint_to_t", "Prims.bool", "Lib.ByteBuffer.lbytes_eq", "Hacl.Curve25519_51.scalarmult", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "Lib.Buffer.create", "Lib.IntTypes.u8", "FStar.HyperStack.ST.push_frame" ]
[]
false
false
false
true
false
let dh_c51:dh_st (DH.DH_Curve25519) True =
fun o k i -> push_frame (); let zeros = create 32ul (u8 0) in Hacl.Curve25519_51.scalarmult o k i; let res = if lbytes_eq o zeros then 1ul else 0ul in pop_frame (); res
false