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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.is_false | val is_false : term -> Tac bool | val is_false : term -> Tac bool | let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 7,
"end_line": 191,
"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 FStar.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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 | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.bool | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Tactics.NamedView.term",
"Prims.bool",
"FStar.Reflection.V2.Formula.formula",
"FStar.Stubs.Reflection.V2.Data.argv",
"FStar.Tactics.NamedView.binder",
"FStar.Reflection.V2.Formula.term_as_formula'",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.inspect"
] | [] | false | true | false | false | false | let is_false t =
| match term_as_formula' t with
| False_ -> true
| _ ->
match inspect t with
| Tv_App l r ->
(match inspect l with
| Tv_Abs b t ->
(match term_as_formula' t with
| False_ -> true
| _ -> false)
| _ -> false)
| _ -> false | false |
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.simplify | val simplify: Prims.unit -> Tac unit | val simplify: Prims.unit -> Tac unit | let simplify () : Tac unit =
apply_lemma (`equiv);
simplify_point () | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 309,
"start_col": 0,
"start_line": 307
} | (*
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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool
let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val inhabit : unit -> Tac unit
let inhabit () =
let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid then exact (`42)
else if qn = bool_lid then exact (`true)
else if qn = unit_lid then exact (`())
else fail ""
| _ -> fail ""
val simplify_point : unit -> Tac unit
val recurse : unit -> Tac unit
let rec simplify_point () =
recurse ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And p q ->
if is_true p then apply_lemma (`lem_true_and_p)
else if is_true q then apply_lemma (`lem_p_and_true)
else if is_false p then apply_lemma (`lem_false_and_p)
else if is_false q then apply_lemma (`lem_p_and_false)
else tiff ()
| Or p q ->
if is_true p then apply_lemma (`lem_true_or_p)
else if is_true q then apply_lemma (`lem_p_or_true)
else if is_false p then apply_lemma (`lem_false_or_p)
else if is_false q then apply_lemma (`lem_p_or_false)
else tiff ()
| Implies p q ->
if is_true p then apply_lemma (`lem_true_imp_p)
else if is_true q then apply_lemma (`lem_p_imp_true)
else if is_false p then apply_lemma (`lem_false_imp_p)
else tiff ()
| Forall _b _sort p ->
if is_true p then apply_lemma (`lem_fa_true)
else if is_false p then or_else (fun () -> apply_lemma (`lem_fa_false); inhabit ()) tiff
else tiff ()
| Exists _b _sort p ->
if is_false p then apply_lemma (`lem_ex_false)
else if is_true p then or_else (fun () -> apply_lemma (`lem_ex_true); inhabit ()) tiff
else tiff ()
| Not p ->
if is_true p then apply_lemma (`lem_neg_true)
else if is_false p then apply_lemma (`lem_neg_false)
else tiff ()
| Iff p q ->
// After applying the lemma, we might still have more simpl to do,
// so add an intermediate step.
step ();
if is_true p then apply_lemma (`lem_true_iff_p)
else if is_true q then apply_lemma (`lem_p_iff_true)
else if is_false p then apply_lemma (`lem_false_iff_p)
else if is_false q then apply_lemma (`lem_p_iff_false)
else tiff ();
simplify_point ()
| _ -> tiff ()
end
| _ -> fail "simplify_point: failed precondition: goal should be `g <==> ?u`"
and recurse () : Tac unit =
step ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And _ _ ->
seq (fun () -> apply_lemma (`and_cong)) simplify_point
| Or _ _ ->
seq (fun () -> apply_lemma (`or_cong)) simplify_point
| Implies _ _ ->
seq (fun () -> apply_lemma (`imp_cong)) simplify_point
| Forall _ _ _ ->
apply_lemma (`fa_cong);
let _ = intro () in
simplify_point ()
| Exists _ _ _ ->
apply_lemma (`ex_cong);
let _ = intro () in
simplify_point ()
| Not _ ->
apply_lemma (`neg_cong);
simplify_point ()
| Iff _ _ ->
seq (fun () -> apply_lemma (`iff_cong)) simplify_point
| _ -> tiff ()
end
| _ -> fail "recurse: failed precondition: goal should be `g <==> ?u`"
val equiv : #p:Type -> #q:Type -> squash (p <==> q) -> squash q -> Lemma p
let equiv #p #q _ _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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 | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Tactics.Simplifier.simplify_point",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | false | true | false | false | false | let simplify () : Tac unit =
| apply_lemma (`equiv);
simplify_point () | false |
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.fa_cong | val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x)) | val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x)) | let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
) | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 132,
"start_col": 0,
"start_line": 121
} | (*
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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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: (x: a -> Prims.squash (p x <==> q x))
-> FStar.Pervasives.Lemma (ensures (forall (x: a). p x) <==> (forall (x: a). q x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.squash",
"Prims.l_iff",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_Forall",
"Prims.unit",
"FStar.Tactics.V2.Derived.iseq",
"Prims.Cons",
"Prims.Nil",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.pose",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Stubs.Reflection.Types.term",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"FStar.Tactics.V2.Derived.nth_var",
"Prims.op_Minus",
"Prims.list",
"FStar.Tactics.V2.Logic.l_intros",
"FStar.Tactics.V2.Logic.split"
] | [] | false | false | true | false | false | let fa_cong #a #p #q f =
| FStar.Tactics.Effect.assert_by_tactic ((forall (x: a). p x) <==> (forall (x: a). q x))
(fun _ ->
();
(split ();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (- 1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1])) | false |
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.inhabit | val inhabit : unit -> Tac unit | val inhabit : unit -> Tac unit | let inhabit () =
let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid then exact (`42)
else if qn = bool_lid then exact (`true)
else if qn = unit_lid then exact (`())
else fail ""
| _ -> fail "" | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 203,
"start_col": 0,
"start_line": 194
} | (*
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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool
let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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 | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.unit",
"FStar.Stubs.Reflection.Types.fv",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"FStar.Reflection.Const.int_lid",
"FStar.Tactics.V2.Derived.exact",
"Prims.bool",
"FStar.Reflection.Const.bool_lid",
"FStar.Reflection.Const.unit_lid",
"FStar.Tactics.V2.Derived.fail",
"FStar.Stubs.Reflection.Types.name",
"FStar.Stubs.Reflection.V2.Builtins.inspect_fv",
"FStar.Tactics.NamedView.named_term_view",
"FStar.Tactics.NamedView.inspect",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V2.Derived.cur_goal"
] | [] | false | true | false | false | false | let inhabit () =
| let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid
then exact (`42)
else if qn = bool_lid then exact (`true) else if qn = unit_lid then exact (`()) else fail ""
| _ -> fail "" | false |
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.ex_cong | val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x)) | val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x)) | let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
)) | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 4,
"end_line": 148,
"start_col": 0,
"start_line": 137
} | (*
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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) -> | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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: (x: a -> Prims.squash (p x <==> q x))
-> FStar.Pervasives.Lemma (ensures (exists (x: a). p x) <==> (exists (x: a). q x)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.squash",
"Prims.l_iff",
"FStar.Tactics.Effect.assert_by_tactic",
"Prims.l_Exists",
"Prims.unit",
"FStar.Tactics.Effect.assume_safe",
"FStar.Tactics.V2.Derived.iseq",
"Prims.Cons",
"Prims.Nil",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Derived.pose",
"FStar.Reflection.V2.Derived.mk_e_app",
"FStar.Stubs.Reflection.Types.term",
"FStar.Tactics.V2.SyntaxCoercions.binding_to_term",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Logic.elim_exists",
"Prims.list",
"FStar.Tactics.V2.Logic.l_intros",
"FStar.Tactics.V2.Logic.split"
] | [] | false | false | true | false | false | let ex_cong #a #p #q f =
| FStar.Tactics.Effect.assert_by_tactic ((exists (x: a). p x) <==> (exists (x: a). q x))
(fun _ ->
();
(assume_safe (fun () ->
split ();
let do1 () : Tac unit =
let [ex] = l_intros () in
let b, pf = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]))) | false |
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.recurse | val recurse : unit -> Tac unit | val recurse : unit -> Tac unit | let rec simplify_point () =
recurse ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And p q ->
if is_true p then apply_lemma (`lem_true_and_p)
else if is_true q then apply_lemma (`lem_p_and_true)
else if is_false p then apply_lemma (`lem_false_and_p)
else if is_false q then apply_lemma (`lem_p_and_false)
else tiff ()
| Or p q ->
if is_true p then apply_lemma (`lem_true_or_p)
else if is_true q then apply_lemma (`lem_p_or_true)
else if is_false p then apply_lemma (`lem_false_or_p)
else if is_false q then apply_lemma (`lem_p_or_false)
else tiff ()
| Implies p q ->
if is_true p then apply_lemma (`lem_true_imp_p)
else if is_true q then apply_lemma (`lem_p_imp_true)
else if is_false p then apply_lemma (`lem_false_imp_p)
else tiff ()
| Forall _b _sort p ->
if is_true p then apply_lemma (`lem_fa_true)
else if is_false p then or_else (fun () -> apply_lemma (`lem_fa_false); inhabit ()) tiff
else tiff ()
| Exists _b _sort p ->
if is_false p then apply_lemma (`lem_ex_false)
else if is_true p then or_else (fun () -> apply_lemma (`lem_ex_true); inhabit ()) tiff
else tiff ()
| Not p ->
if is_true p then apply_lemma (`lem_neg_true)
else if is_false p then apply_lemma (`lem_neg_false)
else tiff ()
| Iff p q ->
// After applying the lemma, we might still have more simpl to do,
// so add an intermediate step.
step ();
if is_true p then apply_lemma (`lem_true_iff_p)
else if is_true q then apply_lemma (`lem_p_iff_true)
else if is_false p then apply_lemma (`lem_false_iff_p)
else if is_false q then apply_lemma (`lem_p_iff_false)
else tiff ();
simplify_point ()
| _ -> tiff ()
end
| _ -> fail "simplify_point: failed precondition: goal should be `g <==> ?u`"
and recurse () : Tac unit =
step ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And _ _ ->
seq (fun () -> apply_lemma (`and_cong)) simplify_point
| Or _ _ ->
seq (fun () -> apply_lemma (`or_cong)) simplify_point
| Implies _ _ ->
seq (fun () -> apply_lemma (`imp_cong)) simplify_point
| Forall _ _ _ ->
apply_lemma (`fa_cong);
let _ = intro () in
simplify_point ()
| Exists _ _ _ ->
apply_lemma (`ex_cong);
let _ = intro () in
simplify_point ()
| Not _ ->
apply_lemma (`neg_cong);
simplify_point ()
| Iff _ _ ->
seq (fun () -> apply_lemma (`iff_cong)) simplify_point
| _ -> tiff ()
end
| _ -> fail "recurse: failed precondition: goal should be `g <==> ?u`" | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 302,
"start_col": 0,
"start_line": 208
} | (*
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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool
let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val inhabit : unit -> Tac unit
let inhabit () =
let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid then exact (`42)
else if qn = bool_lid then exact (`true)
else if qn = unit_lid then exact (`())
else fail ""
| _ -> fail ""
val simplify_point : unit -> Tac unit
val recurse : unit -> Tac unit | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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 | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [
"simplify_point",
"recurse"
] | [
"Prims.unit",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.seq",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Tactics.Simplifier.simplify_point",
"FStar.Tactics.NamedView.bv",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Stubs.Reflection.V2.Data.binding",
"FStar.Stubs.Tactics.V2.Builtins.intro",
"FStar.Reflection.V2.Formula.formula",
"FStar.Tactics.Simplifier.tiff",
"FStar.Reflection.V2.Formula.term_as_formula'",
"FStar.Tactics.V2.Derived.fail",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Tactics.V2.Derived.cur_goal",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"Prims.Nil",
"FStar.Pervasives.norm_step",
"FStar.Tactics.Simplifier.step"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec recurse () : Tac unit =
| step ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
(match term_as_formula' l with
| And _ _ -> seq (fun () -> apply_lemma (`and_cong)) simplify_point
| Or _ _ -> seq (fun () -> apply_lemma (`or_cong)) simplify_point
| Implies _ _ -> seq (fun () -> apply_lemma (`imp_cong)) simplify_point
| Forall _ _ _ ->
apply_lemma (`fa_cong);
let _ = intro () in
simplify_point ()
| Exists _ _ _ ->
apply_lemma (`ex_cong);
let _ = intro () in
simplify_point ()
| Not _ ->
apply_lemma (`neg_cong);
simplify_point ()
| Iff _ _ -> seq (fun () -> apply_lemma (`iff_cong)) simplify_point
| _ -> tiff ())
| _ -> fail "recurse: failed precondition: goal should be `g <==> ?u`" | false |
FStar.Tactics.Simplifier.fst | FStar.Tactics.Simplifier.simplify_point | val simplify_point : unit -> Tac unit | val simplify_point : unit -> Tac unit | let rec simplify_point () =
recurse ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And p q ->
if is_true p then apply_lemma (`lem_true_and_p)
else if is_true q then apply_lemma (`lem_p_and_true)
else if is_false p then apply_lemma (`lem_false_and_p)
else if is_false q then apply_lemma (`lem_p_and_false)
else tiff ()
| Or p q ->
if is_true p then apply_lemma (`lem_true_or_p)
else if is_true q then apply_lemma (`lem_p_or_true)
else if is_false p then apply_lemma (`lem_false_or_p)
else if is_false q then apply_lemma (`lem_p_or_false)
else tiff ()
| Implies p q ->
if is_true p then apply_lemma (`lem_true_imp_p)
else if is_true q then apply_lemma (`lem_p_imp_true)
else if is_false p then apply_lemma (`lem_false_imp_p)
else tiff ()
| Forall _b _sort p ->
if is_true p then apply_lemma (`lem_fa_true)
else if is_false p then or_else (fun () -> apply_lemma (`lem_fa_false); inhabit ()) tiff
else tiff ()
| Exists _b _sort p ->
if is_false p then apply_lemma (`lem_ex_false)
else if is_true p then or_else (fun () -> apply_lemma (`lem_ex_true); inhabit ()) tiff
else tiff ()
| Not p ->
if is_true p then apply_lemma (`lem_neg_true)
else if is_false p then apply_lemma (`lem_neg_false)
else tiff ()
| Iff p q ->
// After applying the lemma, we might still have more simpl to do,
// so add an intermediate step.
step ();
if is_true p then apply_lemma (`lem_true_iff_p)
else if is_true q then apply_lemma (`lem_p_iff_true)
else if is_false p then apply_lemma (`lem_false_iff_p)
else if is_false q then apply_lemma (`lem_p_iff_false)
else tiff ();
simplify_point ()
| _ -> tiff ()
end
| _ -> fail "simplify_point: failed precondition: goal should be `g <==> ?u`"
and recurse () : Tac unit =
step ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
begin match term_as_formula' l with
| And _ _ ->
seq (fun () -> apply_lemma (`and_cong)) simplify_point
| Or _ _ ->
seq (fun () -> apply_lemma (`or_cong)) simplify_point
| Implies _ _ ->
seq (fun () -> apply_lemma (`imp_cong)) simplify_point
| Forall _ _ _ ->
apply_lemma (`fa_cong);
let _ = intro () in
simplify_point ()
| Exists _ _ _ ->
apply_lemma (`ex_cong);
let _ = intro () in
simplify_point ()
| Not _ ->
apply_lemma (`neg_cong);
simplify_point ()
| Iff _ _ ->
seq (fun () -> apply_lemma (`iff_cong)) simplify_point
| _ -> tiff ()
end
| _ -> fail "recurse: failed precondition: goal should be `g <==> ?u`" | {
"file_name": "ulib/FStar.Tactics.Simplifier.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 302,
"start_col": 0,
"start_line": 208
} | (*
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.Tactics.Simplifier
open FStar.Tactics.V2
open FStar.Reflection.V2.Formula
open FStar.Reflection.Const
(* A correct-by-construction logical simplifier
*
* No calling `norm [simpl]`, that's cheating!
*)
val lem_iff_refl : #a:Type -> Lemma (a <==> a)
let lem_iff_refl #a = ()
val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c)
-> Lemma (a <==> c)
let lem_iff_trans #a #b #c _ _ = ()
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p)
let lem_true_and_p #p = ()
val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p)
let lem_p_and_true #p = ()
val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False)
let lem_false_and_p #p = ()
val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False)
let lem_p_and_false #p = ()
val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True)
let lem_true_or_p #p = ()
val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True)
let lem_p_or_true #p = ()
val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p)
let lem_false_or_p #p = ()
val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p)
let lem_p_or_false #p = ()
val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p)
let lem_true_imp_p #p = ()
val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True)
let lem_p_imp_true #p = ()
val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True)
let lem_false_imp_p #p = ()
val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True)
let lem_fa_true #a = ()
val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False)
let lem_fa_false #a x = ()
val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False)
let lem_ex_false #a = ()
val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True)
let lem_ex_true #a x = ()
val lem_neg_false : unit -> Lemma (~False <==> True)
let lem_neg_false () = ()
val lem_neg_true : unit -> Lemma (~True <==> False)
let lem_neg_true () = ()
val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p)
let lem_true_iff_p #p = ()
val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p)
let lem_false_iff_p #p = ()
val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p)
let lem_p_iff_true #p = ()
val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p)
let lem_p_iff_false #p = ()
val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p /\ q) <==> (p' /\ q'))
let and_cong #p #q #p' #q' _ _ = ()
val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p \/ q) <==> (p' \/ q'))
let or_cong #p #q #p' #q' _ _ = ()
val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') ->
squash (q <==> q') ->
Lemma ((p ==> q) <==> (p' ==> q'))
let imp_cong #p #q #p' #q' _ _ = ()
val fa_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((forall (x:a). p x) <==> (forall (x:a). q x))
let fa_cong #a #p #q f =
assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by (
split();
let do1 () : Tac unit =
let _ = l_intros () in
let t = quote f in
let x = nth_var (-1) in
let bb = pose (mk_e_app t [binding_to_term x]) in
()
in
iseq [do1; do1]
)
val ex_cong (#a : Type) (#p #q : a -> Type) :
(x:a -> squash (p x <==> q x)) ->
Lemma ((exists (x:a). p x) <==> (exists (x:a). q x))
let ex_cong #a #p #q f =
assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () ->
split();
let do1 () : Tac unit =
let [ex] = l_intros () in
let (b, pf) = elim_exists (binding_to_term ex) in
let t = quote f in
let bb = pose (mk_e_app t [binding_to_term b]) in
()
in
iseq [do1; do1]
))
val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q)
let neg_cong #p #q _ = ()
val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q'))
let iff_cong #p #p' #q #q' _ _ = ()
// Absolutely hideous, do something about normalization
val is_true : term -> Tac bool
let is_true t =
begin match term_as_formula' t with
| True_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| True_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val is_false : term -> Tac bool
let is_false t =
begin match term_as_formula' t with
| False_ -> true
| _ -> begin match inspect t with
| Tv_App l r ->
begin match inspect l with
| Tv_Abs b t ->
begin match term_as_formula' t with
| False_ -> true
| _ -> false
end
| _ -> false
end
| _ -> false
end
end
val inhabit : unit -> Tac unit
let inhabit () =
let t = cur_goal () in
match inspect t with
| Tv_FVar fv ->
let qn = inspect_fv fv in
if qn = int_lid then exact (`42)
else if qn = bool_lid then exact (`true)
else if qn = unit_lid then exact (`())
else fail ""
| _ -> fail ""
val simplify_point : unit -> Tac unit
val recurse : unit -> Tac unit | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.Const.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Simplifier.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Reflection.Const",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"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 | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | FStar.Tactics.Effect.Tac | [] | [
"simplify_point",
"recurse"
] | [
"Prims.unit",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.apply_lemma",
"Prims.bool",
"FStar.Tactics.Simplifier.tiff",
"FStar.Tactics.Simplifier.is_false",
"FStar.Tactics.Simplifier.is_true",
"FStar.Tactics.NamedView.bv",
"FStar.Stubs.Reflection.Types.typ",
"FStar.Tactics.V2.Derived.or_else",
"FStar.Tactics.Simplifier.inhabit",
"FStar.Tactics.Simplifier.simplify_point",
"FStar.Tactics.Simplifier.step",
"FStar.Reflection.V2.Formula.formula",
"FStar.Reflection.V2.Formula.term_as_formula'",
"FStar.Tactics.V2.Derived.fail",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Tactics.V2.Derived.cur_goal",
"FStar.Stubs.Tactics.V2.Builtins.norm",
"Prims.Nil",
"FStar.Pervasives.norm_step",
"FStar.Tactics.Simplifier.recurse"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec simplify_point () =
| recurse ();
norm [];
let g = cur_goal () in
let f = term_as_formula g in
match f with
| Iff l r ->
(match term_as_formula' l with
| And p q ->
if is_true p
then apply_lemma (`lem_true_and_p)
else
if is_true q
then apply_lemma (`lem_p_and_true)
else
if is_false p
then apply_lemma (`lem_false_and_p)
else if is_false q then apply_lemma (`lem_p_and_false) else tiff ()
| Or p q ->
if is_true p
then apply_lemma (`lem_true_or_p)
else
if is_true q
then apply_lemma (`lem_p_or_true)
else
if is_false p
then apply_lemma (`lem_false_or_p)
else if is_false q then apply_lemma (`lem_p_or_false) else tiff ()
| Implies p q ->
if is_true p
then apply_lemma (`lem_true_imp_p)
else
if is_true q
then apply_lemma (`lem_p_imp_true)
else if is_false p then apply_lemma (`lem_false_imp_p) else tiff ()
| Forall _b _sort p ->
if is_true p
then apply_lemma (`lem_fa_true)
else
if is_false p
then
or_else (fun () ->
apply_lemma (`lem_fa_false);
inhabit ())
tiff
else tiff ()
| Exists _b _sort p ->
if is_false p
then apply_lemma (`lem_ex_false)
else
if is_true p
then
or_else (fun () ->
apply_lemma (`lem_ex_true);
inhabit ())
tiff
else tiff ()
| Not p ->
if is_true p
then apply_lemma (`lem_neg_true)
else if is_false p then apply_lemma (`lem_neg_false) else tiff ()
| Iff p q ->
step ();
if is_true p
then apply_lemma (`lem_true_iff_p)
else
if is_true q
then apply_lemma (`lem_p_iff_true)
else
if is_false p
then apply_lemma (`lem_false_iff_p)
else if is_false q then apply_lemma (`lem_p_iff_false) else tiff ();
simplify_point ()
| _ -> tiff ())
| _ -> fail "simplify_point: failed precondition: goal should be `g <==> ?u`" | false |
Steel.Channel.Simplex.fst | Steel.Channel.Simplex.intro_trace_until_init | val intro_trace_until_init (#p: _) (c: chan_t p) (v: init_chan_val p)
: SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) | val intro_trace_until_init (#p: _) (c: chan_t p) (v: init_chan_val p)
: SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) | let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p)
: SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p))
(fun _ -> trace_until c.trace v)
= intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg);
//TODO: Not sure why I need this rewrite
rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star`
pure (until (initial_trace p) == step v.chan_prot v.chan_msg))
(MRef.pts_to c.trace full_perm (initial_trace p) `star`
pure (until (initial_trace p) == step v.chan_prot v.chan_msg))
(fun _ -> ());
intro_exists (initial_trace p) (trace_until_prop c.trace v) | {
"file_name": "lib/steel/Steel.Channel.Simplex.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 63,
"end_line": 195,
"start_col": 0,
"start_line": 185
} | (*
Copyright 2020 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 Steel.Channel.Simplex
module P = Steel.Channel.Protocol
open Steel.SpinLock
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
open Steel.HigherReference
open Steel.FractionalPermission
module MRef = Steel.MonotonicHigherReference
module H = Steel.HigherReference
let sprot = p:prot { more p }
noeq
type chan_val = {
chan_prot : sprot;
chan_msg : msg_t chan_prot;
chan_ctr : nat
}
let mref a p = MRef.ref a p
let trace_ref (p:prot) = mref (partial_trace_of p) extended_to
noeq
type chan_t (p:prot) = {
send: ref chan_val;
recv: ref chan_val;
trace: trace_ref p;
}
let half : perm = half_perm full_perm
let step (s:sprot) (x:msg_t s) = step s x
let chan_inv_step_p (vrecv vsend:chan_val) : prop =
(vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\
vsend.chan_ctr == vrecv.chan_ctr + 1)
let chan_inv_step (vrecv vsend:chan_val) : vprop =
pure (chan_inv_step_p vrecv vsend)
let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop =
if vsend.chan_ctr = vrecv.chan_ctr
then pure (vsend == vrecv)
else chan_inv_step vrecv vsend
let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop =
MRef.pts_to r full_perm tr `star`
pure (until tr == step vr.chan_prot vr.chan_msg)
let trace_until #p (r:trace_ref p) (vr:chan_val) =
h_exists (trace_until_prop r vr)
let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) =
h_exists (fun (vrecv:chan_val) ->
pts_to c.recv half vrecv `star`
trace_until c.trace vrecv `star`
chan_inv_cond vsend vrecv)
let chan_inv #p (c:chan_t p) : vprop =
h_exists (fun (vsend:chan_val) ->
pts_to c.send half vsend `star` chan_inv_recv c vsend)
let intro_chan_inv_cond_eqT (vs vr:chan_val)
: Steel unit emp
(fun _ -> chan_inv_cond vs vr)
(requires fun _ -> vs == vr)
(ensures fun _ _ _ -> True)
= intro_pure (vs == vs);
rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
let intro_chan_inv_cond_stepT (vs vr:chan_val)
: SteelT unit (chan_inv_step vr vs)
(fun _ -> chan_inv_cond vs vr)
= Steel.Utils.extract_pure (chan_inv_step_p vr vs);
rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
let intro_chan_inv_auxT #p (#vs : chan_val)
(#vr : chan_val)
(c:chan_t p)
: SteelT unit (pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr `star`
chan_inv_cond vs vr)
(fun _ -> chan_inv c)
= intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr);
intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs)
let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val)
: SteelT unit (pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr `star`
chan_inv_step vr vs)
(fun _ -> chan_inv c)
= intro_chan_inv_cond_stepT vs vr;
intro_chan_inv_auxT c
let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val)
: Steel unit (pts_to c.send half vs `star`
pts_to c.recv half vr `star`
trace_until c.trace vr)
(fun _ -> chan_inv c)
(requires fun _ -> vs == vr)
(ensures fun _ _ _ -> True)
= intro_chan_inv_cond_eqT vs vr;
intro_chan_inv_auxT c
noeq
type chan p = {
chan_chan : chan_t p;
chan_lock : lock (chan_inv chan_chan)
}
let in_state_prop (p:prot) (vsend:chan_val) : prop =
p == step vsend.chan_prot vsend.chan_msg
irreducible
let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 })
: Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs})
= {
chan_prot = (step vs0.chan_prot vs0.chan_msg);
chan_msg = x;
chan_ctr = vs0.chan_ctr + 1
}
[@@__reduce__]
let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend)
let in_state (r:ref chan_val) (p:prot) =
h_exists (fun (vsend:chan_val) ->
pts_to r half vsend `star` in_state_slprop p vsend)
let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p
let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p
let intro_chan_inv #p (c:chan_t p) (v:chan_val)
: SteelT unit (pts_to c.send half v `star`
pts_to c.recv half v `star`
trace_until c.trace v)
(fun _ -> chan_inv c)
= intro_chan_inv_eqT c v v
let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 })
let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p)
: SteelT unit (pts_to r half v) (fun _ -> in_state r p)
= intro_pure (in_state_prop p v);
intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v)
let msg t p = Msg Send unit (fun _ -> p)
let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p}
let initial_trace (p:prot) : (q:partial_trace_of p {until q == p})
= { to = p; tr=Waiting p}
let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val)
: Steel unit (MRef.pts_to r full_perm tr)
(fun _ -> trace_until r v)
(requires fun _ -> until tr == step v.chan_prot v.chan_msg)
(ensures fun _ _ _ -> True)
= intro_pure (until tr == step v.chan_prot v.chan_msg);
intro_exists tr
(fun (tr:partial_trace_of q) ->
MRef.pts_to r full_perm tr `star`
pure (until tr == (step v.chan_prot v.chan_msg)));
()
let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) | {
"checked_file": "/",
"dependencies": [
"Steel.Utils.fst.checked",
"Steel.SpinLock.fsti.checked",
"Steel.MonotonicHigherReference.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.HigherReference.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"Steel.Channel.Protocol.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Channel.Simplex.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.HigherReference",
"short_module": "H"
},
{
"abbrev": true,
"full_module": "Steel.MonotonicHigherReference",
"short_module": "MRef"
},
{
"abbrev": false,
"full_module": "Steel.FractionalPermission",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.HigherReference",
"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": "Steel.SpinLock",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Channel.Protocol",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel.Protocol",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Channel",
"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: Steel.Channel.Simplex.chan_t p -> v: Steel.Channel.Simplex.init_chan_val p
-> Steel.Effect.SteelT Prims.unit | Steel.Effect.SteelT | [] | [] | [
"Steel.Channel.Simplex.prot",
"Steel.Channel.Simplex.chan_t",
"Steel.Channel.Simplex.init_chan_val",
"Steel.Effect.Atomic.intro_exists",
"Steel.Channel.Protocol.partial_trace_of",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Channel.Simplex.initial_trace",
"Steel.Channel.Simplex.trace_until_prop",
"Steel.Channel.Simplex.__proj__Mkchan_t__item__trace",
"Prims.unit",
"Steel.Effect.Atomic.rewrite_slprop",
"Steel.Effect.Common.star",
"Steel.MonotonicHigherReference.pts_to",
"Steel.Channel.Protocol.extended_to",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.pure",
"Prims.eq2",
"Steel.Channel.Protocol.protocol",
"Steel.Channel.Protocol.until",
"Steel.Channel.Simplex.step",
"Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot",
"Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg",
"Steel.Memory.mem",
"Steel.Effect.Atomic.intro_pure",
"Steel.Channel.Simplex.trace_until",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let intro_trace_until_init #p (c: chan_t p) (v: init_chan_val p)
: SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) =
| intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg);
rewrite_slprop ((MRef.pts_to c.trace full_perm (initial_trace p))
`star`
(pure (until (initial_trace p) == step v.chan_prot v.chan_msg)))
((MRef.pts_to c.trace full_perm (initial_trace p))
`star`
(pure (until (initial_trace p) == step v.chan_prot v.chan_msg)))
(fun _ -> ());
intro_exists (initial_trace p) (trace_until_prop c.trace v) | false |
Lens.fst | Lens.op_String_Access | val ( .[] ) (x: 'a) (l: lens 'a 'b) : 'b | val ( .[] ) (x: 'a) (l: lens 'a 'b) : 'b | let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 53,
"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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: 'a -> l: Lens.lens 'a 'b -> 'b | Prims.Tot | [
"total"
] | [] | [
"Lens.lens",
"Lens.op_Bar_Dot"
] | [] | false | false | false | true | false | let ( .[] ) (x: 'a) (l: lens 'a 'b) : 'b =
| x |. l | false |
Lens.fst | Lens.op_String_Assignment | val ( .[]<- ) (x: 'a) (l: lens 'a 'b) (v: 'b) : 'a | val ( .[]<- ) (x: 'a) (l: lens 'a 'b) (v: 'b) : 'a | let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 72,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: 'a -> l: Lens.lens 'a 'b -> v: 'b -> 'a | Prims.Tot | [
"total"
] | [] | [
"Lens.lens",
"Lens.op_Bar_Colon_Equals"
] | [] | false | false | false | true | false | let ( .[]<- ) (x: 'a) (l: lens 'a 'b) (v: 'b) : 'a =
| (x |:= l) v | false |
Lens.fst | Lens.x | val x:lens point int | val x:lens point int | let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 68,
"start_col": 0,
"start_line": 65
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.point Prims.int | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.point",
"Prims.int",
"Lens.__proj__Mkpoint__item__x",
"Lens.Mkpoint",
"Lens.__proj__Mkpoint__item__y",
"Lens.__proj__Mkpoint__item__z"
] | [] | false | false | false | true | false | let x:lens point int =
| { get = (fun p -> p.x); put = (fun x' p -> { p with x = x' }) } | false |
OWGCounter.ST.fst | OWGCounter.ST.incr_main | val incr_main (#v: G.erased int) (r: R.ref int)
: STT unit (R.pts_to r full_perm v) (fun _ -> R.pts_to r full_perm (v + 2)) | val incr_main (#v: G.erased int) (r: R.ref int)
: STT unit (R.pts_to r full_perm v) (fun _ -> R.pts_to r full_perm (v + 2)) | let incr_main (#v:G.erased int) (r:R.ref int)
: STT unit
(R.pts_to r full_perm v)
(fun _ -> R.pts_to r full_perm (v+2))
=
//
// Allocate the ghost state and share
//
let r1 = GR.alloc 0 in
let r2 = GR.alloc v in
GR.share r1;
rewrite (GR.pts_to r1 (P.half_perm full_perm) 0
`star`
GR.pts_to r1 (P.half_perm full_perm) 0)
(GR.pts_to r1 half_perm (fst (0, v))
`star`
GR.pts_to r1 half_perm 0);
GR.share r2;
rewrite (GR.pts_to r2 (P.half_perm full_perm) v
`star`
GR.pts_to r2 (P.half_perm full_perm) v)
(GR.pts_to r2 half_perm (snd (0, G.reveal v))
`star`
GR.pts_to r2 half_perm v);
//
// Set up the lock invariant
//
rewrite (R.pts_to r full_perm v)
(R.pts_to r full_perm (fst (0, v) + snd (0, G.reveal v)));
intro_exists (0, G.reveal v) (lock_inv_predicate r r1 r2);
//
// Create the lock
//
let l = new_lock (lock_inv r r1 r2) in
//
// Now run the two threads in parallel
// Note the r1 and r2 are switched in the two calls
//
let _ = par (incr r r1 r2 true l 0)
(incr r r2 r1 false l v) in
//
// Now we need to gather ghost state and establish the theorem
// We also free the ghost state
//
Steel.ST.SpinLock.acquire l;
let w = elim_exists () in
GR.gather #_ #_ #_ #_ #_ #(G.hide (fst w)) r1;
GR.gather #_ #_ #_ #_ #_ #(G.hide (snd w)) r2;
GR.free r1;
GR.free r2;
rewrite (R.pts_to r full_perm (fst w+snd w))
(R.pts_to r full_perm (v+2)) | {
"file_name": "share/steel/examples/steel/OWGCounter.ST.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 271,
"start_col": 0,
"start_line": 213
} | (*
Copyright 2019 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.
Author: Aseem Rastogi
*)
module OWGCounter.ST
open Steel.Memory
open Steel.ST.Effect.Atomic
open Steel.ST.Effect
open Steel.ST.SpinLock
open Steel.ST.Util
module G = FStar.Ghost
module R = Steel.ST.Reference
module GR = Steel.ST.GhostReference
(*
* An implementation of the parallel counter presented by Owicki and Gries
* "Verifying properties of parallel programs: An axiomatic approach.", CACM'76
*
* In this example, the main thread forks two worker thread that both
* increment a shared counter. The goal of the example is to show that
* after both the worker threads are done, the value of the counter is
* its original value + 2.
*
* See http://pm.inf.ethz.ch/publications/getpdf.php for an implementation
* of the OWG counters in the Chalice framework.
*
* The main idea is that the worker threads maintain ghost state
* that stores their respective contributions to the counter
* And the invariant between the counter and their contributions is
* protected by a lock
*)
#set-options "--ide_id_info_off"
let half_perm = half_perm full_perm
/// r1 and r2 are the ghost references for the two worker threads
///
/// The counter's value is the sum of values of r1 and r2
///
/// The lock contains full permission to the counter,
/// and half permission each for r1 and r2
///
/// Rest of the half permissions for r1 and r2 are given to the
/// two worker threads
[@@ __reduce__]
let lock_inv_predicate (r:R.ref int) (r1 r2:GR.ref int)
: int & int -> vprop
= fun w ->
GR.pts_to r1 half_perm (fst w)
`star`
GR.pts_to r2 half_perm (snd w)
`star`
R.pts_to r full_perm (fst w + snd w)
[@@ __reduce__]
let lock_inv (r:R.ref int) (r1 r2:GR.ref int) : vprop =
exists_ (lock_inv_predicate r r1 r2)
/// For the auxiliary functions, we maintain r1 and r2 as
/// (if b then r1 else r2) and (if b then r2 else r1),
/// where b is a ghost boolean
///
/// This allows us to write a single function that both threads
/// can invoke by switching r1 and r2 as r_mine and r_other
inline_for_extraction
noextract
let acquire (r:R.ref int) (r_mine r_other:GR.ref int) (b:G.erased bool)
(l:lock (lock_inv r (if b then r_mine else r_other)
(if b then r_other else r_mine)))
: STT unit
emp
(fun _ -> lock_inv r r_mine r_other)
= acquire l;
if b returns STGhostT unit
Set.empty
_
(fun _ -> lock_inv r r_mine r_other)
then begin
rewrite (lock_inv _ _ _)
(lock_inv r r_mine r_other)
end
else begin
rewrite (lock_inv _ _ _)
(lock_inv r r_other r_mine);
let w = elim_exists () in
rewrite
(GR.pts_to r_other _ _
`star`
GR.pts_to r_mine _ _
`star`
R.pts_to _ _ _)
(GR.pts_to r_other half_perm (snd (snd w, fst w))
`star`
GR.pts_to r_mine half_perm (fst (snd w, fst w))
`star`
R.pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w)));
intro_exists (snd w, fst w) (lock_inv_predicate r r_mine r_other)
end
inline_for_extraction
noextract
let release (r:R.ref int) (r_mine r_other:GR.ref int) (b:G.erased bool)
(l:lock (lock_inv r (if b then r_mine else r_other)
(if b then r_other else r_mine)))
: STT unit
(lock_inv r r_mine r_other)
(fun _ -> emp)
= if b
then begin
rewrite (lock_inv r r_mine r_other)
(lock_inv r (if b then r_mine else r_other)
(if b then r_other else r_mine))
end
else begin
let w = elim_exists () in
rewrite
(GR.pts_to r_mine half_perm (fst w)
`star`
GR.pts_to r_other half_perm (snd w)
`star`
R.pts_to r full_perm (fst w + snd w))
(GR.pts_to r_mine half_perm (snd (snd w, fst w))
`star`
GR.pts_to r_other half_perm (fst (snd w, fst w))
`star`
R.pts_to r full_perm (fst (snd w, fst w) + snd (snd w, fst w)));
intro_exists
(snd w, fst w)
(lock_inv_predicate r r_other r_mine);
rewrite (lock_inv r r_other r_mine)
(lock_inv r (if b then r_mine else r_other)
(if b then r_other else r_mine))
end;
release l
module P = Steel.FractionalPermission
/// The incr function that each thread invokes in parallel
///
/// It acquires the lock and increments the counter
/// as well as the ghost reference
///
/// Finally releasing the lock after establishing the lock invariant
let incr (r:R.ref int) (r_mine r_other:GR.ref int) (b:G.erased bool)
(l:lock (lock_inv r (if b then r_mine else r_other)
(if b then r_other else r_mine)))
(n:G.erased int)
()
: STT unit
(GR.pts_to r_mine half_perm n)
(fun _ -> GR.pts_to r_mine half_perm (n+1))
= acquire r r_mine r_other b l;
let w = elim_exists () in
//
// The lock has full permission to r,
// so we can just increment it
//
let v = R.read r in
R.write r (v+1);
rewrite
(R.pts_to r full_perm (v+1))
(R.pts_to r full_perm ((fst w+1) + snd w));
//
// The permission to the ghost reference is split
// between the lock and the thread, so we need to gather
// before we can increment
//
GR.gather #_ #_ #_ #_ #n #(G.hide (fst w)) r_mine;
rewrite (GR.pts_to r_mine (sum_perm half_perm half_perm) n)
(GR.pts_to r_mine full_perm n);
GR.write r_mine (n+1);
//
// Now we share back the ghost ref,
// and restore the lock invariant
//
GR.share r_mine;
rewrite (GR.pts_to r_mine (P.half_perm full_perm) (n+1))
(GR.pts_to r_mine half_perm (fst w+1));
intro_exists (fst w+1, snd w)
(lock_inv_predicate r r_mine r_other);
release r r_mine r_other b l;
rewrite (GR.pts_to r_mine (P.half_perm full_perm) (n+1))
(GR.pts_to r_mine half_perm (n+1))
/// The main function that creates the two worker threads, and
/// runs them in parallel | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.SpinLock.fsti.checked",
"Steel.ST.Reference.fsti.checked",
"Steel.ST.GhostReference.fsti.checked",
"Steel.ST.Effect.Atomic.fsti.checked",
"Steel.ST.Effect.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "OWGCounter.ST.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.GhostReference",
"short_module": "GR"
},
{
"abbrev": true,
"full_module": "Steel.ST.Reference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.SpinLock",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "OWGCounter",
"short_module": null
},
{
"abbrev": false,
"full_module": "OWGCounter",
"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 | r: Steel.ST.Reference.ref Prims.int -> Steel.ST.Effect.STT Prims.unit | Steel.ST.Effect.STT | [] | [] | [
"FStar.Ghost.erased",
"Prims.int",
"Steel.ST.Reference.ref",
"Steel.ST.Util.rewrite",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.Reference.pts_to",
"Steel.FractionalPermission.full_perm",
"Prims.op_Addition",
"FStar.Pervasives.Native.fst",
"FStar.Ghost.reveal",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.snd",
"Prims.unit",
"Steel.ST.GhostReference.free",
"Steel.ST.GhostReference.gather",
"OWGCounter.ST.half_perm",
"Steel.ST.Util.elim_exists",
"Steel.Effect.Common.VStar",
"Steel.ST.GhostReference.pts_to",
"Steel.Effect.Common.vprop",
"Steel.ST.SpinLock.acquire",
"OWGCounter.ST.lock_inv",
"Steel.ST.Util.par",
"OWGCounter.ST.incr",
"Prims.bool",
"Steel.ST.SpinLock.lock",
"Steel.ST.SpinLock.new_lock",
"Steel.ST.Util.intro_exists",
"FStar.Pervasives.Native.Mktuple2",
"OWGCounter.ST.lock_inv_predicate",
"Steel.Effect.Common.star",
"Steel.FractionalPermission.half_perm",
"Steel.ST.GhostReference.share",
"Steel.ST.GhostReference.ref",
"Steel.ST.GhostReference.alloc"
] | [] | false | true | false | false | false | let incr_main (#v: G.erased int) (r: R.ref int)
: STT unit (R.pts_to r full_perm v) (fun _ -> R.pts_to r full_perm (v + 2)) =
| let r1 = GR.alloc 0 in
let r2 = GR.alloc v in
GR.share r1;
rewrite ((GR.pts_to r1 (P.half_perm full_perm) 0) `star` (GR.pts_to r1 (P.half_perm full_perm) 0))
((GR.pts_to r1 half_perm (fst (0, v))) `star` (GR.pts_to r1 half_perm 0));
GR.share r2;
rewrite ((GR.pts_to r2 (P.half_perm full_perm) v) `star` (GR.pts_to r2 (P.half_perm full_perm) v))
((GR.pts_to r2 half_perm (snd (0, G.reveal v))) `star` (GR.pts_to r2 half_perm v));
rewrite (R.pts_to r full_perm v) (R.pts_to r full_perm (fst (0, v) + snd (0, G.reveal v)));
intro_exists (0, G.reveal v) (lock_inv_predicate r r1 r2);
let l = new_lock (lock_inv r r1 r2) in
let _ = par (incr r r1 r2 true l 0) (incr r r2 r1 false l v) in
Steel.ST.SpinLock.acquire l;
let w = elim_exists () in
GR.gather #_ #_ #_ #_ #_ #(G.hide (fst w)) r1;
GR.gather #_ #_ #_ #_ #_ #(G.hide (snd w)) r2;
GR.free r1;
GR.free r2;
rewrite (R.pts_to r full_perm (fst w + snd w)) (R.pts_to r full_perm (v + 2)) | false |
Lens.fst | Lens.y | val y:lens point int | val y:lens point int | let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 73,
"start_col": 0,
"start_line": 70
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.point Prims.int | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.point",
"Prims.int",
"Lens.__proj__Mkpoint__item__y",
"Lens.Mkpoint",
"Lens.__proj__Mkpoint__item__x",
"Lens.__proj__Mkpoint__item__z"
] | [] | false | false | false | true | false | let y:lens point int =
| { get = (fun p -> p.y); put = (fun y' p -> { p with y = y' }) } | false |
Lens.fst | Lens.center | val center:lens circle point | val center:lens circle point | let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 90,
"start_col": 0,
"start_line": 87
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.circle Lens.point | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.circle",
"Lens.point",
"Lens.__proj__Mkcircle__item__center",
"Lens.Mkcircle",
"Lens.__proj__Mkcircle__item__radius"
] | [] | false | false | false | true | false | let center:lens circle point =
| { get = (fun c -> c.center); put = (fun n c -> { c with center = n }) } | false |
Lens.fst | Lens.z | val z:lens point int | val z:lens point int | let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 78,
"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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.point Prims.int | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.point",
"Prims.int",
"Lens.__proj__Mkpoint__item__z",
"Lens.Mkpoint",
"Lens.__proj__Mkpoint__item__x",
"Lens.__proj__Mkpoint__item__y"
] | [] | false | false | false | true | false | let z:lens point int =
| { get = (fun p -> p.z); put = (fun z' p -> { p with z = z' }) } | false |
Lens.fst | Lens.getY'' | val getY'' : c: Lens.circle -> Prims.int | let getY'' (c:circle) = c.center.y | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 105,
"start_col": 0,
"start_line": 105
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ... | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.circle -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Lens.circle",
"Lens.__proj__Mkpoint__item__y",
"Lens.__proj__Mkcircle__item__center",
"Prims.int"
] | [] | false | false | false | true | false | let getY'' (c: circle) =
| c.center.y | false |
|
Lens.fst | Lens.getY | val getY : c: Lens.circle -> Prims.int | let getY (c:circle) = c |. center |. y | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 97,
"start_col": 0,
"start_line": 97
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.circle -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Lens.circle",
"Lens.op_Bar_Dot",
"Lens.point",
"Prims.int",
"Lens.center",
"Lens.y"
] | [] | false | false | false | true | false | let getY (c: circle) =
| c |. center |. y | false |
|
Lens.fst | Lens.radius | val radius:lens circle nat | val radius:lens circle nat | let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 94,
"start_col": 0,
"start_line": 91
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.circle Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.circle",
"Prims.nat",
"Lens.__proj__Mkcircle__item__radius",
"Lens.Mkcircle",
"Lens.__proj__Mkcircle__item__center"
] | [] | false | false | false | true | false | let radius:lens circle nat =
| { get = (fun c -> c.radius); put = (fun n c -> { c with radius = n }) } | false |
Lens.fst | Lens.getY' | val getY' : c: Lens.circle -> Prims.int | let getY' (c:circle) = c.[center |.. y] | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 100,
"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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.circle -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Lens.circle",
"Lens.op_String_Access",
"Prims.int",
"Lens.op_Bar_Dot_Dot",
"Lens.point",
"Lens.center",
"Lens.y"
] | [] | false | false | false | true | false | let getY' (c: circle) =
| c.[ center |.. y ] | false |
|
Lens.fst | Lens.setY | val setY : c: Lens.circle -> new_y: Prims.int -> Lens.circle | let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 109,
"start_col": 0,
"start_line": 108
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.circle -> new_y: Prims.int -> Lens.circle | Prims.Tot | [
"total"
] | [] | [
"Lens.circle",
"Prims.int",
"Lens.op_String_Assignment",
"Lens.op_Bar_Dot_Dot",
"Lens.point",
"Lens.center",
"Lens.y"
] | [] | false | false | false | true | false | let setY (c: circle) (new_y: int) =
| c.[ center |.. y ] <- new_y | false |
|
Lens.fst | Lens.tedious_setY | val tedious_setY : c: Lens.circle -> new_y: Prims.int -> Lens.circle | let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 112,
"start_col": 0,
"start_line": 111
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.circle -> new_y: Prims.int -> Lens.circle | Prims.Tot | [
"total"
] | [] | [
"Lens.circle",
"Prims.int",
"Lens.Mkcircle",
"Lens.Mkpoint",
"Lens.__proj__Mkpoint__item__x",
"Lens.__proj__Mkpoint__item__z",
"Lens.point",
"Lens.__proj__Mkcircle__item__center",
"Lens.__proj__Mkcircle__item__radius"
] | [] | false | false | false | true | false | let tedious_setY (c: circle) (new_y: int) =
| { c with center = { c.center with y = new_y } } | false |
|
Lens.fst | Lens.moveUp | val moveUp : c: Lens.circle -> offset_y: Prims.int -> Lens.circle | let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 51,
"end_line": 116,
"start_col": 0,
"start_line": 115
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.circle -> offset_y: Prims.int -> Lens.circle | Prims.Tot | [
"total"
] | [] | [
"Lens.circle",
"Prims.int",
"Lens.op_String_Assignment",
"Lens.op_Bar_Dot_Dot",
"Lens.point",
"Lens.center",
"Lens.y",
"Prims.op_Addition",
"Lens.op_String_Access"
] | [] | false | false | false | true | false | let moveUp (c: circle) (offset_y: int) =
| c.[ center |.. y ] <- c.[ center |.. y ] + offset_y | false |
|
Lens.fst | Lens.green | val green:lens rgb nat | val green:lens rgb nat | let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 134,
"start_col": 0,
"start_line": 131
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.rgb Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.rgb",
"Prims.nat",
"Lens.__proj__Mkrgb__item__green",
"Lens.Mkrgb",
"Lens.__proj__Mkrgb__item__red",
"Lens.__proj__Mkrgb__item__blue"
] | [] | false | false | false | true | false | let green:lens rgb nat =
| { get = (fun p -> p.green); put = (fun z p -> { p with green = z }) } | false |
Lens.fst | Lens.red | val red:lens rgb nat | val red:lens rgb nat | let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 130,
"start_col": 0,
"start_line": 127
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.rgb Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.rgb",
"Prims.nat",
"Lens.__proj__Mkrgb__item__red",
"Lens.Mkrgb",
"Lens.__proj__Mkrgb__item__green",
"Lens.__proj__Mkrgb__item__blue"
] | [] | false | false | false | true | false | let red:lens rgb nat =
| { get = (fun p -> p.red); put = (fun z p -> { p with red = z }) } | false |
Lens.fst | Lens.blue | val blue:lens rgb nat | val blue:lens rgb nat | let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 138,
"start_col": 0,
"start_line": 135
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens Lens.rgb Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.rgb",
"Prims.nat",
"Lens.__proj__Mkrgb__item__blue",
"Lens.Mkrgb",
"Lens.__proj__Mkrgb__item__red",
"Lens.__proj__Mkrgb__item__green"
] | [] | false | false | false | true | false | let blue:lens rgb nat =
| { get = (fun p -> p.blue); put = (fun z p -> { p with blue = z }) } | false |
Lens.fst | Lens.color | val color (#a: Type) : lens (colored a) rgb | val color (#a: Type) : lens (colored a) rgb | let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 149,
"start_col": 0,
"start_line": 146
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens (Lens.colored a) Lens.rgb | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.colored",
"Lens.rgb",
"Lens.__proj__Mkcolored__item__color",
"Lens.Mkcolored",
"Lens.__proj__Mkcolored__item__payload",
"Lens.lens"
] | [] | false | false | false | true | false | let color (#a: Type) : lens (colored a) rgb =
| { get = (fun p -> p.color); put = (fun z p -> { p with color = z }) } | false |
Lens.fst | Lens.payload | val payload (#a: Type) : lens (colored a) a | val payload (#a: Type) : lens (colored a) a | let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 153,
"start_col": 0,
"start_line": 150
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z}) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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 | Lens.lens (Lens.colored a) a | Prims.Tot | [
"total"
] | [] | [
"Lens.Mklens",
"Lens.colored",
"Lens.__proj__Mkcolored__item__payload",
"Lens.Mkcolored",
"Lens.__proj__Mkcolored__item__color",
"Lens.lens"
] | [] | false | false | false | true | false | let payload (#a: Type) : lens (colored a) a =
| { get = (fun p -> p.payload); put = (fun z p -> { p with payload = z }) } | false |
Lens.fst | Lens.moveUp' | val moveUp' : c: Lens.colored Lens.circle -> offset_y: Prims.int -> Lens.colored Lens.circle | let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 75,
"end_line": 157,
"start_col": 0,
"start_line": 156
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.colored Lens.circle -> offset_y: Prims.int -> Lens.colored Lens.circle | Prims.Tot | [
"total"
] | [] | [
"Lens.colored",
"Lens.circle",
"Prims.int",
"Lens.op_String_Assignment",
"Lens.op_Bar_Dot_Dot",
"Lens.point",
"Lens.payload",
"Lens.center",
"Lens.y",
"Prims.op_Addition",
"Lens.op_String_Access"
] | [] | false | false | false | true | false | let moveUp' (c: colored circle) (offset_y: int) =
| c.[ payload |.. center |.. y ] <- c.[ payload |.. center |.. y ] + offset_y | false |
|
Lens.fst | Lens.makeGreen | val makeGreen : c: Lens.colored Lens.circle -> Lens.colored Lens.circle | let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0 | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 168,
"start_col": 0,
"start_line": 167
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"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: Lens.colored Lens.circle -> Lens.colored Lens.circle | Prims.Tot | [
"total"
] | [] | [
"Lens.colored",
"Lens.circle",
"Lens.op_String_Assignment",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Lens.op_Bar_Dot_Dot",
"Lens.rgb",
"Lens.color",
"Lens.op_Bar_Bar",
"Lens.red",
"Lens.green",
"Lens.blue",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | false | false | true | false | let makeGreen (c: colored circle) =
| c.[ color |.. (red || green || blue) ] <- (0, 1), 0 | false |
|
Lens.fst | Lens.op_Array_Assignment | val op_Array_Assignment : x: FStar.ST.ref a -> m: Lens.lens a b -> y: b -> FStar.ST.STATE Prims.unit | let op_Array_Assignment #a #b (x:ref a) (m:lens a b) (y:b)
= let _ = (x |::= (st m)) y in () | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 232,
"start_col": 0,
"start_line": 231
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
}
/// And now you can use these to update multiple components at once
let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0
////////////////////////////////////////////////////////////////////////////////
/// Now for some stateful stuff
/// – This is not quite as nice an compositional as before
/// Would be curious to have your thoughts on how it could be generalized
/// (My first naive attempt: See StatefulLens for how to do it better)
////////////////////////////////////////////////////////////////////////////////
open FStar.Heap
open FStar.Ref
/// An `stlens #a #b l` goes via a `ref a` to access the `b`component
/// that is focused by `l`
noeq
type stlens (#a:Type) (#b:Type) (l:lens a b) = {
// Getting a `b` from an `r:ref a` requires dereferencing it
// and then reaching into the result with `l`
st_get: r:ref a
-> ST b
(requires (fun h -> True))
(ensures (fun h0 b h1 -> h0==h1 /\ b == ((sel h1 r)|. l)));
// Setting a `b` component inside a `r:ref a` modifies only `r`
// and updates the contents of `r` using `l`
st_put: y:b
-> r:ref a
-> ST (ref a)
(requires (fun h -> True))
(ensures (fun h0 s h1 ->
r == s /\
modifies (Set.singleton (addr_of r)) h0 h1 /\
(sel h1 r == ((sel h0 r).[l] <- y))))
}
/// You can turn a regular lens into a stateful lens
let st #a #b (l:lens a b) : stlens l = {
st_get = (fun (r:ref a) -> (!r).[l]);
st_put = (fun (x:b) (r:ref a) -> r := (!r.[l] <- x); r)
}
/// And we can compose a stateful lens with a pure lens on the right
let ( |:.. ) #a #b #c (#l:lens a b) (sl:stlens l) (m:lens b c) : stlens (l |.. m) = {
st_get = (fun (r:ref a) -> (sl.st_get r).[m]);
st_put = (fun (x:c) (r:ref a) -> sl.st_put ((sl.st_get r).[m] <- x) r)
}
/// Limitations:
/// But, you can't compose an stlens with another stlens
/// – Because the spec of st_get and st_put is inherently rigged to
/// work with a single reference
/// Nor can you compose a pure lens with an stlens on the left
/// - Because stlens's always start with a ref
/// We can define access and mutation operators for stlenses
let ( |:. ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) = s.st_get x
let ( |::= ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) (y:b) = s.st_put y x
/// Although, as before the access/assignment operators probably work better
/// x.(m) <- v: promotes m to a stateful lens and then updates x's m
/// component with v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ref",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"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: FStar.ST.ref a -> m: Lens.lens a b -> y: b -> FStar.ST.STATE Prims.unit | FStar.ST.STATE | [
"trivial_postcondition"
] | [] | [
"FStar.ST.ref",
"Lens.lens",
"Prims.unit",
"Lens.op_Bar_Colon_Colon_Equals",
"Lens.st"
] | [] | false | true | false | false | false | let ( .()<- ) #a #b (x: ref a) (m: lens a b) (y: b) =
| let _ = (x |::= (st m)) y in
() | false |
|
Lens.fst | Lens.op_Array_Access | val op_Array_Access : x: FStar.ST.ref a -> m: Lens.lens a b -> FStar.ST.ST b | let op_Array_Access #a #b (x:ref a) (m:lens a b)
= x |:. (st m) | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 236,
"start_col": 0,
"start_line": 235
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
}
/// And now you can use these to update multiple components at once
let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0
////////////////////////////////////////////////////////////////////////////////
/// Now for some stateful stuff
/// – This is not quite as nice an compositional as before
/// Would be curious to have your thoughts on how it could be generalized
/// (My first naive attempt: See StatefulLens for how to do it better)
////////////////////////////////////////////////////////////////////////////////
open FStar.Heap
open FStar.Ref
/// An `stlens #a #b l` goes via a `ref a` to access the `b`component
/// that is focused by `l`
noeq
type stlens (#a:Type) (#b:Type) (l:lens a b) = {
// Getting a `b` from an `r:ref a` requires dereferencing it
// and then reaching into the result with `l`
st_get: r:ref a
-> ST b
(requires (fun h -> True))
(ensures (fun h0 b h1 -> h0==h1 /\ b == ((sel h1 r)|. l)));
// Setting a `b` component inside a `r:ref a` modifies only `r`
// and updates the contents of `r` using `l`
st_put: y:b
-> r:ref a
-> ST (ref a)
(requires (fun h -> True))
(ensures (fun h0 s h1 ->
r == s /\
modifies (Set.singleton (addr_of r)) h0 h1 /\
(sel h1 r == ((sel h0 r).[l] <- y))))
}
/// You can turn a regular lens into a stateful lens
let st #a #b (l:lens a b) : stlens l = {
st_get = (fun (r:ref a) -> (!r).[l]);
st_put = (fun (x:b) (r:ref a) -> r := (!r.[l] <- x); r)
}
/// And we can compose a stateful lens with a pure lens on the right
let ( |:.. ) #a #b #c (#l:lens a b) (sl:stlens l) (m:lens b c) : stlens (l |.. m) = {
st_get = (fun (r:ref a) -> (sl.st_get r).[m]);
st_put = (fun (x:c) (r:ref a) -> sl.st_put ((sl.st_get r).[m] <- x) r)
}
/// Limitations:
/// But, you can't compose an stlens with another stlens
/// – Because the spec of st_get and st_put is inherently rigged to
/// work with a single reference
/// Nor can you compose a pure lens with an stlens on the left
/// - Because stlens's always start with a ref
/// We can define access and mutation operators for stlenses
let ( |:. ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) = s.st_get x
let ( |::= ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) (y:b) = s.st_put y x
/// Although, as before the access/assignment operators probably work better
/// x.(m) <- v: promotes m to a stateful lens and then updates x's m
/// component with v
/// -- Making them return unit since that works better with sequencing `;`
let op_Array_Assignment #a #b (x:ref a) (m:lens a b) (y:b)
= let _ = (x |::= (st m)) y in () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ref",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"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: FStar.ST.ref a -> m: Lens.lens a b -> FStar.ST.ST b | FStar.ST.ST | [] | [] | [
"FStar.ST.ref",
"Lens.lens",
"Lens.op_Bar_Colon_Dot",
"Lens.st"
] | [] | false | true | false | false | false | let ( .() ) #a #b (x: ref a) (m: lens a b) =
| x |:. (st m) | false |
|
Lens.fst | Lens.mutate | val mutate : c: FStar.ST.ref (Lens.colored Lens.circle) -> FStar.ST.STATE Prims.unit | let mutate (c:ref (colored circle)) =
c.(color |.. (red || green || blue)) <- (0, 1), 2 | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 240,
"start_col": 0,
"start_line": 239
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
}
/// And now you can use these to update multiple components at once
let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0
////////////////////////////////////////////////////////////////////////////////
/// Now for some stateful stuff
/// – This is not quite as nice an compositional as before
/// Would be curious to have your thoughts on how it could be generalized
/// (My first naive attempt: See StatefulLens for how to do it better)
////////////////////////////////////////////////////////////////////////////////
open FStar.Heap
open FStar.Ref
/// An `stlens #a #b l` goes via a `ref a` to access the `b`component
/// that is focused by `l`
noeq
type stlens (#a:Type) (#b:Type) (l:lens a b) = {
// Getting a `b` from an `r:ref a` requires dereferencing it
// and then reaching into the result with `l`
st_get: r:ref a
-> ST b
(requires (fun h -> True))
(ensures (fun h0 b h1 -> h0==h1 /\ b == ((sel h1 r)|. l)));
// Setting a `b` component inside a `r:ref a` modifies only `r`
// and updates the contents of `r` using `l`
st_put: y:b
-> r:ref a
-> ST (ref a)
(requires (fun h -> True))
(ensures (fun h0 s h1 ->
r == s /\
modifies (Set.singleton (addr_of r)) h0 h1 /\
(sel h1 r == ((sel h0 r).[l] <- y))))
}
/// You can turn a regular lens into a stateful lens
let st #a #b (l:lens a b) : stlens l = {
st_get = (fun (r:ref a) -> (!r).[l]);
st_put = (fun (x:b) (r:ref a) -> r := (!r.[l] <- x); r)
}
/// And we can compose a stateful lens with a pure lens on the right
let ( |:.. ) #a #b #c (#l:lens a b) (sl:stlens l) (m:lens b c) : stlens (l |.. m) = {
st_get = (fun (r:ref a) -> (sl.st_get r).[m]);
st_put = (fun (x:c) (r:ref a) -> sl.st_put ((sl.st_get r).[m] <- x) r)
}
/// Limitations:
/// But, you can't compose an stlens with another stlens
/// – Because the spec of st_get and st_put is inherently rigged to
/// work with a single reference
/// Nor can you compose a pure lens with an stlens on the left
/// - Because stlens's always start with a ref
/// We can define access and mutation operators for stlenses
let ( |:. ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) = s.st_get x
let ( |::= ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) (y:b) = s.st_put y x
/// Although, as before the access/assignment operators probably work better
/// x.(m) <- v: promotes m to a stateful lens and then updates x's m
/// component with v
/// -- Making them return unit since that works better with sequencing `;`
let op_Array_Assignment #a #b (x:ref a) (m:lens a b) (y:b)
= let _ = (x |::= (st m)) y in ()
/// x.(m): promotes m to a stateful lens and access x's m component
let op_Array_Access #a #b (x:ref a) (m:lens a b)
= x |:. (st m) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ref",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"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: FStar.ST.ref (Lens.colored Lens.circle) -> FStar.ST.STATE Prims.unit | FStar.ST.STATE | [
"trivial_postcondition"
] | [] | [
"FStar.ST.ref",
"Lens.colored",
"Lens.circle",
"Lens.op_Array_Assignment",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Lens.op_Bar_Dot_Dot",
"Lens.rgb",
"Lens.color",
"Lens.op_Bar_Bar",
"Lens.red",
"Lens.green",
"Lens.blue",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit"
] | [] | false | true | false | false | false | let mutate (c: ref (colored circle)) =
| c.(color |.. (red || green || blue)) <- (0, 1), 2 | false |
|
FStar.ErasedLogic.fst | FStar.ErasedLogic.gex_proj1 | val gex_proj1 : #a:Type -> #p:(a->Type) -> (ex a p) -> GTot a | val gex_proj1 : #a:Type -> #p:(a->Type) -> (ex a p) -> GTot a | let gex_proj1 #a #p e = (reveal (ex_proj1 e)) | {
"file_name": "ulib/legacy/FStar.ErasedLogic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 45,
"end_line": 44,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.ErasedLogic
(*F* 's exists should be thought of Coq's sigT. It is totally unerased *)
(*Coq has 2 more versions, with increasing degree of erasure*)
(* https://coq.inria.fr/library/Coq.Init.Specif.html#sigT *)
open FStar.Ghost
(*you can get the witness x, that the proof part is erased*)
(*https://coq.inria.fr/library/Coq.Init.Specif.html#sig*)
type sig_ (a:Type) (p: a->Type) = exists (x:a). (erased (p x))
(*you get nothing. Of course, in ghost contexts, or to build other erased date, you get everything*)
(* https://coq.inria.fr/library/Coq.Init.Logic.html#ex *)
type ex (a:Type) (p:a->Type) = erased (exists (x:a). (p x))
(*how to use the above:*)
(*assuming that existentials in F* are constructive. If so, the following 2 assumes must be definable*)
assume val exists_proj1 : #a:Type -> #p:(a->Type) -> (exists x.p x) -> GTot a
assume val mkexists : #a:Type -> #p:(a->Type) -> x:a -> (p x) -> Tot (exists x.p x)
val ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a)
let ex_proj1 #a #p e = (elift1 (exists_proj1 #a #p)) e | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.ErasedLogic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"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 | e: FStar.ErasedLogic.ex a p -> Prims.GTot a | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.ErasedLogic.ex",
"FStar.Ghost.reveal",
"FStar.ErasedLogic.ex_proj1"
] | [] | false | false | false | false | false | let gex_proj1 #a #p e =
| (reveal (ex_proj1 e)) | false |
Lens.fst | Lens.mutate3 | val mutate3 : c: FStar.ST.ref (Lens.colored (FStar.ST.ref (Lens.colored (FStar.ST.ref Lens.circle))))
-> FStar.ST.STATE Prims.unit | let mutate3 (c:ref (colored (ref (colored (ref circle))))) =
((c.(payload)).(payload)).(center |.. x) <- 17 | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 254,
"start_col": 0,
"start_line": 253
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
}
/// And now you can use these to update multiple components at once
let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0
////////////////////////////////////////////////////////////////////////////////
/// Now for some stateful stuff
/// – This is not quite as nice an compositional as before
/// Would be curious to have your thoughts on how it could be generalized
/// (My first naive attempt: See StatefulLens for how to do it better)
////////////////////////////////////////////////////////////////////////////////
open FStar.Heap
open FStar.Ref
/// An `stlens #a #b l` goes via a `ref a` to access the `b`component
/// that is focused by `l`
noeq
type stlens (#a:Type) (#b:Type) (l:lens a b) = {
// Getting a `b` from an `r:ref a` requires dereferencing it
// and then reaching into the result with `l`
st_get: r:ref a
-> ST b
(requires (fun h -> True))
(ensures (fun h0 b h1 -> h0==h1 /\ b == ((sel h1 r)|. l)));
// Setting a `b` component inside a `r:ref a` modifies only `r`
// and updates the contents of `r` using `l`
st_put: y:b
-> r:ref a
-> ST (ref a)
(requires (fun h -> True))
(ensures (fun h0 s h1 ->
r == s /\
modifies (Set.singleton (addr_of r)) h0 h1 /\
(sel h1 r == ((sel h0 r).[l] <- y))))
}
/// You can turn a regular lens into a stateful lens
let st #a #b (l:lens a b) : stlens l = {
st_get = (fun (r:ref a) -> (!r).[l]);
st_put = (fun (x:b) (r:ref a) -> r := (!r.[l] <- x); r)
}
/// And we can compose a stateful lens with a pure lens on the right
let ( |:.. ) #a #b #c (#l:lens a b) (sl:stlens l) (m:lens b c) : stlens (l |.. m) = {
st_get = (fun (r:ref a) -> (sl.st_get r).[m]);
st_put = (fun (x:c) (r:ref a) -> sl.st_put ((sl.st_get r).[m] <- x) r)
}
/// Limitations:
/// But, you can't compose an stlens with another stlens
/// – Because the spec of st_get and st_put is inherently rigged to
/// work with a single reference
/// Nor can you compose a pure lens with an stlens on the left
/// - Because stlens's always start with a ref
/// We can define access and mutation operators for stlenses
let ( |:. ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) = s.st_get x
let ( |::= ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) (y:b) = s.st_put y x
/// Although, as before the access/assignment operators probably work better
/// x.(m) <- v: promotes m to a stateful lens and then updates x's m
/// component with v
/// -- Making them return unit since that works better with sequencing `;`
let op_Array_Assignment #a #b (x:ref a) (m:lens a b) (y:b)
= let _ = (x |::= (st m)) y in ()
/// x.(m): promotes m to a stateful lens and access x's m component
let op_Array_Access #a #b (x:ref a) (m:lens a b)
= x |:. (st m)
/// You can write stuff like this to go past a ref and then update
let mutate (c:ref (colored circle)) =
c.(color |.. (red || green || blue)) <- (0, 1), 2
/// But, as you nest refs further, you're forces to break up the updates
/// piecewise, since stlenses don't compose
let mutate2 (c:ref (colored (ref circle))) =
c.(color |.. (red || green || blue)) <- (0, 1), 2;
(c.(payload)).(center |.. x) <- 17
//i.e., you can't write c.(payload |.. center |.. x) <- 17
//Also, sadly, you seem to need parantheses on the first access
//i.e., c.(payload).(center |.. x) <- 17 parses as
// c.(payload.(center |.. x)) <- 17 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ref",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"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: FStar.ST.ref (Lens.colored (FStar.ST.ref (Lens.colored (FStar.ST.ref Lens.circle))))
-> FStar.ST.STATE Prims.unit | FStar.ST.STATE | [
"trivial_postcondition"
] | [] | [
"FStar.ST.ref",
"Lens.colored",
"Lens.circle",
"Lens.op_Array_Assignment",
"Prims.int",
"Lens.op_Bar_Dot_Dot",
"Lens.point",
"Lens.center",
"Lens.x",
"Prims.unit",
"Lens.op_Array_Access",
"Lens.payload"
] | [] | false | true | false | false | false | let mutate3 (c: ref (colored (ref (colored (ref circle))))) =
| ((c.(payload)).(payload)).(center |.. x) <- 17 | false |
|
Lens.fst | Lens.mutate2 | val mutate2 : c: FStar.ST.ref (Lens.colored (FStar.ST.ref Lens.circle)) -> FStar.ST.STATE Prims.unit | let mutate2 (c:ref (colored (ref circle))) =
c.(color |.. (red || green || blue)) <- (0, 1), 2;
(c.(payload)).(center |.. x) <- 17 | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 246,
"start_col": 0,
"start_line": 244
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
}
/// And now you can use these to update multiple components at once
let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0
////////////////////////////////////////////////////////////////////////////////
/// Now for some stateful stuff
/// – This is not quite as nice an compositional as before
/// Would be curious to have your thoughts on how it could be generalized
/// (My first naive attempt: See StatefulLens for how to do it better)
////////////////////////////////////////////////////////////////////////////////
open FStar.Heap
open FStar.Ref
/// An `stlens #a #b l` goes via a `ref a` to access the `b`component
/// that is focused by `l`
noeq
type stlens (#a:Type) (#b:Type) (l:lens a b) = {
// Getting a `b` from an `r:ref a` requires dereferencing it
// and then reaching into the result with `l`
st_get: r:ref a
-> ST b
(requires (fun h -> True))
(ensures (fun h0 b h1 -> h0==h1 /\ b == ((sel h1 r)|. l)));
// Setting a `b` component inside a `r:ref a` modifies only `r`
// and updates the contents of `r` using `l`
st_put: y:b
-> r:ref a
-> ST (ref a)
(requires (fun h -> True))
(ensures (fun h0 s h1 ->
r == s /\
modifies (Set.singleton (addr_of r)) h0 h1 /\
(sel h1 r == ((sel h0 r).[l] <- y))))
}
/// You can turn a regular lens into a stateful lens
let st #a #b (l:lens a b) : stlens l = {
st_get = (fun (r:ref a) -> (!r).[l]);
st_put = (fun (x:b) (r:ref a) -> r := (!r.[l] <- x); r)
}
/// And we can compose a stateful lens with a pure lens on the right
let ( |:.. ) #a #b #c (#l:lens a b) (sl:stlens l) (m:lens b c) : stlens (l |.. m) = {
st_get = (fun (r:ref a) -> (sl.st_get r).[m]);
st_put = (fun (x:c) (r:ref a) -> sl.st_put ((sl.st_get r).[m] <- x) r)
}
/// Limitations:
/// But, you can't compose an stlens with another stlens
/// – Because the spec of st_get and st_put is inherently rigged to
/// work with a single reference
/// Nor can you compose a pure lens with an stlens on the left
/// - Because stlens's always start with a ref
/// We can define access and mutation operators for stlenses
let ( |:. ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) = s.st_get x
let ( |::= ) #a #b (#l:lens a b) (x:ref a) (s:stlens l) (y:b) = s.st_put y x
/// Although, as before the access/assignment operators probably work better
/// x.(m) <- v: promotes m to a stateful lens and then updates x's m
/// component with v
/// -- Making them return unit since that works better with sequencing `;`
let op_Array_Assignment #a #b (x:ref a) (m:lens a b) (y:b)
= let _ = (x |::= (st m)) y in ()
/// x.(m): promotes m to a stateful lens and access x's m component
let op_Array_Access #a #b (x:ref a) (m:lens a b)
= x |:. (st m)
/// You can write stuff like this to go past a ref and then update
let mutate (c:ref (colored circle)) =
c.(color |.. (red || green || blue)) <- (0, 1), 2
/// But, as you nest refs further, you're forces to break up the updates | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ref",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"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: FStar.ST.ref (Lens.colored (FStar.ST.ref Lens.circle)) -> FStar.ST.STATE Prims.unit | FStar.ST.STATE | [
"trivial_postcondition"
] | [] | [
"FStar.ST.ref",
"Lens.colored",
"Lens.circle",
"Lens.op_Array_Assignment",
"Prims.int",
"Lens.op_Bar_Dot_Dot",
"Lens.point",
"Lens.center",
"Lens.x",
"Prims.unit",
"Lens.op_Array_Access",
"Lens.payload",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Lens.rgb",
"Lens.color",
"Lens.op_Bar_Bar",
"Lens.red",
"Lens.green",
"Lens.blue",
"FStar.Pervasives.Native.Mktuple2"
] | [] | false | true | false | false | false | let mutate2 (c: ref (colored (ref circle))) =
| c.(color |.. (red || green || blue)) <- (0, 1), 2;
(c.(payload)).(center |.. x) <- 17 | false |
|
FStar.ErasedLogic.fst | FStar.ErasedLogic.ex_proj1 | val ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a) | val ex_proj1 : #a:Type -> #p:(a->Type) -> ex a p -> Tot (erased a) | let ex_proj1 #a #p e = (elift1 (exists_proj1 #a #p)) e | {
"file_name": "ulib/legacy/FStar.ErasedLogic.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 40,
"start_col": 0,
"start_line": 40
} | (*
Copyright 2008-2014 Nikhil Swamy and 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.ErasedLogic
(*F* 's exists should be thought of Coq's sigT. It is totally unerased *)
(*Coq has 2 more versions, with increasing degree of erasure*)
(* https://coq.inria.fr/library/Coq.Init.Specif.html#sigT *)
open FStar.Ghost
(*you can get the witness x, that the proof part is erased*)
(*https://coq.inria.fr/library/Coq.Init.Specif.html#sig*)
type sig_ (a:Type) (p: a->Type) = exists (x:a). (erased (p x))
(*you get nothing. Of course, in ghost contexts, or to build other erased date, you get everything*)
(* https://coq.inria.fr/library/Coq.Init.Logic.html#ex *)
type ex (a:Type) (p:a->Type) = erased (exists (x:a). (p x))
(*how to use the above:*)
(*assuming that existentials in F* are constructive. If so, the following 2 assumes must be definable*)
assume val exists_proj1 : #a:Type -> #p:(a->Type) -> (exists x.p x) -> GTot a
assume val mkexists : #a:Type -> #p:(a->Type) -> x:a -> (p x) -> Tot (exists x.p x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.ErasedLogic.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ghost",
"short_module": null
},
{
"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 | e: FStar.ErasedLogic.ex a p -> FStar.Ghost.erased a | Prims.Tot | [
"total"
] | [] | [
"FStar.ErasedLogic.ex",
"FStar.Ghost.elift1",
"Prims.l_Exists",
"FStar.ErasedLogic.exists_proj1",
"FStar.Ghost.erased"
] | [] | false | false | false | false | false | let ex_proj1 #a #p e =
| (elift1 (exists_proj1 #a #p)) e | false |
EverParse3d.Actions.Base.fst | EverParse3d.Actions.Base.validate_dep_pair_with_refinement' | val validate_dep_pair_with_refinement'
(name1: string)
(#nz1: _)
(#k1: parser_kind nz1 _)
(#t1: _)
(#p1: parser k1 t1)
(#inv1 #disj1 #l1: _)
(v1: validate_with_action_t p1 inv1 disj1 l1 true)
(r1: leaf_reader p1)
(f: (t1 -> bool))
(#nz2 #wk2: _)
(#k2: parser_kind nz2 wk2)
(#t2: (refine _ f -> Type))
(#p2: (x: refine _ f -> parser k2 (t2 x)))
(#inv2 #disj2 #l2 #ar2: _)
(v2: (x: refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
: Tot
(validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2)
(conj_inv inv1 inv2)
(conj_disjointness disj1 disj2)
(l1 `eloc_union` l2)
false) | val validate_dep_pair_with_refinement'
(name1: string)
(#nz1: _)
(#k1: parser_kind nz1 _)
(#t1: _)
(#p1: parser k1 t1)
(#inv1 #disj1 #l1: _)
(v1: validate_with_action_t p1 inv1 disj1 l1 true)
(r1: leaf_reader p1)
(f: (t1 -> bool))
(#nz2 #wk2: _)
(#k2: parser_kind nz2 wk2)
(#t2: (refine _ f -> Type))
(#p2: (x: refine _ f -> parser k2 (t2 x)))
(#inv2 #disj2 #l2 #ar2: _)
(v2: (x: refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
: Tot
(validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2)
(conj_inv inv1 inv2)
(conj_disjointness disj1 disj2)
(l1 `eloc_union` l2)
false) | let validate_dep_pair_with_refinement'
(name1: string)
#nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1)
#inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1)
(f: t1 -> bool)
#nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x)))
#inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
: Tot (validate_with_action_t
((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2)
(conj_inv inv1 inv2)
(conj_disjointness disj1 disj2)
(l1 `eloc_union` l2)
false)
= fun ctxt error_handler_fn input input_length startPosition ->
let h0 = HST.get () in
LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0);
LPC.parse_filter_eq p1 f (I.get_remaining input h0);
[@(rename_let ("positionAfter" ^ name1))]
let res = v1 ctxt error_handler_fn input input_length startPosition in
let h1 = HST.get() in
modifies_address_liveness_insensitive_unused_in h0 h1;
if LPE.is_error res
then begin
res
end
else begin
[@(rename_let ("" ^ name1))]
let field_value = r1 input startPosition in
[@(rename_let (name1 ^ "ConstraintIsOk"))]
let ok = f field_value in
[@(rename_let ("positionAfter" ^ name1))]
let res1 = LPE.check_constraint_ok ok res in
if LPE.is_error res1
then
res1
else let h2 = HST.get() in
// assert (B.modifies B.loc_none h1 h2);
// assert (inv1' input.LPL.base h2);
modifies_address_liveness_insensitive_unused_in h1 h2;
// assert (loc_not_unused_in h2 `loc_includes` l1');
// assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res));
let h15 = HST.get () in
let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in
validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1
end | {
"file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 11,
"end_line": 680,
"start_col": 0,
"start_line": 636
} | module EverParse3d.Actions.Base
friend EverParse3d.Kinds
friend EverParse3d.Prelude
open FStar.HyperStack.ST
open LowStar.Buffer
open LowStar.BufferOps
module B = LowStar.Buffer
module I = EverParse3d.InputStream.Base
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
module CP = EverParse3d.CopyBuffer
module AppCtxt = EverParse3d.AppCtxt
module LPE = EverParse3d.ErrorCode
open FStar.Tactics.Typeclasses
open FStar.FunctionalExtensionality
module B = LowStar.Buffer
module U8 = FStar.UInt8
module P = EverParse3d.Prelude
module F = FStar.FunctionalExtensionality
let hinv = HS.mem ^-> prop
let liveness_inv = i:hinv {
forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1
}
let mem_inv = liveness_inv
let slice_inv = mem_inv
let inv_implies (inv0 inv1:slice_inv) =
forall h.
inv0 h ==> inv1 h
let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True)
let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h)
let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l })
let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2
let eloc_none : eloc = B.loc_none
let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True
let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True
let inv_implies_refl inv = ()
let inv_implies_true inv0 = ()
let inv_implies_conj inv0 inv1 inv2 h01 h02 = ()
let conj_inv_true_left_unit i =
FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i
let conj_inv_true_right_unit i =
FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i
let eloc_includes_none l = ()
let eloc_includes_union l0 l1 l2 h01 h02 = ()
let eloc_includes_refl l = ()
let eloc_union_none_left_unit l = ()
let eloc_union_none_right_unit l = ()
let disjointness_pre = prop
let disjointness_trivial = True
let disjoint l1 l2 = eloc_disjoint l1 l2
let conj_disjointness p1 p2 = p1 /\ p2
let imp_disjointness p1 p2 = p1 ==> p2
let disjoint_none_r l =
FStar.PropositionalExtensionality.apply
(disjoint l eloc_none)
(disjointness_trivial)
let disjoint_none_l l =
FStar.PropositionalExtensionality.apply
(disjoint eloc_none l)
(disjointness_trivial)
let conj_disjointness_trivial_left_unit (d:disjointness_pre)
= FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d
let conj_disjointness_trivial_right_unit (d:disjointness_pre)
= FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d
let imp_disjointness_refl (d:disjointness_pre)
= ()
let index_equations ()
= introduce forall d. _
with conj_inv_true_left_unit d;
introduce forall d. _
with conj_inv_true_right_unit d;
introduce forall l. _
with eloc_union_none_right_unit l;
introduce forall l. _
with eloc_union_none_left_unit l;
introduce forall l. _
with disjoint_none_r l;
introduce forall l. _
with disjoint_none_l l;
introduce forall d. _
with conj_disjointness_trivial_left_unit d;
introduce forall d. _
with conj_disjointness_trivial_right_unit d;
introduce forall d. _
with imp_disjointness_refl d;
introduce forall i. _
with inv_implies_refl i;
introduce forall i. _
with inv_implies_true i;
introduce forall i0 i1 i2.
(i0 `inv_implies` i1 /\
i0 `inv_implies` i2) ==>
(i0 `inv_implies` (i1 `conj_inv` i2))
with introduce _ ==> _
with _ . inv_implies_conj i0 i1 i2 () ();
introduce forall l. _
with eloc_includes_none l;
introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\
l0 `eloc_includes` l2) ==>
(l0 `eloc_includes` (l1 `eloc_union` l2))
with introduce _ ==> _
with _ . eloc_includes_union l0 l1 l2 () ();
introduce forall l. _
with eloc_includes_refl l
let bpointer a = B.pointer a
let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x
let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True)
let app_ctxt = AppCtxt.app_ctxt
let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc =
AppCtxt.properties x;
AppCtxt.loc_of x `loc_union` l
inline_for_extraction
noextract
let input_buffer_t = EverParse3d.InputStream.All.t
inline_for_extraction
let error_handler =
typename:string ->
fieldname:string ->
error_reason:string ->
error_code:U64.t ->
ctxt: app_ctxt ->
sl: input_buffer_t ->
pos: LPE.pos_t ->
Stack unit
(requires fun h ->
I.live sl h /\
true_inv h /\
B.live h ctxt /\
loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\
address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\
app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\
U64.v pos <= Seq.length (I.get_read sl h)
)
(ensures fun h0 _ h1 ->
let sl = Ghost.reveal sl in
modifies (app_loc ctxt eloc_none) h0 h1 /\
B.live h1 ctxt /\
true_inv h1)
let action
inv disj l on_success a
= (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) ->
ctxt: app_ctxt ->
error_handler_fn : error_handler ->
sl: input_buffer_t ->
len: I.tlen sl ->
pos: LPE.pos_t ->
posf: LPE.pos_t ->
Stack a
(requires fun h ->
I.live sl h /\
disj /\
inv h /\
B.live h ctxt /\
loc_not_unused_in h `loc_includes` app_loc ctxt l /\
address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\
app_loc ctxt l `loc_disjoint` I.footprint sl /\
U64.v pos <= U64.v posf /\
U64.v posf == Seq.length (I.get_read sl h)
)
(ensures fun h0 _ h1 ->
let sl = Ghost.reveal sl in
modifies (app_loc ctxt l) h0 h1 /\
B.live h1 ctxt /\
inv h1)
module LP = LowParse.Spec.Base
module LPL = LowParse.Low.Base
unfold
let valid_consumed
(#input_buffer_t: Type0)
(# [tcresolve ()] inst : I.input_stream_inst input_buffer_t)
(#k: LP.parser_kind)
(#t: Type)
(p: LP.parser k t)
(h: HS.mem)
(h': HS.mem)
(sl: input_buffer_t)
: Tot prop
= I.live sl h /\
I.live sl h' /\
begin
let s = I.get_remaining sl h in
begin match LP.parse p s with
| None -> False
| Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s)
end
end
unfold
let valid_length
(#input_buffer_t: Type0)
(# [tcresolve ()] inst : I.input_stream_inst input_buffer_t)
(#k: LP.parser_kind)
(#t: Type)
(p: LP.parser k t)
(h: HS.mem)
(sl: input_buffer_t)
(len: int)
: Tot prop
= I.live sl h /\
begin
let s = I.get_remaining sl h in
begin match LP.parse p s with
| None -> False
| Some (_, len') -> len == len'
end
end
let valid
(#input_buffer_t: Type0)
(# [tcresolve ()] inst : I.input_stream_inst input_buffer_t)
(#k: LP.parser_kind)
(#t: Type)
(p: LP.parser k t)
(h: HS.mem)
(sl: input_buffer_t)
: Tot prop
= I.live sl h /\
Some? (LP.parse p (I.get_remaining sl h))
inline_for_extraction noextract
let validate_with_action_t'
(#k:LP.parser_kind)
(#t:Type)
(p:LP.parser k t)
(inv:slice_inv)
(disj:disjointness_pre)
(l:eloc)
(allow_reading:bool)
: Type
= (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) ->
(ctxt: app_ctxt) ->
(error_handler_fn : error_handler) ->
(sl: input_buffer_t) ->
(len: I.tlen sl) ->
(pos: LPE.pos_t) ->
Stack U64.t
(requires fun h ->
I.live sl h /\
disj /\
inv h /\
B.live h ctxt /\
loc_not_unused_in h `loc_includes` app_loc ctxt l /\
address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\
U64.v pos == Seq.length (I.get_read sl h) /\
app_loc ctxt l `loc_disjoint` I.footprint sl
)
(ensures fun h res h' ->
I.live sl h' /\
modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\
inv h' /\
B.live h' ctxt /\
(((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\
begin let s = I.get_remaining sl h in
if LPE.is_success res
then
begin if allow_reading
then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s
else valid_consumed p h h' sl
end
else
let s' = I.get_remaining sl h' in
(LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\
Seq.length s' <= Seq.length s /\
s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s)
end
)
let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading
let validate_eta v =
fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos
let act_with_comment
s res a
=
fun ctxt err sl len pos posf ->
LPL.comment s;
a ctxt err sl len pos posf
let leaf_reader
#nz
#k
(#t: Type)
(p: parser k t)
: Tot Type
=
(# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) ->
(sl: input_buffer_t) ->
(pos: LPE.pos_t) ->
Stack t
(requires (fun h ->
valid p h sl /\
U64.v pos == Seq.length (I.get_read sl h)
))
(ensures (fun h res h' ->
let s = I.get_remaining sl h in
I.live sl h' /\
modifies (I.perm_footprint sl) h h' /\
begin match LP.parse p s with
| None -> False
| Some (y, len) ->
res == y /\
I.get_remaining sl h' == Seq.slice s len (Seq.length s)
end
))
#push-options "--z3rlimit 32"
inline_for_extraction
noextract
let validate_with_success_action'
(name: string)
#nz #wk (#k1:parser_kind nz wk)
#t1 (#p1:parser k1 t1)
(#inv1:_) (#disj1:_) (#l1:eloc)
(v1:validate_with_action_t p1 inv1 disj1 l1 false)
(#inv2:_) (#disj2:_) (#l2:eloc) #b
(a:action inv2 disj2 l2 b bool)
: validate_with_action_t p1
(conj_inv inv1 inv2)
(conj_disjointness disj1 disj2)
(l1 `eloc_union` l2)
false
= fun ctxt error_handler_fn input input_length start_position ->
[@inline_let] let pos0 = start_position in
let h0 = HST.get () in
[@(rename_let ("positionAfter" ^ name))]
let pos1 = v1 ctxt error_handler_fn input input_length pos0 in
let h1 = HST.get () in
modifies_address_liveness_insensitive_unused_in h0 h1;
if LPE.is_success pos1
then
[@(rename_let ("action_success_" ^ name))]
let b = a ctxt error_handler_fn input input_length pos0 pos1 in
let h2 = HST.get () in
modifies_address_liveness_insensitive_unused_in h1 h2;
if not b
then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1
else pos1
else
pos1
inline_for_extraction
noextract
let validate_drop_true
(#k:LP.parser_kind)
(#t:Type)
(#p:LP.parser k t)
(#inv:slice_inv)
(#disj:disjointness_pre)
(#l:eloc)
(v: validate_with_action_t' p inv disj l true)
: Tot (validate_with_action_t' p inv disj l false)
= fun ctxt error_handler_fn input input_length start_position ->
[@inline_let] let pos = start_position in
let res = v ctxt error_handler_fn input input_length pos in
I.skip_if_success input pos res;
res
inline_for_extraction
noextract
let validate_drop
(#k:LP.parser_kind)
(#t:Type)
(#p:LP.parser k t)
(#inv:slice_inv)
(#disj:disjointness_pre)
(#l:eloc)
#allow_reading
(v: validate_with_action_t' p inv disj l allow_reading)
: Tot (validate_with_action_t' p inv disj l false)
= if allow_reading
then validate_drop_true v
else v
let validate_with_success_action
name v1 a
= validate_with_success_action' name (validate_drop v1) a
inline_for_extraction noextract
let validate_with_error_handler
(typename:string)
(fieldname:string)
#nz
#wk
(#k1:parser_kind nz wk)
#t1
(#p1:parser k1 t1)
(#inv1 #disj1:_)
(#l1:eloc)
(#ar:_)
(v1:validate_with_action_t p1 inv1 disj1 l1 ar)
: validate_with_action_t p1 inv1 disj1 l1 ar
= fun ctxt error_handler_fn input input_length start_position ->
[@inline_let] let pos0 = start_position in
let h0 = HST.get () in
[@(rename_let ("positionAfter" ^ typename))]
let pos1 = v1 ctxt error_handler_fn input input_length pos0 in
let h1 = HST.get () in
modifies_address_liveness_insensitive_unused_in h0 h1;
if LPE.is_success pos1
then pos1
else (
error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0;
pos1
)
inline_for_extraction noextract
let validate_ret
: validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true
= fun ctxt error_handler_fn input input_length start_position ->
start_position
#push-options "--z3rlimit 32"
module LPC = LowParse.Spec.Combinators
inline_for_extraction noextract
let validate_pair
(name1: string)
#nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1)
(#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1)
#nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2)
(#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2)
= fun ctxt error_handler_fn input input_length start_position ->
[@inline_let] let pos = start_position in
let h = HST.get () in
LPC.nondep_then_eq p1 p2 (I.get_remaining input h);
[@(rename_let ("positionAfter" ^ name1))]
let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in
let h1 = HST.get () in
modifies_address_liveness_insensitive_unused_in h h1;
if LPE.is_error pos1
then
pos1
else
validate_drop v2 ctxt error_handler_fn input input_length pos1
inline_for_extraction noextract
let validate_dep_pair
(name1: string)
#nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1)
#inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1)
#nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x)))
#inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
= fun ctxt error_handler_fn input input_length start_position ->
[@inline_let] let pos = start_position in
let h = HST.get () in
LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h);
[@(rename_let ("positionAfter" ^ name1))]
let pos1 = v1 ctxt error_handler_fn input input_length pos in
let h1 = HST.get() in
if LPE.is_error pos1
then begin
pos1
end
else
[@(rename_let ("" ^ name1))]
let x = r1 input pos in
let h15 = HST.get () in
let _ = modifies_address_liveness_insensitive_unused_in h h15 in
validate_drop (v2 x) ctxt error_handler_fn input input_length pos1
#pop-options
#push-options "--z3rlimit 64"
#restart-solver
inline_for_extraction noextract
let validate_dep_pair_with_refinement_and_action'
(name1: string)
(#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1)
(#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1)
(f: t1 -> bool)
(#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool)
(#nz2 #wk2: _) (#k2:parser_kind nz2 wk2)
(#t2:refine _ f -> Type)
(#p2:(x:refine _ f) -> parser k2 (t2 x))
(#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
: validate_with_action_t
((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2)
(conj_inv inv1 (conj_inv inv1' inv2))
(conj_disjointness disj1 (conj_disjointness disj1' disj2))
(l1 `eloc_union` (l1' `eloc_union` l2))
false
= fun ctxt error_handler_fn input input_length startPosition ->
let h0 = HST.get () in
LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0);
LPC.parse_filter_eq p1 f (I.get_remaining input h0);
[@(rename_let ("positionAfter" ^ name1))]
let res = v1 ctxt error_handler_fn input input_length startPosition in
let h1 = HST.get() in
modifies_address_liveness_insensitive_unused_in h0 h1;
if LPE.is_error res
then begin
res
end
else begin
assert (I.get_remaining input h1 == I.get_remaining input h0);
[@(rename_let ("" ^ name1))]
let field_value = r1 input startPosition in
[@(rename_let (name1 ^ "ConstraintIsOk"))]
let ok = f field_value in
[@(rename_let ("positionAfter" ^ name1))]
let res1 = LPE.check_constraint_ok ok res in
let h2 = HST.get() in
if LPE.is_error res1
then
res1
else begin
modifies_address_liveness_insensitive_unused_in h1 h2;
if not (a field_value ctxt error_handler_fn input input_length startPosition res1)
then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed
else begin
let h15 = HST.get () in
let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in
validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1
end
end
end
inline_for_extraction noextract
let validate_dep_pair_with_refinement_and_action_total_zero_parser'
(name1: string)
(#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix)
(#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1)
(inv1 disj1 l1: _)
(f: t1 -> bool)
(#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool)
(#nz2 #wk2: _) (#k2:parser_kind nz2 wk2)
(#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x)))
(#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
: Pure (validate_with_action_t
((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2)
(conj_inv inv1 (conj_inv inv1' inv2))
(conj_disjointness disj1 (conj_disjointness disj1' disj2))
(l1 `eloc_union` (l1' `eloc_union` l2))
false)
(requires (
let open LP in
k1.parser_kind_high == Some 0 /\
k1.parser_kind_metadata == Some ParserKindMetadataTotal
))
(ensures (fun _ -> True))
= fun ctxt error_handler_fn input input_length startPosition ->
let h0 = HST.get () in
LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0);
LPC.parse_filter_eq p1 f (I.get_remaining input h0);
[@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in
begin
LowStar.Comment.comment ("Validating field " ^ name1);
[@(rename_let ("" ^ name1))]
let field_value = r1 input startPosition in
[@(rename_let (name1 ^ "ConstraintIsOk"))]
let ok = f field_value in
[@(rename_let ("positionAfter" ^ name1))]
let res1 = LPE.check_constraint_ok ok startPosition in
if LPE.is_error res1
then
res1
else let h2 = HST.get() in
modifies_address_liveness_insensitive_unused_in h0 h2;
if not (a field_value ctxt error_handler_fn input input_length startPosition res1)
then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed
else begin
let h15 = HST.get () in
let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in
validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1
end
end
inline_for_extraction noextract
let validate_dep_pair_with_refinement_and_action
(p1_is_constant_size_without_actions: bool)
(name1: string)
#nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1)
#inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true)
(r1: leaf_reader p1)
(f: t1 -> bool)
#inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool)
#nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x)))
#inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
= if
p1_is_constant_size_without_actions `LP.bool_and`
(k1.LP.parser_kind_high = Some 0) `LP.bool_and`
(k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal)
then
validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2
else
validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2
inline_for_extraction noextract
let validate_dep_pair_with_action
#nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1)
#inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1)
#inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool)
#nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x)))
#inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
= fun ctxt error_handler_fn input input_length startPosition ->
let h0 = HST.get () in
LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0);
let res = v1 ctxt error_handler_fn input input_length startPosition in
let h1 = HST.get() in
modifies_address_liveness_insensitive_unused_in h0 h1;
if LPE.is_error res
then begin
res
end
else begin
let field_value = r1 input startPosition in
let h2 = HST.get() in
modifies_address_liveness_insensitive_unused_in h1 h2;
let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in
let h3 = HST.get () in
modifies_address_liveness_insensitive_unused_in h2 h3;
if not action_result
then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed
else
validate_drop (v2 field_value) ctxt error_handler_fn input input_length res
end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Comment.fsti.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.FLData.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"LowParse.Low.ListUpTo.fst.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.BoundedInt.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Seq.fst.checked",
"FStar.PropositionalExtensionality.fst.checked",
"FStar.PredicateExtensionality.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.FunctionalExtensionality.fsti.checked",
"FStar.Classical.Sugar.fsti.checked",
"FStar.Classical.fsti.checked",
"EverParse3d.Util.fst.checked",
"EverParse3d.Prelude.fst.checked",
"EverParse3d.Kinds.fst.checked",
"EverParse3d.InputStream.Base.fst.checked",
"EverParse3d.InputStream.All.fsti.checked",
"EverParse3d.ErrorCode.fst.checked",
"EverParse3d.CopyBuffer.fsti.checked",
"EverParse3d.AppCtxt.fsti.checked",
"C.Loops.fst.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Actions.Base.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Low.Base",
"short_module": "LPL"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": true,
"full_module": "FStar.FunctionalExtensionality",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "EverParse3d.Prelude",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.UInt8",
"short_module": "U8"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.FunctionalExtensionality",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Typeclasses",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverParse3d.ErrorCode",
"short_module": "LPE"
},
{
"abbrev": true,
"full_module": "EverParse3d.AppCtxt",
"short_module": "AppCtxt"
},
{
"abbrev": true,
"full_module": "EverParse3d.CopyBuffer",
"short_module": "CP"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "EverParse3d.InputStream.Base",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "EverParse3d.CopyBuffer",
"short_module": "CP"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "EverParse3d.Prelude",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Int.Cast",
"short_module": "Cast"
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d.Actions",
"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": 2,
"max_fuel": 0,
"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": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 64,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
name1: Prims.string ->
v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 true ->
r1: EverParse3d.Actions.Base.leaf_reader p1 ->
f: (_: t1 -> Prims.bool) ->
v2:
(x: EverParse3d.Prelude.refine t1 f
-> EverParse3d.Actions.Base.validate_with_action_t (p2 x) inv2 disj2 l2 ar2)
-> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (LowParse.Spec.Combinators.parse_filter
p1
f)
p2)
(EverParse3d.Actions.Base.conj_inv inv1 inv2)
(EverParse3d.Actions.Base.conj_disjointness disj1 disj2)
(EverParse3d.Actions.Base.eloc_union l1 l2)
false | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.bool",
"EverParse3d.Kinds.parser_kind",
"EverParse3d.Kinds.WeakKindStrongPrefix",
"EverParse3d.Prelude.parser",
"EverParse3d.Actions.Base.slice_inv",
"EverParse3d.Actions.Base.disjointness_pre",
"EverParse3d.Actions.Base.eloc",
"EverParse3d.Actions.Base.validate_with_action_t",
"EverParse3d.Actions.Base.leaf_reader",
"EverParse3d.Kinds.weak_kind",
"EverParse3d.Prelude.refine",
"EverParse3d.InputStream.Base.extra_t",
"EverParse3d.Actions.Base.input_buffer_t",
"EverParse3d.InputStream.All.inst",
"EverParse3d.Actions.Base.app_ctxt",
"EverParse3d.Actions.Base.error_handler",
"EverParse3d.InputStream.Base.tlen",
"EverParse3d.ErrorCode.pos_t",
"EverParse3d.ErrorCode.is_error",
"FStar.UInt64.t",
"EverParse3d.Actions.Base.validate_drop",
"Prims.unit",
"LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"EverParse3d.ErrorCode.check_constraint_ok",
"LowParse.Spec.Combinators.parse_filter_eq",
"EverParse3d.InputStream.Base.get_remaining",
"LowParse.Spec.Combinators.parse_dtuple2_eq'",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"Prims.op_BarBar",
"EverParse3d.Kinds.and_then_kind",
"Prims.dtuple2",
"EverParse3d.Prelude.parse_dep_pair",
"EverParse3d.Actions.Base.conj_inv",
"EverParse3d.Actions.Base.conj_disjointness",
"EverParse3d.Actions.Base.eloc_union"
] | [] | false | false | false | false | false | let validate_dep_pair_with_refinement'
(name1: string)
#nz1
(#k1: parser_kind nz1 _)
#t1
(#p1: parser k1 t1)
#inv1
#disj1
#l1
(v1: validate_with_action_t p1 inv1 disj1 l1 true)
(r1: leaf_reader p1)
(f: (t1 -> bool))
#nz2
#wk2
(#k2: parser_kind nz2 wk2)
(#t2: (refine _ f -> Type))
(#p2: (x: refine _ f -> parser k2 (t2 x)))
#inv2
#disj2
#l2
#ar2
(v2: (x: refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2))
: Tot
(validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2)
(conj_inv inv1 inv2)
(conj_disjointness disj1 disj2)
(l1 `eloc_union` l2)
false) =
| fun ctxt error_handler_fn input input_length startPosition ->
let h0 = HST.get () in
LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0);
LPC.parse_filter_eq p1 f (I.get_remaining input h0);
[@@ (rename_let ("positionAfter" ^ name1)) ]let res =
v1 ctxt error_handler_fn input input_length startPosition
in
let h1 = HST.get () in
modifies_address_liveness_insensitive_unused_in h0 h1;
if LPE.is_error res
then res
else
[@@ (rename_let ("" ^ name1)) ]let field_value = r1 input startPosition in
[@@ (rename_let (name1 ^ "ConstraintIsOk")) ]let ok = f field_value in
[@@ (rename_let ("positionAfter" ^ name1)) ]let res1 = LPE.check_constraint_ok ok res in
if LPE.is_error res1
then res1
else
let h2 = HST.get () in
modifies_address_liveness_insensitive_unused_in h1 h2;
let h15 = HST.get () in
let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in
validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 | false |
BinarySearchTree0.fst | BinarySearchTree0.search | val search : int -> tree -> bool | val search : int -> tree -> bool | let rec search x t =
match t with
| Leaf -> false
| Node n t1 t2 -> if x = n then true
else if x < n then search x t1
else search x t2 | {
"file_name": "examples/data_structures/BinarySearchTree0.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 50,
"end_line": 28,
"start_col": 0,
"start_line": 23
} | (*
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 BinarySearchTree0
type tree =
| Leaf : tree
| Node : int -> tree -> tree -> tree | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "BinarySearchTree0.fst"
} | [
{
"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: Prims.int -> t: BinarySearchTree0.tree -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"BinarySearchTree0.tree",
"Prims.op_Equality",
"Prims.bool",
"Prims.op_LessThan",
"BinarySearchTree0.search"
] | [
"recursion"
] | false | false | false | true | false | let rec search x t =
| match t with
| Leaf -> false
| Node n t1 t2 -> if x = n then true else if x < n then search x t1 else search x t2 | false |
Lens.fst | Lens.st | val st (#a #b: _) (l: lens a b) : stlens l | val st (#a #b: _) (l: lens a b) : stlens l | let st #a #b (l:lens a b) : stlens l = {
st_get = (fun (r:ref a) -> (!r).[l]);
st_put = (fun (x:b) (r:ref a) -> r := (!r.[l] <- x); r)
} | {
"file_name": "examples/data_structures/Lens.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 1,
"end_line": 206,
"start_col": 0,
"start_line": 203
} | (*
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.
*)
/// A small experiment with lenses, including stateful lenses toward
/// the end.
///
/// Part of what I'm experimenting with is how to shoehorn this into
/// the existing notational support in F*.
module Lens
let ignore (x:'a) : unit = ()
/// A `lens a b` focuses on the `b` component of `a`
/// It provides a `get` to access the component
/// And a `set` to update and `a` by updating its `b` component
noeq
type lens (a:Type) (b:Type) = {
get: a -> b;
put: b -> a -> a
}
/// `x |. l` : projects using the lens `l` from `x`
let ( |. ) (x:'a) (l:lens 'a 'b) : 'b = l.get x
/// `(x |:= l) v` : updates the `l`-focused component of `x` with `v`
/// – The additional parentheses on the left are necesssary here
let ( |:= ) (x:'a) (l:lens 'a 'b) : 'b -> 'a = fun b -> l.put b x
/// `l |.. m`: composes lenses, building an "access path" that extends
/// the focus of `l` with `m`
let ( |.. ) (m:lens 'a 'b) (l:lens 'b 'c) : lens 'a 'c = {
get = (fun x -> l.get (m.get x));
put = (fun (x:'c) (y:'a) -> m.put (l.put x (m.get y)) y)
}
(* Using these operators provides slightly better notation *)
/// `x.[l] <- v`: updates the l-focused component of x with v
let op_String_Assignment (x:'a) (l:lens 'a 'b) (v:'b) : 'a = (x |:= l) v
/// `x.[l]`: accesses the l-focused component
let op_String_Access (x:'a) (l:lens 'a 'b) : 'b = x |. l
(** Now for some pure examples **)
/// A simple 3d point defined as a record
type point = {
x:int;
y:int;
z:int
}
/// Followed by bit of boilerplate (which would be nice to metaprogram)
/// to define lenses for each of its components
let x : lens point int = {
get = (fun p -> p.x);
put = (fun x' p -> {p with x=x'})
}
let y : lens point int = {
get = (fun p -> p.y);
put = (fun y' p -> {p with y=y'})
}
let z : lens point int = {
get = (fun p -> p.z);
put = (fun z' p -> {p with z=z'})
}
/// A circle is a point and a radius
type circle = {
center: point;
radius: nat
}
/// Again, a bit of boiler plate for lenses on its fields
let center : lens circle point = {
get = (fun c -> c.center);
put = (fun n c -> {c with center = n})
}
let radius : lens circle nat= {
get = (fun c -> c.radius);
put = (fun n c -> {c with radius = n})
}
(** Now some clients that use the lenses **)
let getY (c:circle) = c |. center |. y
/// Or, using the accessor notation
let getY' (c:circle) = c.[center |.. y]
/// Or, of course, using the built-in notation
/// ...
/// So,this doesn't look like much progress so far : )
let getY'' (c:circle) = c.center.y
/// But, updating a nested record is somewhat easier now
let setY (c:circle) (new_y: int) =
c.[center |.. y] <- new_y
/// As opposed to:
let tedious_setY (c:circle) (new_y: int) =
{c with center = {c.center with y = new_y}}
/// You can mix accessors and mutators
let moveUp (c:circle) (offset_y: int) =
c.[center |.. y] <- c.[center |.. y] + offset_y
(** Now lets add more layers of objects **)
/// Here's an RGB color
type rgb = {
red:nat;
green:nat;
blue:nat;
}
/// Boilerplate
let red : lens rgb nat = {
get = (fun p -> p.red);
put = (fun z p -> {p with red=z})
}
let green : lens rgb nat = {
get = (fun p -> p.green);
put = (fun z p -> {p with green=z})
}
let blue : lens rgb nat = {
get = (fun p -> p.blue);
put = (fun z p -> {p with blue=z})
}
/// And a `colored a` is a `color` and an `a`
type colored (a:Type) = {
color:rgb;
payload:a
}
/// Boilerplate
let color (#a:Type) : lens (colored a) rgb = {
get = (fun p -> p.color);
put = (fun z p -> {p with color=z})
}
let payload (#a:Type) : lens (colored a) a = {
get = (fun p -> p.payload);
put = (fun z p -> {p with payload=z})
}
/// And you can build longer lenses to reach into an object quite easily
let moveUp' (c:colored circle) (offset_y: int) =
c.[payload |.. center |.. y] <- c.[payload |.. center |.. y] + offset_y
/// You can also build other kinds of lens combinator
/// For example, focusing on two different parts of an object at once
let ( || ) (l1:lens 'a 'b) (l2:lens 'a 'c) : lens 'a ('b * 'c) = {
get = (fun a -> l1.get a, l2.get a);
put = (fun (b, c) a -> l2.put c (l1.put b a))
}
/// And now you can use these to update multiple components at once
let makeGreen (c:colored circle) =
c.[color |.. (red || green || blue )] <- (0, 1), 0
////////////////////////////////////////////////////////////////////////////////
/// Now for some stateful stuff
/// – This is not quite as nice an compositional as before
/// Would be curious to have your thoughts on how it could be generalized
/// (My first naive attempt: See StatefulLens for how to do it better)
////////////////////////////////////////////////////////////////////////////////
open FStar.Heap
open FStar.Ref
/// An `stlens #a #b l` goes via a `ref a` to access the `b`component
/// that is focused by `l`
noeq
type stlens (#a:Type) (#b:Type) (l:lens a b) = {
// Getting a `b` from an `r:ref a` requires dereferencing it
// and then reaching into the result with `l`
st_get: r:ref a
-> ST b
(requires (fun h -> True))
(ensures (fun h0 b h1 -> h0==h1 /\ b == ((sel h1 r)|. l)));
// Setting a `b` component inside a `r:ref a` modifies only `r`
// and updates the contents of `r` using `l`
st_put: y:b
-> r:ref a
-> ST (ref a)
(requires (fun h -> True))
(ensures (fun h0 s h1 ->
r == s /\
modifies (Set.singleton (addr_of r)) h0 h1 /\
(sel h1 r == ((sel h0 r).[l] <- y))))
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Set.fsti.checked",
"FStar.Ref.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Heap.fst.checked"
],
"interface_file": false,
"source_file": "Lens.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Ref",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Heap",
"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 | l: Lens.lens a b -> Lens.stlens l | Prims.Tot | [
"total"
] | [] | [
"Lens.lens",
"Lens.Mkstlens",
"FStar.ST.ref",
"Lens.op_String_Access",
"FStar.Ref.op_Bang",
"Prims.unit",
"FStar.Ref.op_Colon_Equals",
"Lens.op_String_Assignment",
"Lens.stlens"
] | [] | false | false | false | false | false | let st #a #b (l: lens a b) : stlens l =
| {
st_get = (fun (r: ref a) -> (!r).[ l ]);
st_put
=
(fun (x: b) (r: ref a) ->
r := (!r.[ l ] <- x);
r)
} | false |
BinarySearchTree0.fst | BinarySearchTree0.insert | val insert : int -> tree -> tree | val insert : int -> tree -> tree | let rec insert x t =
match t with
| Leaf -> Node x Leaf Leaf
| Node n t1 t2 -> if x = n then t
else if x < n then Node n (insert x t1) t2
else Node n t1 (insert x t2) | {
"file_name": "examples/data_structures/BinarySearchTree0.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 62,
"end_line": 36,
"start_col": 0,
"start_line": 31
} | (*
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 BinarySearchTree0
type tree =
| Leaf : tree
| Node : int -> tree -> tree -> tree
val search : int -> tree -> bool
let rec search x t =
match t with
| Leaf -> false
| Node n t1 t2 -> if x = n then true
else if x < n then search x t1
else search x t2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "BinarySearchTree0.fst"
} | [
{
"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: Prims.int -> t: BinarySearchTree0.tree -> BinarySearchTree0.tree | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"BinarySearchTree0.tree",
"BinarySearchTree0.Node",
"BinarySearchTree0.Leaf",
"Prims.op_Equality",
"Prims.bool",
"Prims.op_LessThan",
"BinarySearchTree0.insert"
] | [
"recursion"
] | false | false | false | true | false | let rec insert x t =
| match t with
| Leaf -> Node x Leaf Leaf
| Node n t1 t2 ->
if x = n then t else if x < n then Node n (insert x t1) t2 else Node n t1 (insert x t2) | false |
Hacl.Hash.MD5.fst | Hacl.Hash.MD5.update_last | val update_last: update_last_st (|MD5, ()|) | val update_last: update_last_st (|MD5, ()|) | let update_last: update_last_st (|MD5, ()|) =
Hacl.Hash.MD.mk_update_last MD5 update_multi pad | {
"file_name": "code/hash/Hacl.Hash.MD5.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 14,
"start_col": 0,
"start_line": 13
} | module Hacl.Hash.MD5
open Hacl.Hash.Definitions
open Spec.Hash.Definitions
include Hacl.Hash.Core.MD5
friend Hacl.Hash.MD
let update_multi: update_multi_st (|MD5, ()|) =
Hacl.Hash.MD.mk_update_multi MD5 update | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Hacl.Hash.MD.fst.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Core.MD5.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Hash.MD5.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Hash.Core.MD5",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Hash.Definitions.update_last_st (| Spec.Hash.Definitions.MD5, () |) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.MD.mk_update_last",
"Spec.Hash.Definitions.MD5",
"Hacl.Hash.MD5.update_multi",
"Hacl.Hash.Core.MD5.pad",
"Hacl.Hash.Definitions.update_last_st",
"Prims.Mkdtuple2",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.m_spec"
] | [] | false | false | false | false | false | let update_last:update_last_st (| MD5, () |) =
| Hacl.Hash.MD.mk_update_last MD5 update_multi pad | false |
Hacl.Hash.MD5.fst | Hacl.Hash.MD5.update_multi | val update_multi: update_multi_st (|MD5, ()|) | val update_multi: update_multi_st (|MD5, ()|) | let update_multi: update_multi_st (|MD5, ()|) =
Hacl.Hash.MD.mk_update_multi MD5 update | {
"file_name": "code/hash/Hacl.Hash.MD5.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 11,
"start_col": 0,
"start_line": 10
} | module Hacl.Hash.MD5
open Hacl.Hash.Definitions
open Spec.Hash.Definitions
include Hacl.Hash.Core.MD5
friend Hacl.Hash.MD | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Hacl.Hash.MD.fst.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Core.MD5.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Hash.MD5.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Hash.Core.MD5",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Hash.Definitions.update_multi_st (| Spec.Hash.Definitions.MD5, () |) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.MD.mk_update_multi",
"Spec.Hash.Definitions.MD5",
"Hacl.Hash.Core.MD5.update",
"Hacl.Hash.Definitions.update_multi_st",
"Prims.Mkdtuple2",
"Spec.Hash.Definitions.hash_alg",
"Hacl.Hash.Definitions.m_spec"
] | [] | false | false | false | false | false | let update_multi:update_multi_st (| MD5, () |) =
| Hacl.Hash.MD.mk_update_multi MD5 update | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_round | val eval_round : state: Vale.Def.Types_s.quad32 -> round_key: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 37,
"start_col": 0,
"start_line": 32
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s} | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | state: Vale.Def.Types_s.quad32 -> round_key: Vale.Def.Types_s.quad32 -> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.quad32_xor",
"Vale.AES.AES_BE_s.mix_columns",
"Vale.AES.AES_BE_s.shift_rows",
"Vale.AES.AES_common_s.sub_bytes"
] | [] | false | false | false | true | false | let eval_round (state round_key: quad32) =
| let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_rounds | val eval_rounds : _: Vale.Def.Types_s.quad32 ->
_: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
_: n: Prims.nat{n < FStar.Seq.Base.length _}
-> Vale.Def.Types_s.quad32 | let eval_rounds = opaque_make eval_rounds_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 44,
"start_col": 19,
"start_line": 44
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
_: Vale.Def.Types_s.quad32 ->
_: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
_: n: Prims.nat{n < FStar.Seq.Base.length _}
-> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.eval_rounds_def"
] | [] | false | false | false | false | false | let eval_rounds =
| opaque_make eval_rounds_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.is_aes_key_word | val is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0 | val is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0 | let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 29,
"start_col": 0,
"start_line": 29
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | alg: Vale.AES.AES_common_s.algorithm -> s: FStar.Seq.Base.seq Vale.Def.Types_s.nat32
-> Vale.Def.Prop_s.prop0 | Prims.Tot | [
"total"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.AES.AES_common_s.nk",
"Vale.Def.Prop_s.prop0"
] | [] | false | false | false | true | false | let is_aes_key_word (alg: algorithm) (s: seq nat32) : prop0 =
| length s == nk alg | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_rounds_reveal | val eval_rounds_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_rounds == Vale.AES.AES_BE_s.eval_rounds_def) | let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 45,
"start_col": 12,
"start_line": 45
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_rounds == Vale.AES.AES_BE_s.eval_rounds_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.eval_rounds",
"Vale.AES.AES_BE_s.eval_rounds_def"
] | [] | true | false | true | false | false | let eval_rounds_reveal =
| opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_cipher_reveal | val eval_cipher_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_cipher == Vale.AES.AES_BE_s.eval_cipher_def) | let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 96,
"end_line": 58,
"start_col": 12,
"start_line": 58
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.eval_cipher == Vale.AES.AES_BE_s.eval_cipher_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Prims.l_True",
"Vale.AES.AES_BE_s.eval_cipher",
"Vale.AES.AES_BE_s.eval_cipher_def"
] | [] | true | false | true | false | false | let eval_cipher_reveal =
| opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_cipher | val eval_cipher : alg: Vale.AES.AES_common_s.algorithm ->
input: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | let eval_cipher = opaque_make eval_cipher_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 57,
"start_col": 19,
"start_line": 57
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
input: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | Prims.Pure | [] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Prims.l_True",
"Vale.AES.AES_BE_s.eval_cipher_def"
] | [] | false | false | false | false | false | let eval_cipher =
| opaque_make eval_cipher_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.expand_key | val expand_key : _: Vale.AES.AES_common_s.algorithm ->
_: Vale.AES.AES_BE_s.aes_key_word _ ->
_: size: Prims.nat{size <= Vale.AES.AES_common_s.nb * (Vale.AES.AES_common_s.nr _ + 1)}
-> ek: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length ek == _} | let expand_key = opaque_make expand_key_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 78,
"start_col": 19,
"start_line": 78
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
_: Vale.AES.AES_common_s.algorithm ->
_: Vale.AES.AES_BE_s.aes_key_word _ ->
_: size: Prims.nat{size <= Vale.AES.AES_common_s.nb * (Vale.AES.AES_common_s.nr _ + 1)}
-> ek: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length ek == _} | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.eq2",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.expand_key_def"
] | [] | false | false | false | false | false | let expand_key =
| opaque_make expand_key_def | false |
|
Steel.Semantics.Instantiate.fst | Steel.Semantics.Instantiate.is_unit | val is_unit: Prims.unit -> Lemma (S.is_unit emp equiv star) | val is_unit: Prims.unit -> Lemma (S.is_unit emp equiv star) | let is_unit ()
: Lemma (S.is_unit emp equiv star)
= let aux (y:slprop)
: Lemma (star emp y `equiv` y /\ star y emp `equiv` y)
= emp_unit y; star_commutative emp y
in
Classical.forall_intro aux | {
"file_name": "lib/steel/Steel.Semantics.Instantiate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 30,
"end_line": 27,
"start_col": 0,
"start_line": 21
} | (*
Copyright 2020 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 Steel.Semantics.Instantiate
open Steel.Memory
module S = Steel.Semantics.Hoare.MST | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Semantics.Instantiate.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"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 | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Steel.Semantics.Hoare.MST.is_unit Steel.Memory.emp Steel.Memory.equiv Steel.Memory.star
) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro",
"Steel.Memory.slprop",
"Prims.l_and",
"Steel.Memory.equiv",
"Steel.Memory.star",
"Steel.Memory.emp",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Steel.Memory.star_commutative",
"Steel.Memory.emp_unit",
"Steel.Semantics.Hoare.MST.is_unit"
] | [] | false | false | true | false | false | let is_unit () : Lemma (S.is_unit emp equiv star) =
| let aux (y: slprop) : Lemma ((star emp y) `equiv` y /\ (star y emp) `equiv` y) =
emp_unit y;
star_commutative emp y
in
Classical.forall_intro aux | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.expand_key_reveal | val expand_key_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.expand_key == Vale.AES.AES_BE_s.expand_key_def) | let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 79,
"start_col": 12,
"start_line": 79
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp)) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.expand_key == Vale.AES.AES_BE_s.expand_key_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.eq2",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.expand_key",
"Vale.AES.AES_BE_s.expand_key_def"
] | [] | true | false | true | false | false | let expand_key_reveal =
| opaque_revealer (`%expand_key) expand_key expand_key_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_cipher_def | val eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True) | val eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True) | let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 56,
"start_col": 0,
"start_line": 47
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
input: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | Prims.Pure | [] | [] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32_xor",
"FStar.Seq.Base.index",
"Vale.AES.AES_common_s.nr",
"Vale.AES.AES_BE_s.shift_rows",
"Vale.AES.AES_common_s.sub_bytes",
"Vale.AES.AES_BE_s.eval_rounds_def",
"Prims.op_Subtraction",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"Prims.l_True"
] | [] | false | false | false | false | false | let eval_cipher_def (alg: algorithm) (input: quad32) (round_keys: seq quad32)
: Pure quad32 (requires length round_keys == nr alg + 1) (ensures fun _ -> True) =
| let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.aes_encrypt_word_reveal | val aes_encrypt_word_reveal : _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.aes_encrypt_word == Vale.AES.AES_BE_s.aes_encrypt_word_def) | let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 116,
"end_line": 102,
"start_col": 12,
"start_line": 102
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures Vale.AES.AES_BE_s.aes_encrypt_word == Vale.AES.AES_BE_s.aes_encrypt_word_def) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Opaque_s.opaque_revealer",
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.AES.AES_BE_s.aes_encrypt_word_def"
] | [] | true | false | true | false | false | let aes_encrypt_word_reveal =
| opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.aes_encrypt_word | val aes_encrypt_word : alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
input: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | let aes_encrypt_word = opaque_make aes_encrypt_word_def | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 101,
"start_col": 19,
"start_line": 101
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
= | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
input: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | Prims.Pure | [] | [] | [
"Vale.Def.Opaque_s.opaque_make",
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True",
"Vale.AES.AES_BE_s.aes_encrypt_word_def"
] | [] | false | false | false | false | false | let aes_encrypt_word =
| opaque_make aes_encrypt_word_def | false |
|
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.eval_rounds_def | val eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys}) : quad32 | val eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys}) : quad32 | let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 43,
"start_col": 0,
"start_line": 39
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
init: Vale.Def.Types_s.quad32 ->
round_keys: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
n: Prims.nat{n < FStar.Seq.Base.length round_keys}
-> Vale.Def.Types_s.quad32 | Prims.Tot | [
"total"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Seq.Base.length",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Vale.AES.AES_BE_s.eval_round",
"Vale.AES.AES_BE_s.eval_rounds_def",
"Prims.op_Subtraction",
"FStar.Seq.Base.index"
] | [
"recursion"
] | false | false | false | false | false | let rec eval_rounds_def (init: quad32) (round_keys: seq quad32) (n: nat{n < length round_keys})
: quad32 =
| if n = 0 then init else eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n) | false |
Steel.Semantics.Instantiate.fst | Steel.Semantics.Instantiate.state_obeys_st_laws | val state_obeys_st_laws (uses:inames)
: Lemma (S.st_laws (state0 uses)) | val state_obeys_st_laws (uses:inames)
: Lemma (S.st_laws (state0 uses)) | let state_obeys_st_laws uses =
Classical.forall_intro_3 star_associative;
Classical.forall_intro_2 star_commutative;
is_unit ();
FStar.Classical.forall_intro_3 disjoint_join;
let aux (m0 m1:mem)
: Lemma (requires disjoint m0 m1)
(ensures join m0 m1 == join m1 m0)
[SMTPat (disjoint m0 m1)]
= join_commutative m0 m1
in
let aux (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
[SMTPat (disjoint m0 (join m1 m2))]
= join_associative m0 m1 m2
in
let aux (p1 p2 p3:slprop)
: Lemma (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
[SMTPat ()]
= equiv_extensional_on_star p1 p2 p3
in
() | {
"file_name": "lib/steel/Steel.Semantics.Instantiate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 4,
"end_line": 57,
"start_col": 0,
"start_line": 30
} | (*
Copyright 2020 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 Steel.Semantics.Instantiate
open Steel.Memory
module S = Steel.Semantics.Hoare.MST
let is_unit ()
: Lemma (S.is_unit emp equiv star)
= let aux (y:slprop)
: Lemma (star emp y `equiv` y /\ star y emp `equiv` y)
= emp_unit y; star_commutative emp y
in
Classical.forall_intro aux | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Semantics.Instantiate.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"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 | uses: Steel.Memory.inames
-> FStar.Pervasives.Lemma
(ensures Steel.Semantics.Hoare.MST.st_laws (Steel.Semantics.Instantiate.state0 uses)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Memory.inames",
"Steel.Memory.slprop",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Steel.Memory.equiv",
"Steel.Memory.star",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil",
"Steel.Memory.equiv_extensional_on_star",
"Steel.Memory.mem",
"Prims.l_and",
"Steel.Memory.disjoint",
"Steel.Memory.join",
"Prims.eq2",
"Prims.prop",
"Steel.Memory.join_associative",
"Steel.Memory.disjoint_join",
"Steel.Memory.join_commutative",
"FStar.Classical.forall_intro_3",
"Steel.Semantics.Instantiate.is_unit",
"FStar.Classical.forall_intro_2",
"Steel.Memory.star_commutative",
"Steel.Memory.star_associative"
] | [] | false | false | true | false | false | let state_obeys_st_laws uses =
| Classical.forall_intro_3 star_associative;
Classical.forall_intro_2 star_commutative;
is_unit ();
FStar.Classical.forall_intro_3 disjoint_join;
let aux (m0 m1: mem)
: Lemma (requires disjoint m0 m1) (ensures join m0 m1 == join m1 m0) [SMTPat (disjoint m0 m1)] =
join_commutative m0 m1
in
let aux (m0 m1 m2: mem)
: Lemma (requires disjoint m1 m2 /\ disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
[SMTPat (disjoint m0 (join m1 m2))] =
join_associative m0 m1 m2
in
let aux (p1 p2 p3: slprop)
: Lemma (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3)) [SMTPat ()] =
equiv_extensional_on_star p1 p2 p3
in
() | false |
Steel.Semantics.Instantiate.fst | Steel.Semantics.Instantiate.state_correspondence | val state_correspondence (inames:inames)
: Lemma
(let s = state_uses inames in
s.S.hprop == slprop /\
s.S.mem == mem /\
s.S.interp == interp /\
s.S.star == star /\
s.S.locks_invariant == locks_invariant inames /\
(forall (p q frame:slprop)
(m0:mem{interp (p `star` frame `star` locks_invariant inames m0) m0})
(m1:mem{interp (q `star` frame `star` locks_invariant inames m1) m1}).
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)) ==>
S.post_preserves_frame #s q frame m0 m1)) | val state_correspondence (inames:inames)
: Lemma
(let s = state_uses inames in
s.S.hprop == slprop /\
s.S.mem == mem /\
s.S.interp == interp /\
s.S.star == star /\
s.S.locks_invariant == locks_invariant inames /\
(forall (p q frame:slprop)
(m0:mem{interp (p `star` frame `star` locks_invariant inames m0) m0})
(m1:mem{interp (q `star` frame `star` locks_invariant inames m1) m1}).
(forall (f_frame:mprop frame). f_frame (core_mem m0) == f_frame (core_mem m1)) ==>
S.post_preserves_frame #s q frame m0 m1)) | let state_correspondence inames =
let s = state_uses inames in
assert_norm (s.S.hprop == slprop) ;
assert_norm (s.S.mem == mem) ;
assert_norm (s.S.interp == interp);
assert_norm (s.S.star == star);
assert_norm (s.S.locks_invariant == locks_invariant inames) | {
"file_name": "lib/steel/Steel.Semantics.Instantiate.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 63,
"end_line": 66,
"start_col": 0,
"start_line": 60
} | (*
Copyright 2020 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 Steel.Semantics.Instantiate
open Steel.Memory
module S = Steel.Semantics.Hoare.MST
let is_unit ()
: Lemma (S.is_unit emp equiv star)
= let aux (y:slprop)
: Lemma (star emp y `equiv` y /\ star y emp `equiv` y)
= emp_unit y; star_commutative emp y
in
Classical.forall_intro aux
#push-options "--warn_error -271"
let state_obeys_st_laws uses =
Classical.forall_intro_3 star_associative;
Classical.forall_intro_2 star_commutative;
is_unit ();
FStar.Classical.forall_intro_3 disjoint_join;
let aux (m0 m1:mem)
: Lemma (requires disjoint m0 m1)
(ensures join m0 m1 == join m1 m0)
[SMTPat (disjoint m0 m1)]
= join_commutative m0 m1
in
let aux (m0 m1 m2:mem)
: Lemma
(requires
disjoint m1 m2 /\
disjoint m0 (join m1 m2))
(ensures
(disjoint_join m0 m1 m2;
join m0 (join m1 m2) == join (join m0 m1) m2))
[SMTPat (disjoint m0 (join m1 m2))]
= join_associative m0 m1 m2
in
let aux (p1 p2 p3:slprop)
: Lemma (p1 `equiv` p2 ==> (p1 `star` p3) `equiv` (p2 `star` p3))
[SMTPat ()]
= equiv_extensional_on_star p1 p2 p3
in
()
#pop-options | {
"checked_file": "/",
"dependencies": [
"Steel.Semantics.Hoare.MST.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.Semantics.Instantiate.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": true,
"full_module": "Steel.Semantics.Hoare.MST",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Semantics",
"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 | inames: Steel.Memory.inames
-> FStar.Pervasives.Lemma
(ensures
(let s = Steel.Semantics.Instantiate.state_uses inames in
Mkst0?.hprop s == Steel.Memory.slprop /\ Mkst0?.mem s == Steel.Memory.mem /\
Mkst0?.interp s == Steel.Memory.interp /\ Mkst0?.star s == Steel.Memory.star /\
Mkst0?.locks_invariant s == Steel.Memory.locks_invariant inames /\
(forall (p: Steel.Memory.slprop)
(q: Steel.Memory.slprop)
(frame: Steel.Memory.slprop)
(m0:
Steel.Memory.mem
{ Steel.Memory.interp (Steel.Memory.star (Steel.Memory.star p frame)
(Steel.Memory.locks_invariant inames m0))
m0 })
(m1:
Steel.Memory.mem
{ Steel.Memory.interp (Steel.Memory.star (Steel.Memory.star q frame)
(Steel.Memory.locks_invariant inames m1))
m1 }).
(forall (f_frame: Steel.Memory.mprop frame).
f_frame (Steel.Memory.core_mem m0) == f_frame (Steel.Memory.core_mem m1)) ==>
Steel.Semantics.Hoare.MST.post_preserves_frame q frame m0 m1))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Steel.Memory.inames",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__mem",
"Steel.Memory.slprop",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__locks_invariant",
"Steel.Memory.locks_invariant",
"Prims.unit",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__hprop",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__star",
"Steel.Memory.star",
"Steel.Memory.mem",
"Prims.prop",
"Steel.Semantics.Hoare.MST.__proj__Mkst0__item__interp",
"Steel.Memory.interp",
"Steel.Semantics.Hoare.MST.st",
"Steel.Semantics.Instantiate.state_uses"
] | [] | true | false | true | false | false | let state_correspondence inames =
| let s = state_uses inames in
assert_norm (s.S.hprop == slprop);
assert_norm (s.S.mem == mem);
assert_norm (s.S.interp == interp);
assert_norm (s.S.star == star);
assert_norm (s.S.locks_invariant == locks_invariant inames) | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.expand_key_def | val expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size}) | val expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size}) | let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp)) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 77,
"start_col": 0,
"start_line": 60
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: Vale.AES.AES_BE_s.aes_key_word alg ->
size: Prims.nat{size <= Vale.AES.AES_common_s.nb * (Vale.AES.AES_common_s.nr alg + 1)}
-> ek: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length ek == size} | Prims.Tot | [
"total"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_BE_s.aes_key_word",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.empty",
"Vale.Def.Types_s.nat32",
"Prims.bool",
"Prims.op_AmpAmp",
"Prims.op_LessThan",
"Vale.AES.AES_common_s.nk",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"FStar.Seq.Base.index",
"Vale.Def.Types_s.nat32_xor",
"Prims.op_Subtraction",
"Vale.Def.Words_s.nat32",
"Prims.op_Modulus",
"Vale.AES.AES_common_s.sub_word",
"Vale.AES.AES_BE_s.rot_word",
"Vale.AES.AES_common_s.aes_rcon",
"Prims.op_Division",
"Prims.op_GreaterThan",
"FStar.Seq.Base.seq",
"Prims.eq2",
"FStar.Seq.Base.length",
"Vale.AES.AES_BE_s.expand_key_def"
] | [
"recursion"
] | false | false | false | false | false | let rec expand_key_def
(alg: algorithm)
(key: aes_key_word alg)
(size: nat{size <= (nb * ((nr alg) + 1))})
: (ek: seq nat32 {length ek == size}) =
| if size = 0
then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg
then append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0
then nat32_xor (sub_word (rot_word (index w (i - 1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then sub_word (index w (i - 1)) else index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp)) | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.key_schedule_to_round_keys | val key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds}) | val key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds}) | let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 87,
"start_col": 0,
"start_line": 81
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
rounds: Prims.nat ->
w: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 {FStar.Seq.Base.length w >= 4 * rounds}
-> round_keys:
FStar.Seq.Base.seq Vale.Def.Types_s.quad32 {FStar.Seq.Base.length round_keys == rounds} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.Seq.Base.length",
"FStar.Mul.op_Star",
"Prims.op_Equality",
"Prims.int",
"FStar.Seq.Base.empty",
"Vale.Def.Types_s.quad32",
"Prims.bool",
"FStar.Seq.Base.append",
"FStar.Seq.Base.create",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words_s.Mkfour",
"FStar.Seq.Base.index",
"Prims.op_Subtraction",
"Prims.eq2",
"Vale.AES.AES_BE_s.key_schedule_to_round_keys"
] | [
"recursion"
] | false | false | false | false | false | let rec key_schedule_to_round_keys (rounds: nat) (w: seq nat32 {length w >= 4 * rounds})
: (round_keys: seq quad32 {length round_keys == rounds}) =
| if rounds = 0
then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk =
Mkfour (index w (4 * rounds - 1))
(index w (4 * rounds - 2))
(index w (4 * rounds - 3))
(index w (4 * rounds - 4))
in
append round_keys (create 1 rk) | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.key_to_round_keys_word | val key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) | val key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) | let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1))) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 82,
"end_line": 94,
"start_col": 0,
"start_line": 90
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | alg: Vale.AES.AES_common_s.algorithm -> key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32
-> Prims.Pure (FStar.Seq.Base.seq Vale.Def.Types_s.quad32) | Prims.Pure | [] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.AES.AES_BE_s.key_schedule_to_round_keys",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr",
"Vale.AES.AES_BE_s.expand_key",
"FStar.Mul.op_Star",
"Vale.AES.AES_common_s.nb",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length"
] | [] | false | false | false | false | false | let key_to_round_keys_word (alg: algorithm) (key: seq nat32)
: Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1) =
| key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1))) | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.aes_encrypt_word_def | val aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) | val aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) | let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 60,
"end_line": 100,
"start_col": 0,
"start_line": 96
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1))) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: FStar.Seq.Base.seq Vale.Def.Types_s.nat32 ->
input: Vale.Def.Types_s.quad32
-> Prims.Pure Vale.Def.Types_s.quad32 | Prims.Pure | [] | [] | [
"Vale.AES.AES_common_s.algorithm",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.quad32",
"Vale.AES.AES_BE_s.eval_cipher_def",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"Vale.AES.AES_BE_s.is_aes_key_word",
"Prims.l_True"
] | [] | false | false | false | false | false | let aes_encrypt_word_def (alg: algorithm) (key: seq nat32) (input: quad32)
: Pure quad32 (requires is_aes_key_word alg key) (ensures fun _ -> True) =
| eval_cipher_def alg input (key_to_round_keys_word alg key) | false |
Unification.fst | Unification.op_At | val op_At : x: Prims.list _ -> y: Prims.list _ -> Prims.list _ | let op_At = append | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 18,
"end_line": 34,
"start_col": 0,
"start_line": 34
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Prims.list _ -> y: Prims.list _ -> Prims.list _ | Prims.Tot | [
"total"
] | [] | [
"FStar.List.Tot.Base.append",
"Prims.list"
] | [] | false | false | false | true | false | let op_At =
| append | false |
|
Hacl.Hash.MD5.fst | Hacl.Hash.MD5.hash_oneshot | val hash_oneshot: hash_st MD5 | val hash_oneshot: hash_st MD5 | let hash_oneshot: hash_st MD5 =
Hacl.Hash.MD.mk_hash MD5 alloca update_multi update_last finish | {
"file_name": "code/hash/Hacl.Hash.MD5.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 17,
"start_col": 0,
"start_line": 16
} | module Hacl.Hash.MD5
open Hacl.Hash.Definitions
open Spec.Hash.Definitions
include Hacl.Hash.Core.MD5
friend Hacl.Hash.MD
let update_multi: update_multi_st (|MD5, ()|) =
Hacl.Hash.MD.mk_update_multi MD5 update
let update_last: update_last_st (|MD5, ()|) =
Hacl.Hash.MD.mk_update_last MD5 update_multi pad | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Hacl.Hash.MD.fst.checked",
"Hacl.Hash.Definitions.fst.checked",
"Hacl.Hash.Core.MD5.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Hash.MD5.fst"
} | [
{
"abbrev": false,
"full_module": "Hacl.Hash.Core.MD5",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Hash",
"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": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Hash.Definitions.hash_st Spec.Hash.Definitions.MD5 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Hash.MD.mk_hash",
"Spec.Hash.Definitions.MD5",
"Hacl.Hash.Core.MD5.alloca",
"Hacl.Hash.MD5.update_multi",
"Hacl.Hash.MD5.update_last",
"Hacl.Hash.Core.MD5.finish",
"Hacl.Hash.Definitions.hash_st"
] | [] | false | false | false | true | false | let hash_oneshot:hash_st MD5 =
| Hacl.Hash.MD.mk_hash MD5 alloca update_multi update_last finish | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.key_to_round_keys | val key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)}) | val key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)}) | let key_to_round_keys (alg:algorithm) (key:aes_key alg)
: (round_keys:seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word)) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 85,
"end_line": 108,
"start_col": 0,
"start_line": 105
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key)
[@"opaque_to_smt"] let aes_encrypt_word = opaque_make aes_encrypt_word_def
irreducible let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | alg: Vale.AES.AES_common_s.algorithm -> key: Vale.AES.AES_common_s.aes_key alg
-> round_keys:
FStar.Seq.Base.seq Vale.Def.Types_s.nat8
{FStar.Seq.Base.length round_keys == 16 * (Vale.AES.AES_common_s.nr alg + 1)} | Prims.Tot | [
"total"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_common_s.aes_key",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.AES.AES_BE_s.key_to_round_keys_word",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Vale.AES.AES_common_s.nr"
] | [] | false | false | false | false | false | let key_to_round_keys (alg: algorithm) (key: aes_key alg)
: (round_keys: seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
| let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word)) | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.aes_encrypt | val aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8 | val aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8 | let aes_encrypt (alg:algorithm) (key:aes_key alg) (input:seq16 nat8) : seq16 nat8 =
let key_word = seq_nat8_to_seq_nat32_BE key in
let input = be_bytes_to_quad32 input in
be_quad32_to_bytes (aes_encrypt_word alg key_word input) | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 114,
"start_col": 0,
"start_line": 111
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key)
[@"opaque_to_smt"] let aes_encrypt_word = opaque_make aes_encrypt_word_def
irreducible let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def
#push-options "--z3rlimit 20"
let key_to_round_keys (alg:algorithm) (key:aes_key alg)
: (round_keys:seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word))
#pop-options | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
alg: Vale.AES.AES_common_s.algorithm ->
key: Vale.AES.AES_common_s.aes_key alg ->
input: Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8
-> Vale.Def.Words.Seq_s.seq16 Vale.Def.Types_s.nat8 | Prims.Tot | [
"total"
] | [] | [
"Vale.AES.AES_common_s.algorithm",
"Vale.AES.AES_common_s.aes_key",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Types_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.AES.AES_BE_s.aes_encrypt_word",
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.be_bytes_to_quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE"
] | [] | false | false | false | false | false | let aes_encrypt (alg: algorithm) (key: aes_key alg) (input: seq16 nat8) : seq16 nat8 =
| let key_word = seq_nat8_to_seq_nat32_BE key in
let input = be_bytes_to_quad32 input in
be_quad32_to_bytes (aes_encrypt_word alg key_word input) | false |
Vale.AES.AES_BE_s.fst | Vale.AES.AES_BE_s.lemma_shl_rcon | val lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) | val lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) | let lemma_shl_rcon (rcon:nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32)
=
Vale.Def.TypesNative_s.reveal_ishl 32 rcon 16;
FStar.UInt.shift_left_value_lemma #32 rcon 16;
Vale.Def.TypesNative_s.reveal_ishl 64 rcon 16;
FStar.UInt.shift_left_value_lemma #64 rcon 16 | {
"file_name": "vale/specs/crypto/Vale.AES.AES_BE_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 47,
"end_line": 121,
"start_col": 0,
"start_line": 116
} | module Vale.AES.AES_BE_s
// IMPORTANT: This specification is written assuming a big-endian mapping from bytes to quad32s
// This is explicit in key_schedule_to_round_keys when we construct the round_key rk,
// but it also applies implicitly to the input quad32
open Vale.Def.Prop_s
open Vale.Def.Opaque_s
open Vale.Def.Words_s
open Vale.Def.Words.Four_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.Arch.Types
open FStar.Seq
open FStar.Mul
include Vale.AES.AES_common_s
// operations assume that the quad32 and nat32 values are big-endian interpretations
// of 16-byte and 4-byte sequences
assume val mix_columns (q:quad32) : quad32
assume val inv_mix_columns (q:quad32) : quad32
assume val shift_rows (q:quad32) : quad32
assume val inv_shift_rows (q:quad32) : quad32
assume val rot_word (w:nat32) : nat32
assume val commute_rot_word_sub_word (x:nat32) (rcon:nat32) : Lemma
(rot_word (sub_word x *^ ishl32 rcon 16) == sub_word (rot_word x) *^ rcon)
let is_aes_key_word (alg:algorithm) (s:seq nat32) : prop0 = length s == nk alg
type aes_key_word (alg:algorithm) : eqtype = s:(seq nat32){is_aes_key_word alg s}
let eval_round (state round_key:quad32) =
let s = sub_bytes state in
let s = shift_rows s in
let s = mix_columns s in
let s = quad32_xor s round_key in
s
let rec eval_rounds_def (init:quad32) (round_keys:seq quad32) (n:nat{n < length round_keys}) : quad32 =
if n = 0 then
init
else
eval_round (eval_rounds_def init round_keys (n - 1)) (index round_keys n)
[@"opaque_to_smt"] let eval_rounds = opaque_make eval_rounds_def
irreducible let eval_rounds_reveal = opaque_revealer (`%eval_rounds) eval_rounds eval_rounds_def
let eval_cipher_def (alg:algorithm) (input:quad32) (round_keys:seq quad32) : Pure quad32
(requires length round_keys == nr alg + 1)
(ensures fun _ -> True)
=
let state = quad32_xor input (index round_keys 0) in
let state = eval_rounds_def state round_keys (nr alg - 1) in
let state = sub_bytes state in
let state = shift_rows state in
let state = quad32_xor state (index round_keys (nr alg)) in
state
[@"opaque_to_smt"] let eval_cipher = opaque_make eval_cipher_def
irreducible let eval_cipher_reveal = opaque_revealer (`%eval_cipher) eval_cipher eval_cipher_def
let rec expand_key_def (alg:algorithm) (key:aes_key_word alg) (size:nat{size <= (nb * ((nr alg) + 1))})
: (ek:seq nat32 {length ek == size}) =
if size = 0 then empty
else
let w = expand_key_def alg key (size - 1) in
let i = size - 1 in
if 0 <= i && i < nk alg then
append w (create 1 (index key i))
else
let temp =
if i % (nk alg) = 0 then
nat32_xor (sub_word (rot_word (index w (i-1)))) (aes_rcon ((i / (nk alg)) - 1))
else if nk alg > 6 && i % (nk alg) = 4 then
sub_word (index w (i - 1))
else
index w (i - 1)
in
append w (create 1 (nat32_xor (index w (i - (nk alg))) temp))
[@"opaque_to_smt"] let expand_key = opaque_make expand_key_def
irreducible let expand_key_reveal = opaque_revealer (`%expand_key) expand_key expand_key_def
let rec key_schedule_to_round_keys (rounds:nat) (w:seq nat32 {length w >= 4 * rounds})
: (round_keys:seq quad32 {length round_keys == rounds}) =
if rounds = 0 then empty
else
let round_keys = key_schedule_to_round_keys (rounds - 1) w in
let rk = Mkfour (index w (4 * rounds - 1)) (index w (4 * rounds - 2)) (index w (4 * rounds - 3)) (index w (4 * rounds - 4)) in
append round_keys (create 1 rk)
[@"opaque_to_smt"]
let key_to_round_keys_word (alg:algorithm) (key:seq nat32) : Pure (seq quad32)
(requires is_aes_key_word alg key)
(ensures fun round_keys -> length round_keys == nr alg + 1)
=
key_schedule_to_round_keys (nr alg + 1) (expand_key alg key (nb * (nr alg + 1)))
let aes_encrypt_word_def (alg:algorithm) (key:seq nat32) (input:quad32) : Pure quad32
(requires is_aes_key_word alg key)
(ensures fun _ -> True)
=
eval_cipher_def alg input (key_to_round_keys_word alg key)
[@"opaque_to_smt"] let aes_encrypt_word = opaque_make aes_encrypt_word_def
irreducible let aes_encrypt_word_reveal = opaque_revealer (`%aes_encrypt_word) aes_encrypt_word aes_encrypt_word_def
#push-options "--z3rlimit 20"
let key_to_round_keys (alg:algorithm) (key:aes_key alg)
: (round_keys:seq nat8 {length round_keys == 16 * (nr alg + 1)}) =
let key_word = seq_nat8_to_seq_nat32_BE key in
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (key_to_round_keys_word alg key_word))
#pop-options
let aes_encrypt (alg:algorithm) (key:aes_key alg) (input:seq16 nat8) : seq16 nat8 =
let key_word = seq_nat8_to_seq_nat32_BE key in
let input = be_bytes_to_quad32 input in
be_quad32_to_bytes (aes_encrypt_word alg key_word input) | {
"checked_file": "/",
"dependencies": [
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Words.Four_s.fsti.checked",
"Vale.Def.TypesNative_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Prop_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_common_s.fst.checked",
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.AES.AES_BE_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.AES.AES_common_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Prop_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES",
"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": 0,
"max_fuel": 1,
"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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | rcon: Vale.Def.Types_s.nat8
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.ishl32 rcon 16 == Vale.Arch.Types.ishl64 rcon 16 % Vale.Def.Words_s.pow2_32) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.nat8",
"FStar.UInt.shift_left_value_lemma",
"Prims.unit",
"Vale.Def.TypesNative_s.reveal_ishl",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.int",
"Vale.Arch.Types.ishl32",
"Prims.op_Modulus",
"Vale.Arch.Types.ishl64",
"Vale.Def.Words_s.pow2_32",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_shl_rcon (rcon: nat8) : Lemma (ishl32 rcon 16 == ishl64 rcon 16 % pow2_32) =
| Vale.Def.TypesNative_s.reveal_ishl 32 rcon 16;
FStar.UInt.shift_left_value_lemma #32 rcon 16;
Vale.Def.TypesNative_s.reveal_ishl 64 rcon 16;
FStar.UInt.shift_left_value_lemma #64 rcon 16 | false |
Unification.fst | Unification.nat_order | val nat_order : OrdSet.cmp nat | val nat_order : OrdSet.cmp nat | let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 85,
"end_line": 48,
"start_col": 0,
"start_line": 48
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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.OrdSet.cmp Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.bool",
"FStar.OrdSet.total_order"
] | [] | false | false | false | true | false | let nat_order:(f: (nat -> nat -> bool){OrdSet.total_order nat f}) =
| fun x y -> x <= y | false |
Unification.fst | Unification.lemma_shift_append | val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m))) | val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m))) | let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 39,
"start_col": 0,
"start_line": 37
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list a -> x: a -> m: Prims.list a
-> FStar.Pervasives.Lemma (ensures l @ x :: m = (l @ [x]) @ m) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.eqtype",
"Prims.list",
"Unification.lemma_shift_append",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_shift_append #a l x m =
| match l with
| [] -> ()
| hd :: tl -> lemma_shift_append tl x m | false |
Unification.fst | Unification.empty_vars | val empty_vars : varset | val empty_vars : varset | let empty_vars = OrdSet.empty | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 52,
"start_col": 0,
"start_line": 52
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | Unification.varset | Prims.Tot | [
"total"
] | [] | [
"FStar.OrdSet.empty",
"Prims.nat",
"Unification.nat_order"
] | [] | false | false | false | true | false | let empty_vars =
| OrdSet.empty | false |
Unification.fst | Unification.vars | val vars : term -> Tot varset | val vars : term -> Tot varset | let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 47,
"end_line": 58,
"start_col": 0,
"start_line": 56
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Unification.term -> Unification.varset | Prims.Tot | [
"total"
] | [] | [
"Unification.term",
"Prims.nat",
"FStar.OrdSet.singleton",
"Unification.nat_order",
"FStar.OrdSet.union",
"Unification.vars",
"Unification.varset"
] | [
"recursion"
] | false | false | false | true | false | let rec vars =
| function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2) | false |
Unification.fst | Unification.evars | val evars : eqns -> Tot varset | val evars : eqns -> Tot varset | let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 74,
"end_line": 67,
"start_col": 0,
"start_line": 65
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Unification.eqns -> Unification.varset | Prims.Tot | [
"total"
] | [] | [
"Unification.eqns",
"Unification.empty_vars",
"Unification.term",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.OrdSet.union",
"Prims.nat",
"Unification.nat_order",
"Unification.vars",
"Unification.evars",
"Unification.varset"
] | [
"recursion"
] | false | false | false | true | false | let rec evars =
| function
| [] -> empty_vars
| (x, y) :: tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl) | false |
Unification.fst | Unification.lsubst_term | val lsubst_term : list subst -> term -> Tot term | val lsubst_term : list subst -> term -> Tot term | let lsubst_term = fold_right subst_term | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 105,
"start_col": 0,
"start_line": 105
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Prims.list Unification.subst -> _: Unification.term -> Unification.term | Prims.Tot | [
"total"
] | [] | [
"FStar.List.Tot.Base.fold_right",
"Unification.subst",
"Unification.term",
"Unification.subst_term"
] | [] | false | false | false | true | false | let lsubst_term =
| fold_right subst_term | false |
Unification.fst | Unification.n_evars | val n_evars : eqns -> Tot nat | val n_evars : eqns -> Tot nat | let n_evars eqns = OrdSet.size (evars eqns) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 71,
"start_col": 0,
"start_line": 71
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | eqns: Unification.eqns -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Unification.eqns",
"FStar.OrdSet.size",
"Prims.nat",
"Unification.nat_order",
"Unification.evars"
] | [] | false | false | false | true | false | let n_evars eqns =
| OrdSet.size (evars eqns) | false |
Unification.fst | Unification.efuns | val efuns : eqns -> Tot nat | val efuns : eqns -> Tot nat | let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 43,
"end_line": 82,
"start_col": 0,
"start_line": 80
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Unification.eqns -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Unification.eqns",
"Unification.term",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Unification.funs",
"Unification.efuns",
"Prims.nat"
] | [
"recursion"
] | false | false | false | true | false | let rec efuns =
| function
| [] -> 0
| (x, y) :: tl -> funs x + funs y + efuns tl | false |
Unification.fst | Unification.funs | val funs : term -> Tot nat | val funs : term -> Tot nat | let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2 | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 77,
"start_col": 0,
"start_line": 75
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Unification.term -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Unification.term",
"Prims.nat",
"Prims.op_Addition",
"Unification.funs"
] | [
"recursion"
] | false | false | false | true | false | let rec funs =
| function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2 | false |
Unification.fst | Unification.ok | val ok : s: (Prims.nat * Unification.term) -> Prims.bool | let ok s = not (occurs (fst s) (snd s)) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 39,
"end_line": 108,
"start_col": 0,
"start_line": 108
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: (Prims.nat * Unification.term) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Unification.term",
"Prims.op_Negation",
"Unification.occurs",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.bool"
] | [] | false | false | false | true | false | let ok s =
| not (occurs (fst s) (snd s)) | false |
|
Unification.fst | Unification.n_flex_rhs | val n_flex_rhs : eqns -> Tot nat | val n_flex_rhs : eqns -> Tot nat | let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 26,
"end_line": 91,
"start_col": 0,
"start_line": 87
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Unification.eqns -> Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Unification.eqns",
"Prims.nat",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Unification.term",
"Prims.op_Addition",
"Unification.n_flex_rhs"
] | [
"recursion"
] | false | false | false | true | false | let rec n_flex_rhs =
| function
| [] -> 0
| (V _, V _) :: tl | (_, V _) :: tl -> 1 + n_flex_rhs tl
| _ :: tl -> n_flex_rhs tl | false |
Unification.fst | Unification.subst_term | val subst_term : subst -> term -> Tot term | val subst_term : subst -> term -> Tot term | let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 102,
"start_col": 0,
"start_line": 100
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.subst -> t: Unification.term -> Unification.term | Prims.Tot | [
"total"
] | [] | [
"Unification.subst",
"Unification.term",
"Prims.nat",
"Prims.op_Equality",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Prims.bool",
"Unification.V",
"Unification.F",
"Unification.subst_term"
] | [
"recursion"
] | false | false | false | true | false | let rec subst_term s t =
| match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2) | false |
Unification.fst | Unification.occurs | val occurs : x: Prims.nat -> t: Unification.term -> Prims.bool | let occurs x t = OrdSet.mem x (vars t) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 107,
"start_col": 0,
"start_line": 107
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Prims.nat -> t: Unification.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Unification.term",
"FStar.OrdSet.mem",
"Unification.nat_order",
"Unification.vars",
"Prims.bool"
] | [] | false | false | false | true | false | let occurs x t =
| OrdSet.mem x (vars t) | false |
|
Unification.fst | Unification.lsubst_eqns | val lsubst_eqns: list subst -> eqns -> Tot eqns | val lsubst_eqns: list subst -> eqns -> Tot eqns | let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 69,
"end_line": 113,
"start_col": 0,
"start_line": 111
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list Unification.subst -> _: Unification.eqns -> Unification.eqns | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Unification.subst",
"Unification.eqns",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"Unification.term",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Unification.lsubst_term",
"Unification.lsubst_eqns"
] | [
"recursion"
] | false | false | false | true | false | let rec lsubst_eqns l =
| function
| [] -> []
| (x, y) :: tl -> (lsubst_term l x, lsubst_term l y) :: lsubst_eqns l tl | false |
Unification.fst | Unification.lemma_lsubst_eqns_nil | val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)] | val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)] | let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 121,
"start_col": 0,
"start_line": 119
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | e: Unification.eqns
-> FStar.Pervasives.Lemma (ensures Unification.lsubst_eqns [] e = e)
[SMTPat (Unification.lsubst_eqns [] e)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Unification.eqns",
"FStar.Pervasives.Native.tuple2",
"Unification.term",
"Prims.list",
"Unification.lemma_lsubst_eqns_nil",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_lsubst_eqns_nil =
| function
| [] -> ()
| _ :: tl -> lemma_lsubst_eqns_nil tl | false |
Unification.fst | Unification.evars_permute_hd | val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl))) | val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl))) | let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl)) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 85,
"end_line": 128,
"start_col": 0,
"start_line": 128
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.term -> y: Unification.term -> tl: Unification.eqns
-> FStar.Pervasives.Lemma
(ensures Unification.evars ((x, y) :: tl) = Unification.evars ((y, x) :: tl)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Unification.term",
"Unification.eqns",
"FStar.OrdSet.eq_lemma",
"Prims.nat",
"Unification.nat_order",
"Unification.evars",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit"
] | [] | true | false | true | false | false | let evars_permute_hd x y tl =
| OrdSet.eq_lemma (evars ((x, y) :: tl)) (evars ((y, x) :: tl)) | false |
Unification.fst | Unification.evars_unfun | val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl))) | val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl))) | let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl)) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 108,
"end_line": 132,
"start_col": 0,
"start_line": 132
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.term ->
y: Unification.term ->
x': Unification.term ->
y': Unification.term ->
tl: Unification.eqns
-> FStar.Pervasives.Lemma
(ensures
Unification.evars ((Unification.F x y, Unification.F x' y') :: tl) =
Unification.evars ((x, x') :: (y, y') :: tl)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Unification.term",
"Unification.eqns",
"FStar.OrdSet.eq_lemma",
"Prims.nat",
"Unification.nat_order",
"Unification.evars",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Unification.F",
"Prims.unit"
] | [] | true | false | true | false | false | let evars_unfun x y x' y' tl =
| OrdSet.eq_lemma (evars ((F x y, F x' y') :: tl)) (evars ((x, x') :: (y, y') :: tl)) | false |
Unification.fst | Unification.extend_subst | val extend_subst : s: _ -> l: Prims.list _ -> Prims.list _ | let extend_subst s l = s::l | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 27,
"end_line": 191,
"start_col": 0,
"start_line": 191
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: _ -> l: Prims.list _ -> Prims.list _ | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims.Cons"
] | [] | false | false | false | true | false | let extend_subst s l =
| s :: l | false |
|
Unification.fst | Unification.lemma_vars_decrease | val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t'))))) | val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t'))))) | let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2 | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 28,
"end_line": 143,
"start_col": 0,
"start_line": 139
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t')) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.subst -> t': Unification.term
-> FStar.Pervasives.Lemma (requires Unification.ok s)
(ensures
FStar.OrdSet.subset (Unification.vars (Unification.subst_term s t'))
(FStar.OrdSet.remove (FStar.Pervasives.Native.fst s)
(FStar.OrdSet.union (Unification.vars (FStar.Pervasives.Native.snd s))
(Unification.vars t')))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Unification.subst",
"Unification.term",
"Prims.nat",
"Unification.lemma_vars_decrease",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_vars_decrease s t' =
| match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2 | false |
Unification.fst | Unification.extend_lsubst | val extend_lsubst : l: Prims.list _ -> l': Prims.list _ -> Prims.list _ | let extend_lsubst l l' = l @ l' | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 31,
"end_line": 192,
"start_col": 0,
"start_line": 192
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list _ -> l': Prims.list _ -> Prims.list _ | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Unification.op_At"
] | [] | false | false | false | true | false | let extend_lsubst l l' =
| l @ l' | false |
|
Unification.fst | Unification.unify | val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e]) | val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e]) | let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 37,
"end_line": 175,
"start_col": 0,
"start_line": 158
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | e: Unification.eqns -> s: Prims.list Unification.subst
-> Prims.Tot (FStar.Pervasives.Native.option (Prims.list Unification.subst)) | Prims.Tot | [
"total",
""
] | [] | [
"Unification.eqns",
"Prims.list",
"Unification.subst",
"FStar.Pervasives.Native.Some",
"Prims.nat",
"Unification.term",
"FStar.Pervasives.Native.tuple2",
"Prims.op_AmpAmp",
"Unification.uu___is_V",
"Prims.op_Equality",
"Unification.__proj__V__item__i",
"Unification.unify",
"Prims.bool",
"Unification.occurs",
"FStar.Pervasives.Native.None",
"Unification.lsubst_eqns",
"Prims.Cons",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"Prims.unit",
"Unification.vars_decrease_eqns",
"FStar.Pervasives.Native.option",
"Unification.V",
"Unification.evars_permute_hd",
"Unification.evars_unfun"
] | [
"recursion"
] | false | false | false | true | false | let rec unify e s =
| match e with
| [] -> Some s
| (V x, t) :: tl ->
if V? t && V?.i t = x
then unify tl s
else
if occurs x t
then None
else
(vars_decrease_eqns x t tl;
unify (lsubst_eqns [x, t] tl) ((x, t) :: s))
| (t, V x) :: tl ->
evars_permute_hd t (V x) tl;
unify ((V x, t) :: tl) s
| (F t1 t2, F t1' t2') :: tl ->
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1') :: (t2, t2') :: tl) s | false |
Unification.fst | Unification.vars_decrease_eqns | val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e))))) | val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e))))) | let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 30,
"end_line": 154,
"start_col": 0,
"start_line": 150
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Prims.nat -> t: Unification.term -> e: Unification.eqns
-> FStar.Pervasives.Lemma (requires Unification.ok (x, t))
(ensures
FStar.OrdSet.subset (Unification.evars (Unification.lsubst_eqns [x, t] e))
(FStar.OrdSet.remove x (Unification.evars ((Unification.V x, t) :: e)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Unification.term",
"Unification.eqns",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"Unification.vars_decrease_eqns",
"Prims.unit",
"Unification.lemma_vars_decrease",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.Native.fst"
] | [
"recursion"
] | false | false | true | false | false | let rec vars_decrease_eqns x t e =
| match e with
| [] -> ()
| hd :: tl ->
lemma_vars_decrease (x, t) (fst hd);
lemma_vars_decrease (x, t) (snd hd);
vars_decrease_eqns x t tl | false |
Unification.fst | Unification.solved | val solved : eqns -> Tot bool | val solved : eqns -> Tot bool | let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 181,
"start_col": 0,
"start_line": 179
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | _: Unification.eqns -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Unification.eqns",
"Unification.term",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Unification.solved",
"Prims.bool"
] | [
"recursion"
] | false | false | false | true | false | let rec solved =
| function
| [] -> true
| (x, y) :: tl -> x = y && solved tl | false |
Unification.fst | Unification.lsubst_distributes_over_F | val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))] | val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))] | let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2 | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 189,
"start_col": 0,
"start_line": 187
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list Unification.subst -> t1: Unification.term -> t2: Unification.term
-> FStar.Pervasives.Lemma
(ensures
Unification.lsubst_term l (Unification.F t1 t2) =
Unification.F (Unification.lsubst_term l t1) (Unification.lsubst_term l t2))
[SMTPat (Unification.lsubst_term l (Unification.F t1 t2))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Unification.subst",
"Unification.term",
"Unification.lsubst_distributes_over_F",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lsubst_distributes_over_F l t1 t2 =
| match l with
| [] -> ()
| hd :: tl -> lsubst_distributes_over_F tl t1 t2 | false |
Unification.fst | Unification.sub | val sub : l: Prims.list Unification.subst -> e: Unification.eqns -> Unification.eqns | let sub l e = lsubst_eqns l e | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 29,
"end_line": 243,
"start_col": 0,
"start_line": 243
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2
let neutral s (x, t) = subst_term s (V x) = V x && subst_term s t = t && ok (x, t)
let neutral_l l (x, t) = lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t)
val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) =
lsubst_term [s] (lsubst_term l e)))
let rec lemma_lsubst_term_commutes s l e = match e with
| V y -> lemma_subst_id (fst s) (snd s) (snd s)
| F t1 t2 -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2
val lemma_lsubst_eqns_commutes: s:subst -> l:list subst -> e:eqns -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_eqns [s] (lsubst_eqns l (lsubst_eqns [s] e)) =
lsubst_eqns [s] (lsubst_eqns l e)))
let rec lemma_lsubst_eqns_commutes s l = function
| [] -> ()
| (t1,t2)::tl -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2;
lemma_lsubst_eqns_commutes s l tl | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list Unification.subst -> e: Unification.eqns -> Unification.eqns | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Unification.subst",
"Unification.eqns",
"Unification.lsubst_eqns"
] | [] | false | false | false | true | false | let sub l e =
| lsubst_eqns l e | false |
|
Unification.fst | Unification.lemma_extend_lsubst_distributes_term | val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e))) | val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e))) | let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 58,
"end_line": 199,
"start_col": 0,
"start_line": 197
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list Unification.subst -> l': Prims.list Unification.subst -> e: Unification.term
-> FStar.Pervasives.Lemma
(ensures
Unification.lsubst_term (Unification.extend_lsubst l l') e =
Unification.lsubst_term l (Unification.lsubst_term l' e)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Unification.subst",
"Unification.term",
"Unification.lemma_extend_lsubst_distributes_term",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_extend_lsubst_distributes_term l l' e =
| match l with
| [] -> ()
| hd :: tl -> lemma_extend_lsubst_distributes_term tl l' e | false |
Unification.fst | Unification.neutral | val neutral : s: Unification.subst -> _: (Prims.nat * Unification.term) -> Prims.bool | let neutral s (x, t) = subst_term s (V x) = V x && subst_term s t = t && ok (x, t) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 86,
"end_line": 219,
"start_col": 0,
"start_line": 219
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.subst -> _: (Prims.nat * Unification.term) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Unification.subst",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Unification.term",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Unification.subst_term",
"Unification.V",
"Unification.ok",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool"
] | [] | false | false | false | true | false | let neutral s (x, t) =
| subst_term s (V x) = V x && subst_term s t = t && ok (x, t) | false |
|
Unification.fst | Unification.lemma_extend_lsubst_distributes_eqns | val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)] | val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)] | let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 48,
"end_line": 210,
"start_col": 0,
"start_line": 205
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list Unification.subst -> l': Prims.list Unification.subst -> e: Unification.eqns
-> FStar.Pervasives.Lemma
(ensures
Unification.lsubst_eqns (Unification.extend_lsubst l l') e =
Unification.lsubst_eqns l (Unification.lsubst_eqns l' e))
[SMTPat (Unification.lsubst_eqns (Unification.extend_lsubst l l') e)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.list",
"Unification.subst",
"Unification.eqns",
"Unification.term",
"FStar.Pervasives.Native.tuple2",
"Unification.lemma_extend_lsubst_distributes_eqns",
"Prims.unit",
"Unification.lemma_extend_lsubst_distributes_term"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_extend_lsubst_distributes_eqns l l' e =
| match e with
| [] -> ()
| (t1, t2) :: tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl | false |
Unification.fst | Unification.test | val test : l1: Prims.list _ -> l2: Prims.list _ -> l3: Prims.list _ -> Prims.unit | let test l1 l2 l3 = assert (l1 ++ l2 ++ l3 == (l1 ++ l2) ++ l3) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 245,
"start_col": 0,
"start_line": 245
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2
let neutral s (x, t) = subst_term s (V x) = V x && subst_term s t = t && ok (x, t)
let neutral_l l (x, t) = lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t)
val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) =
lsubst_term [s] (lsubst_term l e)))
let rec lemma_lsubst_term_commutes s l e = match e with
| V y -> lemma_subst_id (fst s) (snd s) (snd s)
| F t1 t2 -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2
val lemma_lsubst_eqns_commutes: s:subst -> l:list subst -> e:eqns -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_eqns [s] (lsubst_eqns l (lsubst_eqns [s] e)) =
lsubst_eqns [s] (lsubst_eqns l e)))
let rec lemma_lsubst_eqns_commutes s l = function
| [] -> ()
| (t1,t2)::tl -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2;
lemma_lsubst_eqns_commutes s l tl
let (++) l1 l2 = extend_lsubst l1 l2
let sub l e = lsubst_eqns l e | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 _ -> l2: Prims.list _ -> l3: Prims.list _ -> Prims.unit | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Prims._assert",
"Prims.eq2",
"Unification.op_Plus_Plus",
"Prims.unit"
] | [] | false | false | false | true | false | let test l1 l2 l3 =
| assert (l1 ++ l2 ++ l3 == (l1 ++ l2) ++ l3) | false |
|
Unification.fst | Unification.neutral_l | val neutral_l : l: Prims.list Unification.subst -> _: (Prims.nat * Unification.term) -> Prims.bool | let neutral_l l (x, t) = lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t) | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 86,
"end_line": 220,
"start_col": 0,
"start_line": 220
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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 | l: Prims.list Unification.subst -> _: (Prims.nat * Unification.term) -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Unification.subst",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Unification.term",
"Prims.op_AmpAmp",
"Prims.op_Equality",
"Unification.lsubst_term",
"Unification.V",
"Unification.ok",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool"
] | [] | false | false | false | true | false | let neutral_l l (x, t) =
| lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t) | false |
|
Unification.fst | Unification.lemma_subst_id | val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y)) | val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y)) | let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2 | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 59,
"end_line": 217,
"start_col": 0,
"start_line": 215
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Prims.nat -> z: Unification.term -> y: Unification.term
-> FStar.Pervasives.Lemma (requires Prims.op_Negation (Unification.occurs x y))
(ensures Unification.subst_term (x, z) y = y) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Unification.term",
"Unification.lemma_subst_id",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_subst_id x z y =
| match y with
| V x' -> ()
| F t1 t2 ->
lemma_subst_id x z t1;
lemma_subst_id x z t2 | false |
Unification.fst | Unification.lemma_lsubst_term_commutes | val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) =
lsubst_term [s] (lsubst_term l e))) | val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) =
lsubst_term [s] (lsubst_term l e))) | let rec lemma_lsubst_term_commutes s l e = match e with
| V y -> lemma_subst_id (fst s) (snd s) (snd s)
| F t1 t2 -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2 | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 230,
"start_col": 0,
"start_line": 226
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2
let neutral s (x, t) = subst_term s (V x) = V x && subst_term s t = t && ok (x, t)
let neutral_l l (x, t) = lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t)
val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) = | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.subst -> l: Prims.list Unification.subst -> e: Unification.term
-> FStar.Pervasives.Lemma (requires Unification.neutral_l l s)
(ensures
Unification.lsubst_term [s] (Unification.lsubst_term l (Unification.subst_term s e)) =
Unification.lsubst_term [s] (Unification.lsubst_term l e)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Unification.subst",
"Prims.list",
"Unification.term",
"Prims.nat",
"Unification.lemma_subst_id",
"FStar.Pervasives.Native.fst",
"FStar.Pervasives.Native.snd",
"Unification.lemma_lsubst_term_commutes",
"Prims.unit"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_lsubst_term_commutes s l e =
| match e with
| V y -> lemma_subst_id (fst s) (snd s) (snd s)
| F t1 t2 ->
lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2 | false |
Unification.fst | Unification.lemma_lsubst_eqns_commutes | val lemma_lsubst_eqns_commutes: s:subst -> l:list subst -> e:eqns -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_eqns [s] (lsubst_eqns l (lsubst_eqns [s] e)) =
lsubst_eqns [s] (lsubst_eqns l e))) | val lemma_lsubst_eqns_commutes: s:subst -> l:list subst -> e:eqns -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_eqns [s] (lsubst_eqns l (lsubst_eqns [s] e)) =
lsubst_eqns [s] (lsubst_eqns l e))) | let rec lemma_lsubst_eqns_commutes s l = function
| [] -> ()
| (t1,t2)::tl -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2;
lemma_lsubst_eqns_commutes s l tl | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 36,
"end_line": 240,
"start_col": 0,
"start_line": 236
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2
let neutral s (x, t) = subst_term s (V x) = V x && subst_term s t = t && ok (x, t)
let neutral_l l (x, t) = lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t)
val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) =
lsubst_term [s] (lsubst_term l e)))
let rec lemma_lsubst_term_commutes s l e = match e with
| V y -> lemma_subst_id (fst s) (snd s) (snd s)
| F t1 t2 -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2
val lemma_lsubst_eqns_commutes: s:subst -> l:list subst -> e:eqns -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_eqns [s] (lsubst_eqns l (lsubst_eqns [s] e)) = | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Unification.subst -> l: Prims.list Unification.subst -> e: Unification.eqns
-> FStar.Pervasives.Lemma (requires Unification.neutral_l l s)
(ensures
Unification.lsubst_eqns [s] (Unification.lsubst_eqns l (Unification.lsubst_eqns [s] e)) =
Unification.lsubst_eqns [s] (Unification.lsubst_eqns l e)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Unification.subst",
"Prims.list",
"Unification.eqns",
"Unification.term",
"FStar.Pervasives.Native.tuple2",
"Unification.lemma_lsubst_eqns_commutes",
"Prims.unit",
"Unification.lemma_lsubst_term_commutes"
] | [
"recursion"
] | false | false | true | false | false | let rec lemma_lsubst_eqns_commutes s l =
| function
| [] -> ()
| (t1, t2) :: tl ->
lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2;
lemma_lsubst_eqns_commutes s l tl | false |
Unification.fst | Unification.key_lemma | val key_lemma: x:nat -> y:term -> tl:eqns -> l:list subst -> lpre:list subst -> l'':list subst -> Lemma
(requires (l'' = lpre ++ ([x,y] ++ l)
/\ not (occurs x y)
/\ l `sub` ((V x, y)::tl) = (V x, y)::tl
/\ solved (l'' `sub` ([x, y] `sub` tl))))
(ensures (solved (l'' `sub` ((V x,y)::tl)))) | val key_lemma: x:nat -> y:term -> tl:eqns -> l:list subst -> lpre:list subst -> l'':list subst -> Lemma
(requires (l'' = lpre ++ ([x,y] ++ l)
/\ not (occurs x y)
/\ l `sub` ((V x, y)::tl) = (V x, y)::tl
/\ solved (l'' `sub` ([x, y] `sub` tl))))
(ensures (solved (l'' `sub` ((V x,y)::tl)))) | let key_lemma x y tl l lpre l'' =
let xy = [x,y] in
let xyl = xy++l in
let vxy = V x, y in
assert (l'' `sub` (vxy::tl)
== lpre `sub` (xy `sub` (l `sub` (vxy::tl))));
lemma_lsubst_eqns_commutes (x,y) l (vxy :: tl);
assert (lpre `sub` (xy `sub` (l `sub` (vxy::tl)))
== lpre `sub` (xy `sub` (l `sub` (xy `sub` (vxy::tl)))));
assert (lpre `sub` (xy `sub` (l `sub` (xy `sub` (vxy::tl))))
== l'' `sub` (xy `sub` (vxy :: tl)));
lemma_subst_id x y y | {
"file_name": "examples/algorithms/Unification.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 265,
"start_col": 0,
"start_line": 254
} | (*
Copyright 2008-2015 Nikhil Swamy and 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.
*)
(*
A verified implementation of first-order unification.
The termination argument is based on Ana Bove's Licentiate Thesis:
Programming in Martin-Löf Type Theory Unification - A non-trivial Example
Department of Computer Science, Chalmers University of Technology
1999
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.40.3532
But, is done here directly with lex orderings.
*)
module Unification
open FStar.List.Tot
(* First, a missing lemma from the list library *)
let op_At = append
val lemma_shift_append: #a:eqtype -> l:list a -> x:a -> m:list a -> Lemma
(ensures ( (l@(x::m)) = ((l@[x])@m)))
let rec lemma_shift_append #a l x m = match l with
| [] -> ()
| hd::tl -> lemma_shift_append tl x m
(* A term language with variables V and pairs F *)
type term =
| V : i:nat -> term
| F : t1:term -> t2:term -> term
(* Finite, ordered sets of variables *)
val nat_order : OrdSet.cmp nat
let nat_order :(f:(nat -> nat -> bool){OrdSet.total_order nat f}) = fun x y -> x <= y
type varset = OrdSet.ordset nat nat_order
val empty_vars : varset
let empty_vars = OrdSet.empty
(* Collecting the variables in a term *)
val vars : term -> Tot varset
let rec vars = function
| V i -> OrdSet.singleton i
| F t1 t2 -> OrdSet.union (vars t1) (vars t2)
(* Equations among pairs of terms, to be solved *)
type eqns = list (term * term)
(* All the variables in a set of equations *)
val evars : eqns -> Tot varset
let rec evars = function
| [] -> empty_vars
| (x, y)::tl -> OrdSet.union (OrdSet.union (vars x) (vars y)) (evars tl)
(* Counting variables; used in the termination metric *)
val n_evars : eqns -> Tot nat
let n_evars eqns = OrdSet.size (evars eqns)
(* Counting the number of F-applications; also for the termination metric *)
val funs : term -> Tot nat
let rec funs = function
| V _ -> 0
| F t1 t2 -> 1 + funs t1 + funs t2
val efuns : eqns -> Tot nat
let rec efuns = function
| [] -> 0
| (x,y)::tl -> funs x + funs y + efuns tl
(* Counting the number of equations with variables on the the RHS;
// also for the termination metric *)
val n_flex_rhs : eqns -> Tot nat
let rec n_flex_rhs = function
| [] -> 0
| (V _, V _)::tl
| (_ , V _)::tl -> 1 + n_flex_rhs tl
| _::tl -> n_flex_rhs tl
(* A point substitution *)
type subst = (nat * term)
(* Composition of point substitutions *)
type lsubst = list subst
val subst_term : subst -> term -> Tot term
let rec subst_term s t = match t with
| V x -> if x = fst s then snd s else V x
| F t1 t2 -> F (subst_term s t1) (subst_term s t2)
val lsubst_term : list subst -> term -> Tot term
let lsubst_term = fold_right subst_term
let occurs x t = OrdSet.mem x (vars t)
let ok s = not (occurs (fst s) (snd s))
val lsubst_eqns: list subst -> eqns -> Tot eqns
let rec lsubst_eqns l = function
| [] -> []
| (x,y)::tl -> (lsubst_term l x, lsubst_term l y)::lsubst_eqns l tl
val lemma_lsubst_eqns_nil: e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns [] e = e))
[SMTPat (lsubst_eqns [] e)]
let rec lemma_lsubst_eqns_nil = function
| [] -> ()
| _::tl -> lemma_lsubst_eqns_nil tl
(* A couple of lemmas about variable counts.
// Both of these rely on extensional equality of sets.
// So we need to use eq_lemma explicitly *)
val evars_permute_hd : x:term -> y:term -> tl:eqns -> Lemma
(ensures (evars ((x, y)::tl) = evars ((y, x)::tl)))
let evars_permute_hd x y tl = OrdSet.eq_lemma (evars ((x,y)::tl)) (evars ((y,x)::tl))
val evars_unfun : x:term -> y:term -> x':term -> y':term -> tl:eqns -> Lemma
(ensures (evars ((F x y, F x' y')::tl) = evars ((x, x')::(y, y')::tl)))
let evars_unfun x y x' y' tl = OrdSet.eq_lemma (evars ((F x y, F x' y')::tl)) (evars ((x, x')::(y, y')::tl))
(* Eliminating a variable reduces the variable count *)
val lemma_vars_decrease: s:subst -> t':term -> Lemma
(requires (ok s))
(ensures (OrdSet.subset (vars (subst_term s t'))
(OrdSet.remove (fst s) (OrdSet.union (vars (snd s)) (vars t')))))
let rec lemma_vars_decrease s t' = match t' with
| V x -> ()
| F t1 t2 ->
lemma_vars_decrease s t1;
lemma_vars_decrease s t2
(* Lifting the prior lemma to equations *)
val vars_decrease_eqns: x:nat -> t:term -> e:eqns -> Lemma
(requires (ok (x, t)))
(ensures (OrdSet.subset (evars (lsubst_eqns [x,t] e))
(OrdSet.remove x (evars ((V x, t)::e)))))
let rec vars_decrease_eqns x t e = match e with
| [] -> ()
| hd::tl -> lemma_vars_decrease (x,t) (fst hd);
lemma_vars_decrease (x,t) (snd hd);
vars_decrease_eqns x t tl
val unify : e:eqns -> list subst -> Tot (option (list subst))
(decreases %[n_evars e; efuns e; n_flex_rhs e])
let rec unify e s = match e with
| [] -> Some s
| (V x, t)::tl ->
if V? t && V?.i t = x
then unify tl s //t is a flex-rhs
else if occurs x t
then None
else (vars_decrease_eqns x t tl;
unify (lsubst_eqns [x,t] tl) ((x,t)::s))
| (t, V x)::tl -> //flex-rhs
evars_permute_hd t (V x) tl;
unify ((V x, t)::tl) s
| (F t1 t2, F t1' t2')::tl -> //efuns reduces
evars_unfun t1 t2 t1' t2' tl;
unify ((t1, t1')::(t2, t2')::tl) s
(* All equations are solved when each one is just reflexive *)
val solved : eqns -> Tot bool
let rec solved = function
| [] -> true
| (x,y)::tl -> x=y && solved tl
val lsubst_distributes_over_F: l:list subst -> t1:term -> t2:term -> Lemma
(requires (True))
(ensures (lsubst_term l (F t1 t2) = F (lsubst_term l t1) (lsubst_term l t2)))
[SMTPat (lsubst_term l (F t1 t2))]
let rec lsubst_distributes_over_F l t1 t2 = match l with
| [] -> ()
| hd::tl -> lsubst_distributes_over_F tl t1 t2
let extend_subst s l = s::l
let extend_lsubst l l' = l @ l'
val lemma_extend_lsubst_distributes_term: l:list subst -> l':list subst -> e:term -> Lemma
(requires True)
(ensures (lsubst_term (extend_lsubst l l') e = lsubst_term l (lsubst_term l' e)))
let rec lemma_extend_lsubst_distributes_term l l' e = match l with
| [] -> ()
| hd::tl -> lemma_extend_lsubst_distributes_term tl l' e
val lemma_extend_lsubst_distributes_eqns: l:list subst -> l':list subst -> e:eqns -> Lemma
(requires True)
(ensures (lsubst_eqns (extend_lsubst l l') e = lsubst_eqns l (lsubst_eqns l' e)))
[SMTPat (lsubst_eqns (extend_lsubst l l') e)]
let rec lemma_extend_lsubst_distributes_eqns l l' e = match e with
| [] -> ()
| (t1, t2)::tl ->
lemma_extend_lsubst_distributes_term l l' t1;
lemma_extend_lsubst_distributes_term l l' t2;
lemma_extend_lsubst_distributes_eqns l l' tl
val lemma_subst_id: x:nat -> z:term -> y:term -> Lemma
(requires (not (occurs x y)))
(ensures (subst_term (x,z) y = y))
let rec lemma_subst_id x z y = match y with
| V x' -> ()
| F t1 t2 -> lemma_subst_id x z t1; lemma_subst_id x z t2
let neutral s (x, t) = subst_term s (V x) = V x && subst_term s t = t && ok (x, t)
let neutral_l l (x, t) = lsubst_term l (V x) = V x && lsubst_term l t = t && ok (x, t)
val lemma_lsubst_term_commutes: s:subst -> l:list subst -> e:term -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_term [s] (lsubst_term l (subst_term s e)) =
lsubst_term [s] (lsubst_term l e)))
let rec lemma_lsubst_term_commutes s l e = match e with
| V y -> lemma_subst_id (fst s) (snd s) (snd s)
| F t1 t2 -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2
val lemma_lsubst_eqns_commutes: s:subst -> l:list subst -> e:eqns -> Lemma
(requires (neutral_l l s))
(ensures (lsubst_eqns [s] (lsubst_eqns l (lsubst_eqns [s] e)) =
lsubst_eqns [s] (lsubst_eqns l e)))
let rec lemma_lsubst_eqns_commutes s l = function
| [] -> ()
| (t1,t2)::tl -> lemma_lsubst_term_commutes s l t1;
lemma_lsubst_term_commutes s l t2;
lemma_lsubst_eqns_commutes s l tl
let (++) l1 l2 = extend_lsubst l1 l2
let sub l e = lsubst_eqns l e
let test l1 l2 l3 = assert (l1 ++ l2 ++ l3 == (l1 ++ l2) ++ l3)
val key_lemma: x:nat -> y:term -> tl:eqns -> l:list subst -> lpre:list subst -> l'':list subst -> Lemma
(requires (l'' = lpre ++ ([x,y] ++ l)
/\ not (occurs x y)
/\ l `sub` ((V x, y)::tl) = (V x, y)::tl
/\ solved (l'' `sub` ([x, y] `sub` tl))))
(ensures (solved (l'' `sub` ((V x,y)::tl)))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.OrdSet.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "Unification.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"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: Prims.nat ->
y: Unification.term ->
tl: Unification.eqns ->
l: Prims.list Unification.subst ->
lpre: Prims.list Unification.subst ->
l'': Prims.list Unification.subst
-> FStar.Pervasives.Lemma
(requires
l'' = lpre ++ ([x, y] ++ l) /\ Prims.op_Negation (Unification.occurs x y) /\
Unification.sub l ((Unification.V x, y) :: tl) = (Unification.V x, y) :: tl /\
Unification.solved (Unification.sub l'' (Unification.sub [x, y] tl)))
(ensures Unification.solved (Unification.sub l'' ((Unification.V x, y) :: tl))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Unification.term",
"Unification.eqns",
"Prims.list",
"Unification.subst",
"Unification.lemma_subst_id",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Unification.sub",
"Prims.Cons",
"FStar.Pervasives.Native.tuple2",
"Unification.lemma_lsubst_eqns_commutes",
"FStar.Pervasives.Native.Mktuple2",
"Unification.V",
"Unification.op_Plus_Plus",
"Prims.Nil"
] | [] | true | false | true | false | false | let key_lemma x y tl l lpre l'' =
| let xy = [x, y] in
let xyl = xy ++ l in
let vxy = V x, y in
assert (l'' `sub` (vxy :: tl) == lpre `sub` (xy `sub` (l `sub` (vxy :: tl))));
lemma_lsubst_eqns_commutes (x, y) l (vxy :: tl);
assert (lpre
`sub`
(xy `sub` (l `sub` (vxy :: tl))) ==
lpre
`sub`
(xy `sub` (l `sub` (xy `sub` (vxy :: tl)))));
assert (lpre `sub` (xy `sub` (l `sub` (xy `sub` (vxy :: tl)))) == l'' `sub` (xy `sub` (vxy :: tl)));
lemma_subst_id x y y | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.