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
PulseCore.Semantics.fst
PulseCore.Semantics.act_as_m0
val act_as_m0 (#st: state u#s u#act) (#t: Type u#0) (a: action st t) : Dv (m t a.pre a.post)
val act_as_m0 (#st: state u#s u#act) (#t: Type u#0) (a: action st t) : Dv (m t a.pre a.post)
let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 310, "start_col": 0, "start_line": 301 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
a: PulseCore.Semantics.action st t -> FStar.Pervasives.Dv (PulseCore.Semantics.m t (Mkaction?.pre a) (Mkaction?.post a))
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.action", "PulseCore.Semantics.mbind", "FStar.Universe.raise_t", "PulseCore.Semantics.__proj__Mkaction__item__pre", "PulseCore.Semantics.raise_action", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.act", "PulseCore.Semantics.m", "FStar.Universe.downgrade_val", "PulseCore.Semantics.Ret" ]
[]
false
true
false
false
false
let act_as_m0 (#st: state u#s u#act) (#t: Type u#0) (a: action st t) : Dv (m t a.pre a.post) =
let k (x: U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
false
PulseCore.Semantics.fst
PulseCore.Semantics.act
val act (#st: state u#s u#act) (#t: Type u#act) (a: action st t) : m t a.pre a.post
val act (#st: state u#s u#act) (#t: Type u#act) (a: action st t) : m t a.pre a.post
let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 11, "end_line": 269, "start_col": 0, "start_line": 264 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) }
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
a: PulseCore.Semantics.action st t -> PulseCore.Semantics.m t (Mkaction?.pre a) (Mkaction?.post a)
Prims.Tot
[ "total" ]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.action", "PulseCore.Semantics.Act", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.Ret", "PulseCore.Semantics.m", "PulseCore.Semantics.__proj__Mkaction__item__pre" ]
[]
false
false
false
false
false
let act (#st: state u#s u#act) (#t: Type u#act) (a: action st t) : m t a.pre a.post =
Act a Ret
false
Hacl.Spec.Bignum.Addition.fst
Hacl.Spec.Bignum.Addition.bn_sub_lemma_loop_step
val bn_sub_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1))) (ensures (let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
val bn_sub_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1))) (ensures (let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) = let pbits = bits t in let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in let c, e = bn_sub_f a b (i - 1) c1 in assert (v e - v c * pow2 pbits == v a.[i - 1] - v b.[i - 1] - v c1); calc (==) { bn_v #t #i res - v c * pow2 (pbits * i); (==) { bn_eval_snoc #t #(i - 1) res1 e } bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] - v b.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) - v b.[i - 1] * pow2 (pbits * (i - 1)); (==) { bn_eval_unfold_i a i } eval_ aLen a i - eval_ aLen b (i - 1) - v b.[i - 1] * pow2 (pbits * (i - 1)); (==) { bn_eval_unfold_i b i } eval_ aLen a i - eval_ aLen b i; }; assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i)
{ "file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 85, "end_line": 441, "start_col": 0, "start_line": 416 }
module Hacl.Spec.Bignum.Addition open FStar.Mul open Lib.IntTypes open Lib.Sequence open Hacl.Spec.Bignum.Definitions open Hacl.Spec.Bignum.Base open Hacl.Spec.Lib #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0) val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen) let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i] val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen) let bn_sub #t #aLen #bLen a b = let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in if bLen < aLen then let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in c1, concat #_ #bLen res0 res1 else c0, res0 val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen) let bn_sub1 #t #aLen a b1 = let c0, r0 = subborrow (uint #t 0) a.[0] b1 in let res0 = create 1 r0 in if 1 < aLen then let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in c1, concat res0 res1 else c0, res0 val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0) val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen) let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i] val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen let bn_add #t #aLen #bLen a b = let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in if bLen < aLen then let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in c1, concat #_ #bLen res0 res1 else c0, res0 val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen) let bn_add1 #t #aLen a b1 = let c0, r0 = addcarry (uint #t 0) a.[0] b1 in let res0 = create 1 r0 in if 1 < aLen then let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in c1, concat res0 res1 else c0, res0 val bn_add_carry_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in)) (ensures (let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)) let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) = let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in let c, e = bn_add_carry_f a (i - 1) c1 in assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1); let pbits = bits t in calc (==) { v c * pow2 (pbits * i) + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)); (==) { } v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) } v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) } v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)); (==) { bn_eval_unfold_i #t #aLen a i } eval_ aLen a i + v c_in; }; assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in) val bn_add_carry_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> i:nat{i <= aLen} -> Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in) let rec bn_add_carry_lemma_loop #t #aLen a c_in i = let pbits = bits t in let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in if i = 0 then begin eq_generate_elems0 aLen i (bn_add_carry_f a) c_in; assert (c_out == c_in /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1); assert (generate_elems aLen i (bn_add_carry_f a) c_in == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in)); assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1)); bn_add_carry_lemma_loop a c_in (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in); bn_add_carry_lemma_loop_step a c_in i (c1, res1); assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in); () end val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> Lemma (let (c_out, res) = bn_add_carry a c_in in v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in) let bn_add_carry_lemma #t #aLen a c_in = let (c_out, res) = bn_add_carry a c_in in bn_add_carry_lemma_loop a c_in aLen val bn_add_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1))) (ensures (let (c1, res1) = c1_res1 in let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)) let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) = let pbits = bits t in let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in let c, e = bn_add_f a b (i - 1) c1 in assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1); calc (==) { v c * pow2 (pbits * i) + bn_v #t #i res; (==) { bn_eval_snoc #t #(i - 1) res1 e } v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)); (==) { } v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) } v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) } v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)); (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1)); (==) { bn_eval_unfold_i #t #aLen a i } eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1)); (==) { bn_eval_unfold_i #t #aLen b i } eval_ aLen a i + eval_ aLen b i; }; assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) val bn_add_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:nat{i <= aLen} -> Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) let rec bn_add_lemma_loop #t #aLen a b i = let pbits = bits t in let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in if i = 0 then begin eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0); assert (c == uint #t 0 /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; bn_eval0 b; () end else begin let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1); assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) == generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0))); assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1)); bn_add_lemma_loop a b (i - 1); assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)); bn_add_lemma_loop_step a b i (c1, res1); assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i); () end val bn_add_concat_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen < aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> c0:carry t -> res0:lbignum t bLen -> Lemma (requires v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen) (ensures (let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in let res = concat #_ #bLen res0 res1 in bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen))) let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 = let pbits = bits t in let a0 = sub a 0 bLen in let a1 = sub a bLen (aLen - bLen) in let c1, res1 = bn_add_carry a1 c0 in bn_add_carry_lemma a1 c0; assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0); let res = concat #_ #bLen res0 res1 in bn_concat_lemma res0 res1; assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1); calc (==) { bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1; (==) { } eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen))); (==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) } eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen)); (==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) } eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen); (==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) } eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen); (==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen } eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen); } val bn_add_lemma: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> Lemma (let (c, res) = bn_add a b in v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b) let bn_add_lemma #t #aLen #bLen a b = let pbits = bits t in let (c, res) = bn_add a b in if bLen = aLen then bn_add_lemma_loop a b aLen else begin let a0 = sub a 0 bLen in let a1 = sub a bLen (aLen - bLen) in let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in bn_add_lemma_loop a0 b bLen; assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen); bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end val bn_add1_lemma: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> Lemma (let (c, res) = bn_add1 a b1 in v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1) let bn_add1_lemma #t #aLen a b1 = let pbits = bits t in let c0, r0 = addcarry (uint #t 0) a.[0] b1 in assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1); let res0 = create 1 r0 in let b = create 1 b1 in bn_eval1 res0; bn_eval1 b; if aLen = 1 then bn_eval1 a else begin let bLen = 1 in let a0 = sub a 0 bLen in bn_eval1 a0; assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen); bn_add_concat_lemma a b c0 res0 end val bn_sub_carry_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in)) (ensures (let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)) let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) = let pbits = bits t in let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in let c, e = bn_sub_carry_f a (i - 1) c1 in assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1); calc (==) { bn_v #t #i res - v c * pow2 (pbits * i); (==) { bn_eval_snoc #t #(i - 1) res1 e } bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { } eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); (==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) } eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)); (==) { bn_eval_unfold_i a i } eval_ aLen a i - v c_in; }; assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in) val bn_sub_carry_lemma_loop: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> i:nat{i <= aLen} -> Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in) let rec bn_sub_carry_lemma_loop #t #aLen a c_in i = let pbits = bits t in let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in if i = 0 then begin eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in; assert (c_out == c_in /\ res == Seq.empty); bn_eval0 #t #0 res; assert_norm (pow2 0 = 1); bn_eval0 a; () end else begin let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1); assert (generate_elems aLen i (bn_sub_carry_f a) c_in == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in)); assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1)); bn_sub_carry_lemma_loop a c_in (i - 1); assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in); bn_sub_carry_lemma_loop_step a c_in i (c1, res1); assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in); () end val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> Lemma (let (c_out, res) = bn_sub_carry a c_in in bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in) let bn_sub_carry_lemma #t #aLen a c_in = let (c_out, res) = bn_sub_carry a c_in in bn_sub_carry_lemma_loop a c_in aLen val bn_sub_lemma_loop_step: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:pos{i <= aLen} -> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma (requires (let (c1, res1) = c1_res1 in bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1))) (ensures (let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Hacl.Spec.Lib.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Spec.Bignum.Base.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Calc.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Spec.Bignum.Addition.fst" }
[ { "abbrev": false, "full_module": "Hacl.Spec.Lib", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> i: Prims.pos{i <= aLen} -> c1_res1: Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t) (Hacl.Spec.Bignum.Base.carry t) aLen (i - 1) -> FStar.Pervasives.Lemma (requires (let _ = c1_res1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in Hacl.Spec.Bignum.Definitions.bn_v res1 - Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) == Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) - Hacl.Spec.Bignum.Definitions.eval_ aLen b (i - 1)) <: Type0)) (ensures (let _ = Hacl.Spec.Lib.generate_elem_f aLen (Hacl.Spec.Bignum.Addition.bn_sub_f a b) (i - 1) c1_res1 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in Hacl.Spec.Bignum.Definitions.bn_v res - Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) == Hacl.Spec.Bignum.Definitions.eval_ aLen a i - Hacl.Spec.Bignum.Definitions.eval_ aLen b i) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Prims.pos", "Prims.b2t", "Prims.op_LessThanOrEqual", "Hacl.Spec.Lib.generate_elem_a", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Base.carry", "Prims.op_Subtraction", "Lib.Sequence.seq", "Prims.eq2", "Prims.nat", "Lib.Sequence.length", "Prims.op_Addition", "Prims._assert", "Prims.int", "Hacl.Spec.Bignum.Definitions.bn_v", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.pow2", "Hacl.Spec.Bignum.Definitions.eval_", "Prims.unit", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Lib.Sequence.op_String_Access", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Hacl.Spec.Bignum.Definitions.bn_eval_snoc", "Prims.squash", "FStar.Math.Lemmas.distributivity_sub_left", "FStar.Math.Lemmas.distributivity_add_left", "FStar.Math.Lemmas.pow2_plus", "FStar.Math.Lemmas.paren_mul_right", "Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_sub_f", "Hacl.Spec.Lib.generate_elem_f", "FStar.Pervasives.Native.Mktuple2", "Lib.IntTypes.bits" ]
[]
false
false
true
false
false
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in let c, res = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in let c, e = bn_sub_f a b (i - 1) c1 in assert (v e - v c * pow2 pbits == v a.[ i - 1 ] - v b.[ i - 1 ] - v c1); calc ( == ) { bn_v #t #i res - v c * pow2 (pbits * i); ( == ) { bn_eval_snoc #t #(i - 1) res1 e } bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); ( == ) { () } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[ i - 1 ] - v b.[ i - 1 ] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); ( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ] - v b.[ i - 1 ] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[ i - 1 ] - v b.[ i - 1 ] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); ( == ) { Math.Lemmas.distributivity_add_left (v a.[ i - 1 ] - v b.[ i - 1 ]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[ i - 1 ] - v b.[ i - 1 ]) * pow2 (pbits * (i - 1)) + (v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i); ( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[ i - 1 ] - v b.[ i - 1 ]) * pow2 (pbits * (i - 1)); ( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ]) (v b.[ i - 1 ]) (pow2 (pbits * (i - 1))) } eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[ i - 1 ] * pow2 (pbits * (i - 1)) - v b.[ i - 1 ] * pow2 (pbits * (i - 1)); ( == ) { bn_eval_unfold_i a i } eval_ aLen a i - eval_ aLen b (i - 1) - v b.[ i - 1 ] * pow2 (pbits * (i - 1)); ( == ) { bn_eval_unfold_i b i } eval_ aLen a i - eval_ aLen b i; }; assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i)
false
Hacl.Impl.Blake2.Constants.fst
Hacl.Impl.Blake2.Constants.ivTable_S
val ivTable_S:(x: glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul {witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x})
val ivTable_S:(x: glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul {witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x})
let ivTable_S: (x:glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) = createL_global Spec.list_iv_S
{ "file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 32, "start_col": 0, "start_line": 31 }
module Hacl.Impl.Blake2.Constants open FStar.Mul open FStar.HyperStack open FStar.HyperStack.ST open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.LoopCombinators module ST = FStar.HyperStack.ST module Seq = Lib.Sequence module Loops = Lib.LoopCombinators module Spec = Spec.Blake2 /// We need to unfold manually the definition of the sigma table. This definition /// was not declared as `inline_for_extraction` because otherwise it creates a lot /// of work for the normalizer during the KaRaMeL extraction (which also explores /// the ghost code, including the content of the assertions). However, we can't do /// that by inserting manual calls to `norm` inside the code, because it blocks /// the normalization performed by KaRaMeL, and we can't normalize as much as we /// want because of the interface abstractions. The solution is to use post-processing. noextract let pp_sigmaTable () : Tactics.Tac unit = Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl () [@(Tactics.postprocess_with pp_sigmaTable)] let sigmaTable : x:glbuffer Spec.sigma_elt_t 160ul{witnessed x Spec.sigmaTable /\ recallable x} = createL_global Spec.list_sigma
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Blake2.Constants.fst" }
[ { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2", "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
x: (c: Lib.Buffer.lbuffer_t Lib.Buffer.CONST (Spec.Blake2.Definitions.pub_word_t Spec.Blake2.Definitions.Blake2S) (8ul <: FStar.UInt32.t) {LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE}) { Lib.Buffer.witnessed x (Spec.Blake2.ivTable Spec.Blake2.Definitions.Blake2S) /\ Lib.Buffer.recallable x }
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Spec.Blake2.list_iv_S", "Lib.Buffer.glbuffer", "Lib.IntTypes.size", "FStar.Pervasives.normalize_term", "Lib.IntTypes.size_nat", "FStar.List.Tot.Base.length" ]
[]
false
false
false
false
false
let ivTable_S:(x: glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul {witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) =
createL_global Spec.list_iv_S
false
PulseCore.Semantics.fst
PulseCore.Semantics.act_as_m1
val act_as_m1 (#st: state u#s u#(max 1 b)) (#t: Type u#1) (a: action st t) : Dv (m t a.pre a.post)
val act_as_m1 (#st: state u#s u#(max 1 b)) (#t: Type u#1) (a: action st t) : Dv (m t a.pre a.post)
let act_as_m1 (#st:state u#s u#(max 1 b)) (#t:Type u#1) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 321, "start_col": 0, "start_line": 312 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
a: PulseCore.Semantics.action st t -> FStar.Pervasives.Dv (PulseCore.Semantics.m t (Mkaction?.pre a) (Mkaction?.post a))
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.action", "PulseCore.Semantics.mbind", "FStar.Universe.raise_t", "PulseCore.Semantics.__proj__Mkaction__item__pre", "PulseCore.Semantics.raise_action", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.act", "PulseCore.Semantics.m", "FStar.Universe.downgrade_val", "PulseCore.Semantics.Ret" ]
[]
false
true
false
false
false
let act_as_m1 (#st: state u#s u#(max 1 b)) (#t: Type u#1) (a: action st t) : Dv (m t a.pre a.post) =
let k (x: U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
false
PulseCore.Semantics.fst
PulseCore.Semantics.run
val run (#st: state u#s u#act) (#pre: st.pred) (#a: Type u#a) (#post: post st a) (f: m a pre post) : Dv (nmst_sep st a pre post)
val run (#st: state u#s u#act) (#pre: st.pred) (#a: Type u#a) (#post: post st a) (f: m a pre post) : Dv (nmst_sep st a pre post)
let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 36, "end_line": 242, "start_col": 0, "start_line": 227 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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: PulseCore.Semantics.m a pre post -> FStar.Pervasives.Dv (PulseCore.Semantics.nmst_sep st a pre post)
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.post", "PulseCore.Semantics.m", "PulseCore.NondeterministicMonotonicStateMonad.weaken", "PulseCore.Semantics.full_mem", "PulseCore.Semantics.__proj__Mkstate__item__evolves", "Prims.l_True", "Prims.prop", "Prims.l_and", "Prims.eq2", "PulseCore.Semantics.__proj__Mkstate__item__interp", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.__proj__Mkstate__item__invariant", "PulseCore.NondeterministicMonotonicStateMonad.return", "PulseCore.Semantics.__proj__Mkstate__item__emp", "Prims.l_Forall", "PulseCore.Semantics.step_result", "Prims.l_imp", "PulseCore.Semantics.__proj__Step__item__next", "Prims.l_Exists", "PulseCore.NondeterministicMonotonicStateMonad.bind", "PulseCore.Semantics.step", "PulseCore.Semantics.nmst_sep", "PulseCore.Semantics.run" ]
[ "recursion" ]
false
true
false
false
false
let rec run (#st: state u#s u#act) (#pre: st.pred) (#a: Type u#a) (#post: post st a) (f: m a pre post) : Dv (nmst_sep st a pre post) =
match f with | Ret x -> weaken <| return x | _ -> let k (s: step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k
false
PulseCore.Semantics.fst
PulseCore.Semantics.par
val par (#st: state u#s u#act) (#p0 #q0: _) (m0: m unit p0 (as_post q0)) (#p1 #q1: _) (m1: m unit p1 (as_post q1)) : Dv (m unit (p0 `st.star` p1) (as_post (q0 `st.star` q1)))
val par (#st: state u#s u#act) (#p0 #q0: _) (m0: m unit p0 (as_post q0)) (#p1 #q1: _) (m1: m unit p1 (as_post q1)) : Dv (m unit (p0 `st.star` p1) (as_post (q0 `st.star` q1)))
let par (#st:state u#s u#act) #p0 #q0 (m0:m unit p0 (as_post q0)) #p1 #q1 (m1:m unit p1 (as_post q1)) : Dv (m unit (p0 `st.star` p1) (as_post (q0 `st.star` q1))) = let m0' = mbind m0 (fun _ -> Ret #_ #_ #(as_post q0) (U.raise_val u#0 u#0 ())) in let m1' = mbind m1 (fun _ -> Ret #_ #_ #(as_post q1) (U.raise_val u#0 u#0 ())) in Par m0' m1' (Ret ())
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 23, "end_line": 391, "start_col": 0, "start_line": 385 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m1 (#st:state u#s u#(max 1 b)) (#t:Type u#1) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m2 (#st:state u#s u#(max 2 b)) (#t:Type u#2) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k (* Next, a main property of this semantics is that it supports the frame rule. Here's a proof of it *) /// First, we prove that individual actions can be framed /// /// --- That's not so hard, since we specifically required actions to /// be frameable let frame_action (#st:state u#s u#act) (#a:Type u#act) (f:action st a) (frame:st.pred) : g:action st a { g.post == F.on_dom a (fun x -> f.post x `st.star` frame) /\ g.pre == f.pre `st.star` frame } = let step (fr:st.pred) : mst_sep st a ((f.pre `st.star` frame) `st.star` fr) (F.on_dom a (fun x -> (f.post x `st.star` frame) `st.star` fr)) = f.step (frame `st.star` fr) in { pre = _; post = F.on_dom a (fun x -> f.post x `st.star` frame); step } /// Now, to prove that computations can be framed, we'll just thread /// the frame through the entire computation, passing it over every /// frameable action let rec frame (#st:state u#s u#act) (#a:Type u#a) (#p:st.pred) (#q:post st a) (fr:st.pred) (f:m a p q) : Dv (m a (p `st.star` fr) (F.on_dom a (fun x -> q x `st.star` fr))) = match f with | Ret x -> Ret x | Act f k -> Act (frame_action f fr) (fun x -> frame fr (k x)) | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #postk k -> let m0' : m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (F.on_dom _ (fun x -> (as_post post0) x `st.star` fr)) = frame fr m0 in let m0' : m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (as_post (post0 `st.star` fr)) = m0' in let k' = frame fr k in Par m0' m1 k' (** * [par]: Parallel composition * Works by just using the `Par` node and `Ret` as its continuation
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
m0: PulseCore.Semantics.m Prims.unit p0 (PulseCore.Semantics.as_post q0) -> m1: PulseCore.Semantics.m Prims.unit p1 (PulseCore.Semantics.as_post q1) -> FStar.Pervasives.Dv (PulseCore.Semantics.m Prims.unit (Mkstate?.star st p0 p1) (PulseCore.Semantics.as_post (Mkstate?.star st q0 q1)))
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.m", "Prims.unit", "PulseCore.Semantics.as_post", "PulseCore.Semantics.Par", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.Ret", "FStar.Universe.raise_t", "PulseCore.Semantics.mbind", "FStar.Universe.raise_val" ]
[]
false
true
false
false
false
let par (#st: state u#s u#act) #p0 #q0 (m0: m unit p0 (as_post q0)) #p1 #q1 (m1: m unit p1 (as_post q1)) : Dv (m unit (p0 `st.star` p1) (as_post (q0 `st.star` q1))) =
let m0' = mbind m0 (fun _ -> Ret #_ #_ #(as_post q0) (U.raise_val u#0 u#0 ())) in let m1' = mbind m1 (fun _ -> Ret #_ #_ #(as_post q1) (U.raise_val u#0 u#0 ())) in Par m0' m1' (Ret ())
false
PulseCore.Semantics.fst
PulseCore.Semantics.act_as_m2
val act_as_m2 (#st: state u#s u#(max 2 b)) (#t: Type u#2) (a: action st t) : Dv (m t a.pre a.post)
val act_as_m2 (#st: state u#s u#(max 2 b)) (#t: Type u#2) (a: action st t) : Dv (m t a.pre a.post)
let act_as_m2 (#st:state u#s u#(max 2 b)) (#t:Type u#2) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 32, "end_line": 332, "start_col": 0, "start_line": 323 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m1 (#st:state u#s u#(max 1 b)) (#t:Type u#1) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
a: PulseCore.Semantics.action st t -> FStar.Pervasives.Dv (PulseCore.Semantics.m t (Mkaction?.pre a) (Mkaction?.post a))
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.action", "PulseCore.Semantics.mbind", "FStar.Universe.raise_t", "PulseCore.Semantics.__proj__Mkaction__item__pre", "PulseCore.Semantics.raise_action", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.act", "PulseCore.Semantics.m", "FStar.Universe.downgrade_val", "PulseCore.Semantics.Ret" ]
[]
false
true
false
false
false
let act_as_m2 (#st: state u#s u#(max 2 b)) (#t: Type u#2) (a: action st t) : Dv (m t a.pre a.post) =
let k (x: U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k
false
PulseCore.Semantics.fst
PulseCore.Semantics.mbind
val mbind (#st: state u#s u#act) (#a: Type u#a) (#b: Type u#b) (#p: st.pred) (#q: post st a) (#r: post st b) (f: m a p q) (g: (x: a -> Dv (m b (q x) r))) : Dv (m b p r)
val mbind (#st: state u#s u#act) (#a: Type u#a) (#b: Type u#b) (#p: st.pred) (#q: post st a) (#r: post st b) (f: m a p q) (g: (x: a -> Dv (m b (q x) r))) : Dv (m b p r)
let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 299, "start_col": 0, "start_line": 275 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret`
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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: PulseCore.Semantics.m a p q -> g: (x: a -> FStar.Pervasives.Dv (PulseCore.Semantics.m b (q x) r)) -> FStar.Pervasives.Dv (PulseCore.Semantics.m b p r)
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.post", "PulseCore.Semantics.m", "PulseCore.Semantics.action", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.Act", "PulseCore.Semantics.mbind", "FStar.Universe.raise_t", "Prims.unit", "PulseCore.Semantics.as_post", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.Par", "PulseCore.Semantics.Ret", "FStar.Universe.raise_val" ]
[ "recursion" ]
false
true
false
false
false
let rec mbind (#st: state u#s u#act) (#a: Type u#a) (#b: Type u#b) (#p: st.pred) (#q: post st a) (#r: post st b) (f: m a p q) (g: (x: a -> Dv (m b (q x) r))) : Dv (m b p r) =
match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k:m b (post0 `st.star` post1) r = mbind k g in let ml':m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr':m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k
false
PulseCore.Semantics.fst
PulseCore.Semantics.frame_action
val frame_action (#st: state u#s u#act) (#a: Type u#act) (f: action st a) (frame: st.pred) : g: action st a {g.post == F.on_dom a (fun x -> (f.post x) `st.star` frame) /\ g.pre == f.pre `st.star` frame}
val frame_action (#st: state u#s u#act) (#a: Type u#act) (f: action st a) (frame: st.pred) : g: action st a {g.post == F.on_dom a (fun x -> (f.post x) `st.star` frame) /\ g.pre == f.pre `st.star` frame}
let frame_action (#st:state u#s u#act) (#a:Type u#act) (f:action st a) (frame:st.pred) : g:action st a { g.post == F.on_dom a (fun x -> f.post x `st.star` frame) /\ g.pre == f.pre `st.star` frame } = let step (fr:st.pred) : mst_sep st a ((f.pre `st.star` frame) `st.star` fr) (F.on_dom a (fun x -> (f.post x `st.star` frame) `st.star` fr)) = f.step (frame `st.star` fr) in { pre = _; post = F.on_dom a (fun x -> f.post x `st.star` frame); step }
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 10, "end_line": 353, "start_col": 0, "start_line": 341 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m1 (#st:state u#s u#(max 1 b)) (#t:Type u#1) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m2 (#st:state u#s u#(max 2 b)) (#t:Type u#2) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k (* Next, a main property of this semantics is that it supports the frame rule. Here's a proof of it *) /// First, we prove that individual actions can be framed /// /// --- That's not so hard, since we specifically required actions to
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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: PulseCore.Semantics.action st a -> frame: Mkstate?.pred st -> g: PulseCore.Semantics.action st a { Mkaction?.post g == FStar.FunctionalExtensionality.on_dom a (fun x -> Mkstate?.star st (Mkaction?.post f x) frame) /\ Mkaction?.pre g == Mkstate?.star st (Mkaction?.pre f) frame }
Prims.Tot
[ "total" ]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.action", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.Mkaction", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.__proj__Mkaction__item__pre", "FStar.FunctionalExtensionality.on_dom", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.mst_sep", "FStar.FunctionalExtensionality.on_domain", "PulseCore.Semantics.__proj__Mkaction__item__step", "Prims.l_and", "Prims.eq2", "FStar.FunctionalExtensionality.restricted_t" ]
[]
false
false
false
false
false
let frame_action (#st: state u#s u#act) (#a: Type u#act) (f: action st a) (frame: st.pred) : g: action st a {g.post == F.on_dom a (fun x -> (f.post x) `st.star` frame) /\ g.pre == f.pre `st.star` frame} =
let step (fr: st.pred) : mst_sep st a ((f.pre `st.star` frame) `st.star` fr) (F.on_dom a (fun x -> ((f.post x) `st.star` frame) `st.star` fr)) = f.step (frame `st.star` fr) in { pre = _; post = F.on_dom a (fun x -> (f.post x) `st.star` frame); step = step }
false
PulseCore.Semantics.fst
PulseCore.Semantics.raise_action
val raise_action (#st: state u#s u#(max a b)) (#t: Type u#a) (a: action st t) : action st (U.raise_t u#a u#(max a b) t)
val raise_action (#st: state u#s u#(max a b)) (#t: Type u#a) (a: action st t) : action st (U.raise_t u#a u#(max a b) t)
let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) }
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 4, "end_line": 262, "start_col": 0, "start_line": 250 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
a: PulseCore.Semantics.action st t -> PulseCore.Semantics.action st (FStar.Universe.raise_t t)
Prims.Tot
[ "total" ]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.action", "PulseCore.Semantics.Mkaction", "FStar.Universe.raise_t", "PulseCore.Semantics.__proj__Mkaction__item__pre", "FStar.FunctionalExtensionality.on_dom", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.__proj__Mkaction__item__post", "FStar.Universe.downgrade_val", "PulseCore.MonotonicStateMonad.weaken", "PulseCore.Semantics.full_mem", "PulseCore.Semantics.__proj__Mkstate__item__evolves", "Prims.l_and", "Prims.l_True", "PulseCore.Semantics.__proj__Mkstate__item__interp", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.__proj__Mkstate__item__invariant", "Prims.l_Forall", "Prims.l_imp", "Prims.prop", "Prims.l_Exists", "Prims.eq2", "FStar.Universe.raise_val", "PulseCore.MonotonicStateMonad.bind", "PulseCore.Semantics.__proj__Mkaction__item__step", "PulseCore.MonotonicStateMonad.return", "PulseCore.MonotonicStateMonad.mst", "PulseCore.Semantics.mst_sep" ]
[]
false
false
false
false
false
let raise_action (#st: state u#s u#(max a b)) (#t: Type u#a) (a: action st t) : action st (U.raise_t u#a u#(max a b) t) =
{ pre = a.pre; post = F.on_dom _ (fun (x: U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| (M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x))) }
false
PulseCore.Semantics.fst
PulseCore.Semantics.conv
val conv (#st: state u#s u#act) (a: Type u#a) (#p: st.pred) (#q: post st a) (q': post st a {forall x. q x == q' x}) : Lemma (m a p q == m a p q')
val conv (#st: state u#s u#act) (a: Type u#a) (#p: st.pred) (#q: post st a) (q': post st a {forall x. q x == q' x}) : Lemma (m a p q == m a p q')
let conv (#st:state u#s u#act) (a:Type u#a) (#p:st.pred) (#q:post st a) (q':post st a { forall x. q x == q' x }) : Lemma (m a p q == m a p q') = F.extensionality _ _ q q'
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 27, "end_line": 398, "start_col": 0, "start_line": 393 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m1 (#st:state u#s u#(max 1 b)) (#t:Type u#1) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m2 (#st:state u#s u#(max 2 b)) (#t:Type u#2) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k (* Next, a main property of this semantics is that it supports the frame rule. Here's a proof of it *) /// First, we prove that individual actions can be framed /// /// --- That's not so hard, since we specifically required actions to /// be frameable let frame_action (#st:state u#s u#act) (#a:Type u#act) (f:action st a) (frame:st.pred) : g:action st a { g.post == F.on_dom a (fun x -> f.post x `st.star` frame) /\ g.pre == f.pre `st.star` frame } = let step (fr:st.pred) : mst_sep st a ((f.pre `st.star` frame) `st.star` fr) (F.on_dom a (fun x -> (f.post x `st.star` frame) `st.star` fr)) = f.step (frame `st.star` fr) in { pre = _; post = F.on_dom a (fun x -> f.post x `st.star` frame); step } /// Now, to prove that computations can be framed, we'll just thread /// the frame through the entire computation, passing it over every /// frameable action let rec frame (#st:state u#s u#act) (#a:Type u#a) (#p:st.pred) (#q:post st a) (fr:st.pred) (f:m a p q) : Dv (m a (p `st.star` fr) (F.on_dom a (fun x -> q x `st.star` fr))) = match f with | Ret x -> Ret x | Act f k -> Act (frame_action f fr) (fun x -> frame fr (k x)) | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #postk k -> let m0' : m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (F.on_dom _ (fun x -> (as_post post0) x `st.star` fr)) = frame fr m0 in let m0' : m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (as_post (post0 `st.star` fr)) = m0' in let k' = frame fr k in Par m0' m1 k' (** * [par]: Parallel composition * Works by just using the `Par` node and `Ret` as its continuation **) let par (#st:state u#s u#act) #p0 #q0 (m0:m unit p0 (as_post q0)) #p1 #q1 (m1:m unit p1 (as_post q1)) : Dv (m unit (p0 `st.star` p1) (as_post (q0 `st.star` q1))) = let m0' = mbind m0 (fun _ -> Ret #_ #_ #(as_post q0) (U.raise_val u#0 u#0 ())) in let m1' = mbind m1 (fun _ -> Ret #_ #_ #(as_post q1) (U.raise_val u#0 u#0 ())) in Par m0' m1' (Ret ())
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
a: Type -> q': PulseCore.Semantics.post st a {forall (x: a). q x == q' x} -> FStar.Pervasives.Lemma (ensures PulseCore.Semantics.m a p q == PulseCore.Semantics.m a p q')
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.post", "Prims.l_Forall", "Prims.eq2", "FStar.FunctionalExtensionality.extensionality", "Prims.unit", "Prims.l_True", "Prims.squash", "PulseCore.Semantics.m", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let conv (#st: state u#s u#act) (a: Type u#a) (#p: st.pred) (#q: post st a) (q': post st a {forall x. q x == q' x}) : Lemma (m a p q == m a p q') =
F.extensionality _ _ q q'
false
Hacl.Impl.Blake2.Constants.fst
Hacl.Impl.Blake2.Constants.sigmaTable
val sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x}
val sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x}
let sigmaTable : x:glbuffer Spec.sigma_elt_t 160ul{witnessed x Spec.sigmaTable /\ recallable x} = createL_global Spec.list_sigma
{ "file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 29, "start_col": 0, "start_line": 28 }
module Hacl.Impl.Blake2.Constants open FStar.Mul open FStar.HyperStack open FStar.HyperStack.ST open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Lib.LoopCombinators module ST = FStar.HyperStack.ST module Seq = Lib.Sequence module Loops = Lib.LoopCombinators module Spec = Spec.Blake2 /// We need to unfold manually the definition of the sigma table. This definition /// was not declared as `inline_for_extraction` because otherwise it creates a lot /// of work for the normalizer during the KaRaMeL extraction (which also explores /// the ghost code, including the content of the assertions). However, we can't do /// that by inserting manual calls to `norm` inside the code, because it blocks /// the normalization performed by KaRaMeL, and we can't normalize as much as we /// want because of the interface abstractions. The solution is to use post-processing. noextract let pp_sigmaTable () : Tactics.Tac unit = Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl ()
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Blake2.Constants.fst" }
[ { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.LoopCombinators", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Blake2", "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
x: (c: Lib.Buffer.lbuffer_t Lib.Buffer.CONST Spec.Blake2.Definitions.sigma_elt_t (160ul <: FStar.UInt32.t) {LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE}) {Lib.Buffer.witnessed x Spec.Blake2.sigmaTable /\ Lib.Buffer.recallable x}
Prims.Tot
[ "total" ]
[]
[ "Lib.Buffer.createL_global", "Spec.Blake2.Definitions.sigma_elt_t", "Prims.Cons", "Lib.IntTypes.size", "Prims.Nil" ]
[]
false
false
false
false
false
let sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x} =
createL_global Spec.list_sigma
false
PulseCore.Semantics.fst
PulseCore.Semantics.frame
val frame (#st: state u#s u#act) (#a: Type u#a) (#p: st.pred) (#q: post st a) (fr: st.pred) (f: m a p q) : Dv (m a (p `st.star` fr) (F.on_dom a (fun x -> (q x) `st.star` fr)))
val frame (#st: state u#s u#act) (#a: Type u#a) (#p: st.pred) (#q: post st a) (fr: st.pred) (f: m a p q) : Dv (m a (p `st.star` fr) (F.on_dom a (fun x -> (q x) `st.star` fr)))
let rec frame (#st:state u#s u#act) (#a:Type u#a) (#p:st.pred) (#q:post st a) (fr:st.pred) (f:m a p q) : Dv (m a (p `st.star` fr) (F.on_dom a (fun x -> q x `st.star` fr))) = match f with | Ret x -> Ret x | Act f k -> Act (frame_action f fr) (fun x -> frame fr (k x)) | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #postk k -> let m0' : m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (F.on_dom _ (fun x -> (as_post post0) x `st.star` fr)) = frame fr m0 in let m0' : m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (as_post (post0 `st.star` fr)) = m0' in let k' = frame fr k in Par m0' m1 k'
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 20, "end_line": 379, "start_col": 0, "start_line": 358 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame] *) let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose (** The main partial correctness result: * m computations can be interpreted into nmst_sep computations *) let rec run (#st:state u#s u#act) (#pre:st.pred) (#a:Type u#a) (#post:post st a) (f:m a pre post) : Dv (nmst_sep st a pre post) = match f with | Ret x -> weaken <| return x | _ -> let k (s:step_result a post st.emp) : Dv (nmst_sep st a (Step?.next s) post) = let Step _ f = s in run f in weaken <| bind (step f st.emp) k (** [return]: easy, just use Ret *) let ret (#st:state u#s u#act) (#a:Type u#a) (x:a) (post:post st a) : m a (post x) post = Ret x let raise_action (#st:state u#s u#(max a b)) (#t:Type u#a) (a:action st t) : action st (U.raise_t u#a u#(max a b) t) = { pre = a.pre; post = F.on_dom _ (fun (x:U.raise_t u#a u#(max a b) t) -> a.post (U.downgrade_val x)); step = (fun frame -> M.weaken <| M.bind (a.step frame) <| (fun x -> M.return <| U.raise_val u#a u#(max a b) x)) } let act (#st:state u#s u#act) (#t:Type u#act) (a:action st t) : m t a.pre a.post = Act a Ret (** * [bind]: sequential composition works by pushing `g` into the continuation * at each node, finally applying it at the terminal `Ret` *) let rec mbind (#st:state u#s u#act) (#a:Type u#a) (#b:Type u#b) (#p:st.pred) (#q:post st a) (#r:post st b) (f:m a p q) (g: (x:a -> Dv (m b (q x) r))) : Dv (m b p r) = match f with | Ret x -> g x | Act act k -> Act act (fun x -> mbind (k x) g) | Par #_ #pre0 #post0 ml #pre1 #post1 mr #postk k -> let k : m b (post0 `st.star` post1) r = mbind k g in let ml' : m (U.raise_t u#0 u#b unit) pre0 (as_post post0) = mbind ml (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post0) (U.raise_val u#0 u#b ())) in let mr' : m (U.raise_t u#0 u#b unit) pre1 (as_post post1) = mbind mr (fun _ -> Ret #_ #(U.raise_t u#0 u#b unit) #(as_post post1) (U.raise_val u#0 u#b ())) in Par ml' mr' k let act_as_m0 (#st:state u#s u#act) (#t:Type u#0) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t u#0 u#act t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m1 (#st:state u#s u#(max 1 b)) (#t:Type u#1) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k let act_as_m2 (#st:state u#s u#(max 2 b)) (#t:Type u#2) (a:action st t) : Dv (m t a.pre a.post) = let k (x:U.raise_t t) : Dv (m t (a.post (U.downgrade_val x)) a.post) = Ret (U.downgrade_val x) in mbind (act (raise_action a)) k (* Next, a main property of this semantics is that it supports the frame rule. Here's a proof of it *) /// First, we prove that individual actions can be framed /// /// --- That's not so hard, since we specifically required actions to /// be frameable let frame_action (#st:state u#s u#act) (#a:Type u#act) (f:action st a) (frame:st.pred) : g:action st a { g.post == F.on_dom a (fun x -> f.post x `st.star` frame) /\ g.pre == f.pre `st.star` frame } = let step (fr:st.pred) : mst_sep st a ((f.pre `st.star` frame) `st.star` fr) (F.on_dom a (fun x -> (f.post x `st.star` frame) `st.star` fr)) = f.step (frame `st.star` fr) in { pre = _; post = F.on_dom a (fun x -> f.post x `st.star` frame); step } /// Now, to prove that computations can be framed, we'll just thread /// the frame through the entire computation, passing it over every
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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
fr: Mkstate?.pred st -> f: PulseCore.Semantics.m a p q -> FStar.Pervasives.Dv (PulseCore.Semantics.m a (Mkstate?.star st p fr) (FStar.FunctionalExtensionality.on_dom a (fun x -> Mkstate?.star st (q x) fr)))
FStar.Pervasives.Dv
[]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.post", "PulseCore.Semantics.m", "PulseCore.Semantics.Ret", "FStar.FunctionalExtensionality.on_dom", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.action", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.Act", "PulseCore.Semantics.frame_action", "PulseCore.Semantics.frame", "FStar.Universe.raise_t", "Prims.unit", "PulseCore.Semantics.as_post", "PulseCore.Semantics.Par", "FStar.FunctionalExtensionality.on_domain" ]
[ "recursion" ]
false
true
false
false
false
let rec frame (#st: state u#s u#act) (#a: Type u#a) (#p: st.pred) (#q: post st a) (fr: st.pred) (f: m a p q) : Dv (m a (p `st.star` fr) (F.on_dom a (fun x -> (q x) `st.star` fr))) =
match f with | Ret x -> Ret x | Act f k -> Act (frame_action f fr) (fun x -> frame fr (k x)) | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #postk k -> let m0':m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (F.on_dom _ (fun x -> ((as_post post0) x) `st.star` fr)) = frame fr m0 in let m0':m (U.raise_t u#0 u#a unit) (pre0 `st.star` fr) (as_post (post0 `st.star` fr)) = m0' in let k' = frame fr k in Par m0' m1 k'
false
PulseCore.Semantics.fst
PulseCore.Semantics.step
val step (#st: state u#s u#act) (#p: st.pred) (#a: Type u#a) (#q: post st a) (f: m a p q) (frame: st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x) `st.star` frame)) (decreases f)
val step (#st: state u#s u#act) (#p: st.pred) (#a: Type u#a) (#q: post st a) (f: m a p q) (frame: st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x) `st.star` frame)) (decreases f)
let rec step (#st:state u#s u#act) (#p:st.pred) (#a:Type u#a) (#q:post st a) (f:m a p q) (frame:st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> Step?.next x `st.star` frame)) (decreases f) = match f with | Ret x -> weaken <| return <| Step (q x) (Ret x) | Act f k -> let k (x:_) : Dv (nmst_sep st (step_result a q frame) (f.post x `st.star` frame) (fun v -> Step?.next v `st.star` frame)) = let n : m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| return <| Step _ k | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q : post st a = coerce_eq () q in let choose (b:bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| Step _ <| Par (Step?.m x) m1 k) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| Step _ <| Par m0 (Step?.m x) k) in weaken <| bind (flip()) choose
{ "file_name": "lib/pulse_core/PulseCore.Semantics.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 222, "start_col": 0, "start_line": 181 }
(* Copyright 2024 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 PulseCore.Semantics module U = FStar.Universe module M = PulseCore.MonotonicStateMonad module NM = PulseCore.NondeterministicMonotonicStateMonad module F = FStar.FunctionalExtensionality open FStar.FunctionalExtensionality open PulseCore.NondeterministicMonotonicStateMonad open FStar.Preorder /// We start by defining some basic notions for a commutative monoid. /// /// We could reuse FStar.Algebra.CommMonoid, but this style with /// quantifiers is more convenient for the proof done here. let associative #a (f: a -> a -> a) = forall x y z. f x (f y z) == f (f x y) z let commutative #a (f: a -> a -> a) = forall x y. f x y == f y x let is_unit #a (x:a) (f:a -> a -> a) = forall y. f x y == y /\ f y x == y (** * A state typeclass: * - [s] is the type of states * - [is_full_mem] a refinement on states to the entire heap used at runtime * - [pred] is the type of state assertions * - [emp] is the empty state assertion * - [star] is the separating conjunction of state assertions * - [interp p s] is the interpretation of a state assertion [p] in a state [s] * - [evolves] is a preorder on states, constraining how it evolves * - [invariant] is an internal invariant that a caller can instantiate and is maintained * by every action and the semantics as a whole * - [laws] state that {pred, emp, star} are a commutative monoid *) noeq type state : Type u#(max (s + 1) (act + 1)) = { max_act:Type u#act; s:Type u#s; is_full_mem: s -> prop; pred:Type u#s; emp: pred; star: pred -> pred -> pred; interp: pred -> s -> prop; evolves: FStar.Preorder.preorder (s:s { is_full_mem s }); invariant: s -> pred; laws: squash (associative star /\ commutative star /\ is_unit emp star) } let full_mem (st:state u#s u#act) : Type u#s = m:st.s { st.is_full_mem m } (** [post a c] is a postcondition on [a]-typed result *) let post (s:state) a = a ^-> s.pred (** We interpret computations into the nmst monad, for partial, nondeterministic, monotonic-state transfomers. nmst_sep provides separation-logic specifications for those computations. mst_sep is analogous, except computation in mst_sep are also total **) let mst_sep_aux (st:state u#s u#act) (aux:full_mem st -> prop) (inv:full_mem st -> st.pred) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = M.mst #(full_mem st) st.evolves a (fun s0 -> aux s0 /\ st.interp (pre `st.star` inv s0) s0 ) (fun _ x s1 -> aux s1 /\ st.interp (post x `st.star` inv s1) s1) let mst_sep st a pre post = mst_sep_aux st (fun _ -> True) st.invariant a pre post let nmst_sep (st:state u#s u#act) (a:Type u#a) (pre:st.pred) (post:a -> st.pred) = nmst #(full_mem st) st.evolves a (fun s0 -> st.interp (pre `st.star` st.invariant s0) s0 ) (fun _ x s1 -> st.interp (post x `st.star` st.invariant s1) s1) (** [action c s]: atomic actions are, intuitively, single steps of * state-transforming computations (in the nmst monad). * However, we augment them with two features: * 1. they have pre-condition [pre] and post-condition [post] * 2. their type guarantees that they are frameable * Thanks to Matt Parkinson for suggesting to set up atomic actions * as frame-preserving steps. * Also see: https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/views.pdf *) noeq type action (st:state u#s u#act) (a:Type u#a) : Type u#(max a s) = { pre: st.pred; post: post st a; //a -> st.pred; step: ( frame:st.pred -> mst_sep st a (st.star pre frame) (fun x -> st.star (post x) frame) ) } let as_post (#st:state u#s u#act) (#a:Type u#a) (p:st.pred) : post st a = F.on_dom a (fun _ -> p) (** [m #st a pre post]: * A free monad for divergence, state and parallel composition * with generic actions. The main idea: * * Every continuation may be divergent. As such, [m] is indexed by * pre- and post-conditions so that we can do proofs * intrinsically. * * Universe-polymorphic im both the state and result type * *) noeq type m (#st:state u#s u#act) : (a:Type u#a) -> st.pred -> post st a -> Type u#(max (act + 1) s (a + 1)) = | Ret: #a:Type u#a -> #post:post st a -> x:a -> m a (post x) post | Act: #a:Type u#a -> #post:post st a -> #b:Type u#act -> f:action st b -> k:(x:b -> Dv (m a (f.post x) post)) -> m a f.pre post | Par: #pre0:_ -> #post0:_ -> m0:m (U.raise_t unit) pre0 (as_post post0) -> #pre1:_ -> #post1:_ -> m1:m (U.raise_t unit) pre1 (as_post post1) -> #a:_ -> #post:_ -> k:m a (st.star post0 post1) post -> m a (st.star pre0 pre1) post /// The semantics comes in two levels: /// /// 1. A single-step relation [step] which selects an atomic action to /// execute in the tree of threads /// /// 2. A top-level driver [run] which repeatedly invokes [step] /// until it returns with a result and final state. (** * [step_result #st a q frame]: * The result of evaluating a single step of a program * - s, c: The state and its monoid * - a : the result type * - q : the postcondition to be satisfied after fully reducing the programs * - frame: a framed assertion to carry through the proof *) noeq type step_result (#st:state u#s u#act) (a:Type u#a) (q:post st a) (frame:st.pred) = | Step: next:_ -> //precondition of the reduct m:m a next q -> //the reduct step_result a q frame (** * [step f frame]: Reduces a single step of [f], while framing * the assertion [frame]
{ "checked_file": "/", "dependencies": [ "PulseCore.NondeterministicMonotonicStateMonad.fsti.checked", "PulseCore.MonotonicStateMonad.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "PulseCore.Semantics.fst" }
[ { "abbrev": false, "full_module": "FStar.Preorder", "short_module": null }, { "abbrev": false, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "PulseCore.NondeterministicMonotonicStateMonad", "short_module": "NM" }, { "abbrev": true, "full_module": "PulseCore.MonotonicStateMonad", "short_module": "M" }, { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": false, "full_module": "PulseCore", "short_module": null }, { "abbrev": false, "full_module": "PulseCore", "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: PulseCore.Semantics.m a p q -> frame: Mkstate?.pred st -> Prims.Tot (PulseCore.Semantics.nmst_sep st (PulseCore.Semantics.step_result a q frame) (Mkstate?.star st p frame) (fun x -> Mkstate?.star st (Step?.next x) frame))
Prims.Tot
[ "total", "" ]
[]
[ "PulseCore.Semantics.state", "PulseCore.Semantics.__proj__Mkstate__item__pred", "PulseCore.Semantics.post", "PulseCore.Semantics.m", "PulseCore.NondeterministicMonotonicStateMonad.weaken", "PulseCore.Semantics.full_mem", "PulseCore.Semantics.__proj__Mkstate__item__evolves", "PulseCore.Semantics.step_result", "Prims.l_True", "Prims.prop", "Prims.l_and", "Prims.eq2", "PulseCore.Semantics.Step", "PulseCore.Semantics.Ret", "PulseCore.Semantics.__proj__Mkstate__item__interp", "PulseCore.Semantics.__proj__Mkstate__item__star", "PulseCore.Semantics.__proj__Mkstate__item__invariant", "PulseCore.Semantics.__proj__Step__item__next", "PulseCore.NondeterministicMonotonicStateMonad.return", "PulseCore.Semantics.action", "PulseCore.Semantics.__proj__Mkaction__item__post", "PulseCore.Semantics.__proj__Mkaction__item__pre", "Prims.l_Forall", "Prims.l_imp", "Prims.l_Exists", "PulseCore.NondeterministicMonotonicStateMonad.bind", "PulseCore.NondeterministicMonotonicStateMonad.lift", "PulseCore.Semantics.__proj__Mkaction__item__step", "PulseCore.Semantics.nmst_sep", "FStar.Universe.raise_t", "Prims.unit", "PulseCore.Semantics.as_post", "Prims.bool", "PulseCore.NondeterministicMonotonicStateMonad.flip", "PulseCore.Semantics.Par", "PulseCore.Semantics.__proj__Step__item__m", "PulseCore.Semantics.step", "PulseCore.NondeterministicMonotonicStateMonad.nmst", "FStar.Pervasives.coerce_eq" ]
[ "recursion" ]
false
false
false
false
false
let rec step (#st: state u#s u#act) (#p: st.pred) (#a: Type u#a) (#q: post st a) (f: m a p q) (frame: st.pred) : Tot (nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> (Step?.next x) `st.star` frame)) (decreases f) =
match f with | Ret x -> weaken <| (return <| Step (q x) (Ret x)) | Act f k -> let k (x: _) : Dv (nmst_sep st (step_result a q frame) ((f.post x) `st.star` frame) (fun v -> (Step?.next v) `st.star` frame)) = let n:m a (f.post x) q = k x in weaken (return (Step _ n)) in weaken <| bind (lift <| f.step frame) k | Par #_ #pre0 #post0 (Ret x0) #pre1 #post1 (Ret x1) #a #post k -> weaken <| (return <| Step _ k) | Par #_ #pre0 #post0 m0 #pre1 #post1 m1 #a #postk k -> let q:post st a = coerce_eq () q in let choose (b: bool) : nmst_sep st (step_result a q frame) (p `st.star` frame) (fun x -> ((Step?.next x) `st.star` frame)) = if b then weaken <| bind (step m0 (pre1 `st.star` frame)) (fun x -> return <| (Step _ <| Par (Step?.m x) m1 k)) else weaken <| bind (step m1 (pre0 `st.star` frame)) (fun x -> return <| (Step _ <| Par m0 (Step?.m x) k)) in weaken <| bind (flip ()) choose
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.table_len_t
val table_len_t : len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Type0
let table_len_t (len:size_t{v len > 0}) = table_len:size_t{v table_len * v len <= max_size_t}
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 124, "start_col": 0, "start_line": 123 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //---------------------------------------------- inline_for_extraction noextract let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Lib.IntTypes.max_size_t" ]
[]
false
false
false
false
true
let table_len_t (len: size_t{v len > 0}) =
table_len: size_t{v table_len * v len <= max_size_t}
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.update_block
val update_block:Impl.blake2_update_block_st Spec.Blake2S Core.M32
val update_block:Impl.blake2_update_block_st Spec.Blake2S Core.M32
let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 11, "start_col": 0, "start_line": 10 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline]
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_update_block_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_update_block", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32" ]
[]
false
false
false
true
false
let update_block:Impl.blake2_update_block_st Spec.Blake2S Core.M32 =
Impl.blake2_update_block #Spec.Blake2S #Core.M32
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.update_key
val update_key:Impl.blake2_update_key_st Spec.Blake2S Core.M32
val update_key:Impl.blake2_update_key_st Spec.Blake2S Core.M32
let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 17, "start_col": 0, "start_line": 16 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_update_key_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_update_key", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.update_block" ]
[]
false
false
false
true
false
let update_key:Impl.blake2_update_key_st Spec.Blake2S Core.M32 =
Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.init
val init:Impl.blake2_init_st Spec.Blake2S Core.M32
val init:Impl.blake2_init_st Spec.Blake2S Core.M32
let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 14, "start_col": 0, "start_line": 13 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_init_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_init", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32" ]
[]
false
false
false
true
false
let init:Impl.blake2_init_st Spec.Blake2S Core.M32 =
Impl.blake2_init #Spec.Blake2S #Core.M32
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.update_multi
val update_multi:Impl.blake2_update_multi_st Spec.Blake2S Core.M32
val update_multi:Impl.blake2_update_multi_st Spec.Blake2S Core.M32
let update_multi : Impl.blake2_update_multi_st Spec.Blake2S Core.M32 = Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 20, "start_col": 0, "start_line": 19 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32 let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_update_multi_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_update_multi", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.update_block" ]
[]
false
false
false
true
false
let update_multi:Impl.blake2_update_multi_st Spec.Blake2S Core.M32 =
Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.size_window_t
val size_window_t : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Type0
let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t}
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 85, "end_line": 120, "start_col": 0, "start_line": 119 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //----------------------------------------------
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Exponentiation.Definitions.inttype_a", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Prims.l_and", "Prims.op_LessThan", "Lib.IntTypes.bits", "Prims.op_LessThanOrEqual", "FStar.Mul.op_Star", "Prims.pow2", "Lib.IntTypes.max_size_t" ]
[]
false
false
false
false
true
let size_window_t (a_t: inttype_a) (len: size_t{v len > 0}) =
l: size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t}
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.table_inv_t
val table_inv_t : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> Type
let table_inv_t (a_t:inttype_a) (len:size_t{v len > 0}) (table_len:table_len_t len) = a:LSeq.lseq (uint_t a_t SEC) (v len) -> table:LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 74, "end_line": 129, "start_col": 0, "start_line": 127 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //---------------------------------------------- inline_for_extraction noextract let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} inline_for_extraction noextract let table_len_t (len:size_t{v len > 0}) = table_len:size_t{v table_len * v len <= max_size_t}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> Type
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Exponentiation.Definitions.inttype_a", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Exponentiation.table_len_t", "Lib.Sequence.lseq", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Star_Bang" ]
[]
false
false
false
false
true
let table_inv_t (a_t: inttype_a) (len: size_t{v len > 0}) (table_len: table_len_t len) =
a: LSeq.lseq (uint_t a_t SEC) (v len) -> table: LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.update_blocks
val update_blocks:Impl.blake2_update_blocks_st Spec.Blake2S Core.M32
val update_blocks:Impl.blake2_update_blocks_st Spec.Blake2S Core.M32
let update_blocks : Impl.blake2_update_blocks_st Spec.Blake2S Core.M32 = Impl.blake2_update_blocks #Spec.Blake2S #Core.M32 update_multi update_last
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 27, "start_col": 0, "start_line": 26 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32 let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block let update_multi : Impl.blake2_update_multi_st Spec.Blake2S Core.M32 = Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block let update_last : Impl.blake2_update_last_st Spec.Blake2S Core.M32 = Impl.blake2_update_last #Spec.Blake2S #Core.M32 update_block
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_update_blocks_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_update_blocks", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.update_multi", "Hacl.Blake2s_32.update_last" ]
[]
false
false
false
true
false
let update_blocks:Impl.blake2_update_blocks_st Spec.Blake2S Core.M32 =
Impl.blake2_update_blocks #Spec.Blake2S #Core.M32 update_multi update_last
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.update_last
val update_last:Impl.blake2_update_last_st Spec.Blake2S Core.M32
val update_last:Impl.blake2_update_last_st Spec.Blake2S Core.M32
let update_last : Impl.blake2_update_last_st Spec.Blake2S Core.M32 = Impl.blake2_update_last #Spec.Blake2S #Core.M32 update_block
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 23, "start_col": 0, "start_line": 22 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32 let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block let update_multi : Impl.blake2_update_multi_st Spec.Blake2S Core.M32 = Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_update_last_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_update_last", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.update_block" ]
[]
false
false
false
true
false
let update_last:Impl.blake2_update_last_st Spec.Blake2S Core.M32 =
Impl.blake2_update_last #Spec.Blake2S #Core.M32 update_block
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.update
val update:Impl.blake2_update_st Spec.Blake2S Core.M32
val update:Impl.blake2_update_st Spec.Blake2S Core.M32
let update : Impl.blake2_update_st Spec.Blake2S Core.M32 = Impl.blake2_update #Spec.Blake2S #Core.M32 update_key update_blocks
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 69, "end_line": 31, "start_col": 0, "start_line": 30 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32 let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block let update_multi : Impl.blake2_update_multi_st Spec.Blake2S Core.M32 = Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block let update_last : Impl.blake2_update_last_st Spec.Blake2S Core.M32 = Impl.blake2_update_last #Spec.Blake2S #Core.M32 update_block private let update_blocks : Impl.blake2_update_blocks_st Spec.Blake2S Core.M32 = Impl.blake2_update_blocks #Spec.Blake2S #Core.M32 update_multi update_last
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_update_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_update", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32", "Hacl.Blake2s_32.update_key", "Hacl.Blake2s_32.update_blocks" ]
[]
false
false
false
true
false
let update:Impl.blake2_update_st Spec.Blake2S Core.M32 =
Impl.blake2_update #Spec.Blake2S #Core.M32 update_key update_blocks
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.lexp_fw_st
val lexp_fw_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> Type0
let lexp_fw_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint a ctx /\ disjoint b res /\ disjoint res ctx /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_fw #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 100, "end_line": 270, "start_col": 0, "start_line": 247 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //---------------------------------------------- inline_for_extraction noextract let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} inline_for_extraction noextract let table_len_t (len:size_t{v len > 0}) = table_len:size_t{v table_len * v len <= max_size_t} inline_for_extraction noextract let table_inv_t (a_t:inttype_a) (len:size_t{v len > 0}) (table_len:table_len_t len) = a:LSeq.lseq (uint_t a_t SEC) (v len) -> table:LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0 inline_for_extraction noextract let pow_a_to_small_b_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len)) -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> b:uint_t a_t SEC{v b < pow2 (v l)} -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h table /\ live h res /\ live h ctx /\ disjoint table res /\ disjoint ctx res /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv a /\ table_inv a (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.pow k.to.comm_monoid (k.to.refl a) (v b)) inline_for_extraction noextract let lexp_fw_table_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ live h table /\ disjoint a res /\ disjoint a ctx /\ disjoint b res /\ disjoint res ctx /\ disjoint res table /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ table_inv (as_seq h a) (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_fw k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)) inline_for_extraction noextract val mk_lexp_fw_table: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> l:size_window_t a_t len -> table_len:table_len_t len -> table_inv:table_inv_t a_t len table_len -> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv -> lexp_fw_table_st a_t len ctx_len k l table_len table_inv // Fixed-window method with a precomputed // table = [a^0 = one; a^1; a^2; ..; a^(table_len - 1)] //----------------------------------------------------- inline_for_extraction noextract let table_inv_precomp (#a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) : table_inv_t a_t len table_len = fun a table -> 1 < v table_len /\ v table_len = pow2 (v l) /\ (forall (j:nat{j < v table_len}). PT.precomp_table_inv len ctx_len k a table_len table j) // This function returns table.[bits_l] = a^bits_l // It takes variable time to access bits_l-th element of a table inline_for_extraction noextract val lprecomp_get_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> l:size_window_t a_t len -> table_len:table_len_t len -> pow_a_to_small_b_st a_t len ctx_len k l table_len (table_inv_precomp len ctx_len k l table_len) // This function returns table.[bits_l] = a^bits_l // It takes constant time to access bits_l-th element of a table inline_for_extraction noextract val lprecomp_get_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> l:size_window_t a_t len -> table_len:table_len_t len -> pow_a_to_small_b_st a_t len ctx_len k l table_len (table_inv_precomp len ctx_len k l table_len)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Exponentiation.Definitions.inttype_a", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Exponentiation.Definitions.concrete_ops", "Hacl.Impl.Exponentiation.size_window_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Prims.op_LessThan", "Prims.op_Division", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Hacl.Bignum.Definitions.bn_v", "Prims.pow2", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx", "FStar.Ghost.reveal", "Hacl.Impl.Exponentiation.Definitions.to_comm_monoid", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to", "Lib.Buffer.as_seq", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl", "Lib.Exponentiation.exp_fw", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid" ]
[]
false
false
false
false
true
let lexp_fw_st (a_t: inttype_a) (len: size_t{v len > 0}) (ctx_len: size_t) (k: concrete_ops a_t len ctx_len) (l: size_window_t a_t len) =
ctx: lbuffer (uint_t a_t SEC) ctx_len -> a: lbuffer (uint_t a_t SEC) len -> bLen: size_t -> bBits: size_t{(v bBits - 1) / bits a_t < v bLen} -> b: lbuffer (uint_t a_t SEC) bLen -> res: lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint a ctx /\ disjoint b res /\ disjoint res ctx /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_fw #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.malloc_with_key
val malloc_with_key:Impl.blake2_malloc_st Spec.Blake2S Core.M32
val malloc_with_key:Impl.blake2_malloc_st Spec.Blake2S Core.M32
let malloc_with_key : Impl.blake2_malloc_st Spec.Blake2S Core.M32 = Impl.blake2_malloc Spec.Blake2S Core.M32
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 37, "start_col": 0, "start_line": 36 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32 let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block let update_multi : Impl.blake2_update_multi_st Spec.Blake2S Core.M32 = Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block let update_last : Impl.blake2_update_last_st Spec.Blake2S Core.M32 = Impl.blake2_update_last #Spec.Blake2S #Core.M32 update_block private let update_blocks : Impl.blake2_update_blocks_st Spec.Blake2S Core.M32 = Impl.blake2_update_blocks #Spec.Blake2S #Core.M32 update_multi update_last [@CInline] let update : Impl.blake2_update_st Spec.Blake2S Core.M32 = Impl.blake2_update #Spec.Blake2S #Core.M32 update_key update_blocks let finish : Impl.blake2_finish_st Spec.Blake2S Core.M32 = Impl.blake2_finish #Spec.Blake2S #Core.M32
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_malloc_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_malloc", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32" ]
[]
false
false
false
true
false
let malloc_with_key:Impl.blake2_malloc_st Spec.Blake2S Core.M32 =
Impl.blake2_malloc Spec.Blake2S Core.M32
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.pow_a_to_small_b_st
val pow_a_to_small_b_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len -> Type0
let pow_a_to_small_b_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len)) -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> b:uint_t a_t SEC{v b < pow2 (v l)} -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h table /\ live h res /\ live h ctx /\ disjoint table res /\ disjoint ctx res /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv a /\ table_inv a (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.pow k.to.comm_monoid (k.to.refl a) (v b))
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 76, "end_line": 154, "start_col": 0, "start_line": 133 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //---------------------------------------------- inline_for_extraction noextract let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} inline_for_extraction noextract let table_len_t (len:size_t{v len > 0}) = table_len:size_t{v table_len * v len <= max_size_t} inline_for_extraction noextract let table_inv_t (a_t:inttype_a) (len:size_t{v len > 0}) (table_len:table_len_t len) = a:LSeq.lseq (uint_t a_t SEC) (v len) -> table:LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Exponentiation.Definitions.inttype_a", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Exponentiation.Definitions.concrete_ops", "Hacl.Impl.Exponentiation.size_window_t", "Hacl.Impl.Exponentiation.table_len_t", "Hacl.Impl.Exponentiation.table_inv_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "FStar.Ghost.erased", "Lib.Sequence.lseq", "Lib.Buffer.clbuffer", "Lib.IntTypes.op_Star_Bang", "Prims.op_LessThan", "Prims.pow2", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.CONST", "Lib.Buffer.MUT", "Lib.Buffer.disjoint", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx", "FStar.Ghost.reveal", "Hacl.Impl.Exponentiation.Definitions.to_comm_monoid", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to", "Lib.Buffer.as_seq", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl", "Lib.Exponentiation.Definition.pow", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid" ]
[]
false
false
false
false
true
let pow_a_to_small_b_st (a_t: inttype_a) (len: size_t{v len > 0}) (ctx_len: size_t) (k: concrete_ops a_t len ctx_len) (l: size_window_t a_t len) (table_len: table_len_t len) (table_inv: table_inv_t a_t len table_len) =
ctx: lbuffer (uint_t a_t SEC) ctx_len -> a: Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len)) -> table: clbuffer (uint_t a_t SEC) (table_len *! len) -> b: uint_t a_t SEC {v b < pow2 (v l)} -> res: lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h table /\ live h res /\ live h ctx /\ disjoint table res /\ disjoint ctx res /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv a /\ table_inv a (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.pow k.to.comm_monoid (k.to.refl a) (v b))
false
Hacl.Blake2s_32.fst
Hacl.Blake2s_32.finish
val finish:Impl.blake2_finish_st Spec.Blake2S Core.M32
val finish:Impl.blake2_finish_st Spec.Blake2S Core.M32
let finish : Impl.blake2_finish_st Spec.Blake2S Core.M32 = Impl.blake2_finish #Spec.Blake2S #Core.M32
{ "file_name": "code/blake2/Hacl.Blake2s_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 34, "start_col": 0, "start_line": 33 }
module Hacl.Blake2s_32 module Spec = Spec.Blake2 module Impl = Hacl.Impl.Blake2.Generic module Core = Hacl.Impl.Blake2.Core (* Some specialized components of blake2 *) [@CInline] private let update_block : Impl.blake2_update_block_st Spec.Blake2S Core.M32 = Impl.blake2_update_block #Spec.Blake2S #Core.M32 let init : Impl.blake2_init_st Spec.Blake2S Core.M32 = Impl.blake2_init #Spec.Blake2S #Core.M32 let update_key : Impl.blake2_update_key_st Spec.Blake2S Core.M32 = Impl.blake2_update_key #Spec.Blake2S #Core.M32 update_block let update_multi : Impl.blake2_update_multi_st Spec.Blake2S Core.M32 = Impl.blake2_update_multi #Spec.Blake2S #Core.M32 update_block let update_last : Impl.blake2_update_last_st Spec.Blake2S Core.M32 = Impl.blake2_update_last #Spec.Blake2S #Core.M32 update_block private let update_blocks : Impl.blake2_update_blocks_st Spec.Blake2S Core.M32 = Impl.blake2_update_blocks #Spec.Blake2S #Core.M32 update_multi update_last [@CInline] let update : Impl.blake2_update_st Spec.Blake2S Core.M32 = Impl.blake2_update #Spec.Blake2S #Core.M32 update_key update_blocks
{ "checked_file": "/", "dependencies": [ "Spec.Blake2.fst.checked", "prims.fst.checked", "Hacl.Impl.Blake2.Generic.fst.checked", "Hacl.Impl.Blake2.Core.fsti.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Blake2s_32.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Core", "short_module": "Core" }, { "abbrev": true, "full_module": "Hacl.Impl.Blake2.Generic", "short_module": "Impl" }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Spec" }, { "abbrev": false, "full_module": "Hacl", "short_module": null }, { "abbrev": false, "full_module": "Hacl", "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.Impl.Blake2.Generic.blake2_finish_st Spec.Blake2.Definitions.Blake2S Hacl.Impl.Blake2.Core.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Blake2.Generic.blake2_finish", "Spec.Blake2.Definitions.Blake2S", "Hacl.Impl.Blake2.Core.M32" ]
[]
false
false
false
true
false
let finish:Impl.blake2_finish_st Spec.Blake2S Core.M32 =
Impl.blake2_finish #Spec.Blake2S #Core.M32
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.table_inv_precomp
val table_inv_precomp (#a_t: inttype_a) (len: size_t{v len > 0}) (ctx_len: size_t) (k: concrete_ops a_t len ctx_len) (l: size_window_t a_t len) (table_len: table_len_t len) : table_inv_t a_t len table_len
val table_inv_precomp (#a_t: inttype_a) (len: size_t{v len > 0}) (ctx_len: size_t) (k: concrete_ops a_t len ctx_len) (l: size_window_t a_t len) (table_len: table_len_t len) : table_inv_t a_t len table_len
let table_inv_precomp (#a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) : table_inv_t a_t len table_len = fun a table -> 1 < v table_len /\ v table_len = pow2 (v l) /\ (forall (j:nat{j < v table_len}). PT.precomp_table_inv len ctx_len k a table_len table j)
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 61, "end_line": 215, "start_col": 0, "start_line": 205 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //---------------------------------------------- inline_for_extraction noextract let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} inline_for_extraction noextract let table_len_t (len:size_t{v len > 0}) = table_len:size_t{v table_len * v len <= max_size_t} inline_for_extraction noextract let table_inv_t (a_t:inttype_a) (len:size_t{v len > 0}) (table_len:table_len_t len) = a:LSeq.lseq (uint_t a_t SEC) (v len) -> table:LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0 inline_for_extraction noextract let pow_a_to_small_b_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len)) -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> b:uint_t a_t SEC{v b < pow2 (v l)} -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h table /\ live h res /\ live h ctx /\ disjoint table res /\ disjoint ctx res /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv a /\ table_inv a (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.pow k.to.comm_monoid (k.to.refl a) (v b)) inline_for_extraction noextract let lexp_fw_table_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ live h table /\ disjoint a res /\ disjoint a ctx /\ disjoint b res /\ disjoint res ctx /\ disjoint res table /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ table_inv (as_seq h a) (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_fw k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l)) inline_for_extraction noextract val mk_lexp_fw_table: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> l:size_window_t a_t len -> table_len:table_len_t len -> table_inv:table_inv_t a_t len table_len -> pow_a_to_small_b:pow_a_to_small_b_st a_t len ctx_len k l table_len table_inv -> lexp_fw_table_st a_t len ctx_len k l table_len table_inv // Fixed-window method with a precomputed // table = [a^0 = one; a^1; a^2; ..; a^(table_len - 1)] //-----------------------------------------------------
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> Hacl.Impl.Exponentiation.table_inv_t a_t len table_len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Exponentiation.Definitions.inttype_a", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Exponentiation.Definitions.concrete_ops", "Hacl.Impl.Exponentiation.size_window_t", "Hacl.Impl.Exponentiation.table_len_t", "Lib.Sequence.lseq", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Star_Bang", "Prims.l_and", "Prims.op_LessThan", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.pow2", "Prims.l_Forall", "Prims.nat", "Hacl.Impl.PrecompTable.precomp_table_inv", "Hacl.Impl.Exponentiation.table_inv_t" ]
[]
false
false
false
false
false
let table_inv_precomp (#a_t: inttype_a) (len: size_t{v len > 0}) (ctx_len: size_t) (k: concrete_ops a_t len ctx_len) (l: size_window_t a_t len) (table_len: table_len_t len) : table_inv_t a_t len table_len =
fun a table -> 1 < v table_len /\ v table_len = pow2 (v l) /\ (forall (j: nat{j < v table_len}). PT.precomp_table_inv len ctx_len k a table_len table j)
false
Hacl.Impl.Exponentiation.fsti
Hacl.Impl.Exponentiation.lexp_fw_table_st
val lexp_fw_table_st : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len -> Type0
let lexp_fw_table_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ live h table /\ disjoint a res /\ disjoint a ctx /\ disjoint b res /\ disjoint res ctx /\ disjoint res table /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ table_inv (as_seq h a) (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_fw k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
{ "file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 87, "end_line": 184, "start_col": 0, "start_line": 158 }
module Hacl.Impl.Exponentiation open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module S = Lib.Exponentiation module BD = Hacl.Bignum.Definitions module PT = Hacl.Impl.PrecompTable include Hacl.Impl.Exponentiation.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" // This function computes `a^b` using a binary right-to-left method // It takes variable time to compute the result inline_for_extraction noextract val lexp_rl_vartime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^b` using Montgomery's ladder (a binary method) // It takes constant time to compute the result inline_for_extraction noextract val lexp_mont_ladder_swap_consttime: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> bLen:size_t -> bBits:size_t{(v bBits - 1) / bits a_t < v bLen} -> b:lbuffer (uint_t a_t SEC) bLen -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ disjoint a res /\ disjoint b res /\ disjoint a b /\ disjoint ctx a /\ disjoint ctx res /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a)) (ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b)) // This function computes `a^(2^b)` and writes the result in `res` inline_for_extraction noextract val lexp_pow2: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h res /\ live h ctx /\ live h a /\ disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // This function computes `a^(2^b)` and writes the result in `a` inline_for_extraction noextract val lexp_pow2_in_place: #a_t:inttype_a -> len:size_t{v len > 0} -> ctx_len:size_t -> k:concrete_ops a_t len ctx_len -> ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:lbuffer (uint_t a_t SEC) len -> b:size_t -> Stack unit (requires fun h -> live h a /\ live h ctx /\ disjoint a ctx /\ k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx)) (ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\ k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b)) // Fixed-window method using a precomputed table //---------------------------------------------- inline_for_extraction noextract let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) = l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} inline_for_extraction noextract let table_len_t (len:size_t{v len > 0}) = table_len:size_t{v table_len * v len <= max_size_t} inline_for_extraction noextract let table_inv_t (a_t:inttype_a) (len:size_t{v len > 0}) (table_len:table_len_t len) = a:LSeq.lseq (uint_t a_t SEC) (v len) -> table:LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0 inline_for_extraction noextract let pow_a_to_small_b_st (a_t:inttype_a) (len:size_t{v len > 0}) (ctx_len:size_t) (k:concrete_ops a_t len ctx_len) (l:size_window_t a_t len) (table_len:table_len_t len) (table_inv:table_inv_t a_t len table_len) = ctx:lbuffer (uint_t a_t SEC) ctx_len -> a:Ghost.erased (LSeq.lseq (uint_t a_t SEC) (v len)) -> table:clbuffer (uint_t a_t SEC) (table_len *! len) -> b:uint_t a_t SEC{v b < pow2 (v l)} -> res:lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h table /\ live h res /\ live h ctx /\ disjoint table res /\ disjoint ctx res /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv a /\ table_inv a (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.pow k.to.comm_monoid (k.to.refl a) (v b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.PrecompTable.fsti.checked", "Hacl.Impl.Exponentiation.Definitions.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Exponentiation.fsti" }
[ { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Base", "short_module": "BB" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum", "short_module": "SN" }, { "abbrev": true, "full_module": "Hacl.Bignum", "short_module": "BN" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Impl.PrecompTable", "short_module": "PT" }, { "abbrev": true, "full_module": "Hacl.Bignum.Definitions", "short_module": "BD" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a -> len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> ctx_len: Lib.IntTypes.size_t -> k: Hacl.Impl.Exponentiation.Definitions.concrete_ops a_t len ctx_len -> l: Hacl.Impl.Exponentiation.size_window_t a_t len -> table_len: Hacl.Impl.Exponentiation.table_len_t len -> table_inv: Hacl.Impl.Exponentiation.table_inv_t a_t len table_len -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Exponentiation.Definitions.inttype_a", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_GreaterThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Exponentiation.Definitions.concrete_ops", "Hacl.Impl.Exponentiation.size_window_t", "Hacl.Impl.Exponentiation.table_len_t", "Hacl.Impl.Exponentiation.table_inv_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint_t", "Lib.IntTypes.SEC", "Prims.op_LessThan", "Prims.op_Division", "Prims.op_Subtraction", "Lib.IntTypes.bits", "Lib.Buffer.clbuffer", "Lib.IntTypes.op_Star_Bang", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Lib.Buffer.live", "Lib.Buffer.MUT", "Lib.Buffer.CONST", "Lib.Buffer.disjoint", "Hacl.Bignum.Definitions.bn_v", "Prims.pow2", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv_ctx", "FStar.Ghost.reveal", "Hacl.Impl.Exponentiation.Definitions.to_comm_monoid", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkconcrete_ops__item__to", "Lib.Buffer.as_seq", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv", "Lib.Buffer.modifies", "Lib.Buffer.loc", "Prims.eq2", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__a_spec", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__refl", "Lib.Exponentiation.exp_fw", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__comm_monoid" ]
[]
false
false
false
false
true
let lexp_fw_table_st (a_t: inttype_a) (len: size_t{v len > 0}) (ctx_len: size_t) (k: concrete_ops a_t len ctx_len) (l: size_window_t a_t len) (table_len: table_len_t len) (table_inv: table_inv_t a_t len table_len) =
ctx: lbuffer (uint_t a_t SEC) ctx_len -> a: lbuffer (uint_t a_t SEC) len -> bLen: size_t -> bBits: size_t{(v bBits - 1) / bits a_t < v bLen} -> b: lbuffer (uint_t a_t SEC) bLen -> table: clbuffer (uint_t a_t SEC) (table_len *! len) -> res: lbuffer (uint_t a_t SEC) len -> Stack unit (requires fun h -> live h a /\ live h b /\ live h res /\ live h ctx /\ live h table /\ disjoint a res /\ disjoint a ctx /\ disjoint b res /\ disjoint res ctx /\ disjoint res table /\ BD.bn_v h b < pow2 (v bBits) /\ k.to.linv_ctx (as_seq h ctx) /\ k.to.linv (as_seq h a) /\ table_inv (as_seq h a) (as_seq h table)) (ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\ k.to.refl (as_seq h1 res) == S.exp_fw k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b) (v l))
false
Steel.Reference.fst
Steel.Reference.read_refine_pt
val read_refine_pt (#a:Type0) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v)
val read_refine_pt (#a:Type0) (#p:perm) (q:a -> vprop) (r:ref a) : SteelT a (h_exists (fun (v:a) -> pts_to r p v `star` q v)) (fun v -> pts_to r p v `star` q v)
let read_refine_pt #a #p q r = Classical.forall_intro_2 reveal_equiv; lift_exists (fun (v:a) -> pts_to r p v `star` q v); exists_cong (fun (v:U.raise_t a) -> pts_to r p (U.downgrade_val v) `star` q (U.downgrade_val v)) (fun (v:U.raise_t a) -> H.pts_to r p v `star` U.lift_dom q v); let x = H.read_refine (U.lift_dom q) r in rewrite_slprop (H.pts_to r p (hide x) `star` U.lift_dom q x) (pts_to r p (U.downgrade_val x) `star` q (U.downgrade_val x)) (fun _ -> ()); return (U.downgrade_val x)
{ "file_name": "lib/steel/Steel.Reference.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 122, "start_col": 0, "start_line": 112 }
(* 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.Reference open FStar.Ghost open Steel.Memory open Steel.Effect.Atomic open Steel.Effect module Mem = Steel.Memory module H = Steel.HigherReference module U = FStar.Universe #set-options "--ide_id_info_off" let ref a = H.ref (U.raise_t a) let null #a = H.null #(U.raise_t a) let is_null #a r = H.is_null #(U.raise_t a) r let pts_to_sl r p v = H.pts_to_sl r p (U.raise_val v) val raise_val_inj (#a:Type) (x y:a) : Lemma (requires U.raise_val x == U.raise_val y) (ensures x == y) let raise_val_inj x y = U.downgrade_val_raise_val x; U.downgrade_val_raise_val y let pts_to_ref_injective (#a: Type u#0) (r: ref a) (p0 p1:perm) (v0 v1:a) (m:mem) : Lemma (requires interp (pts_to_sl r p0 v0 `Mem.star` pts_to_sl r p1 v1) m) (ensures v0 == v1) = let v0' = U.raise_val v0 in let v1' = U.raise_val v1 in H.pts_to_ref_injective r p0 p1 v0' v1' m; raise_val_inj v0 v1 let pts_to_not_null (#a:Type u#0) (x:ref a) (p:perm) (v:a) (m:mem) : Lemma (requires interp (pts_to_sl x p v) m) (ensures x =!= null) = let v = U.raise_val v in H.pts_to_not_null #(U.raise_t a) x p v m // let pts_to_not_null' (#a:Type u#0) // (x:ref a) // (p:perm) // (v: erased a) // (m:mem) // (m1:mem{disjoint m m1}) // : Lemma (requires interp (pts_to_sl x p v) m) // (ensures interp (pts_to_sl x p v) (Mem.join m m1)) // = () let pts_to_witinv (#a:Type) (r:ref a) (p:perm) : Lemma (is_witness_invariant (pts_to_sl r p)) = let aux (x y : a) (m:mem) : Lemma (requires (interp (pts_to_sl r p x) m /\ interp (pts_to_sl r p y) m)) (ensures (x == y)) = H.pts_to_witinv r p; raise_val_inj x y in Classical.forall_intro_3 (fun x y -> Classical.move_requires (aux x y)) let pts_to_injective_eq #a #opened #p0 #p1 #v0 #v1 r = extract_info_raw (pts_to r p0 v0 `star` pts_to r p1 v1) (v0 == v1) (fun m -> pts_to_ref_injective r p0 p1 v0 v1 m); rewrite_slprop (pts_to r p1 v1) (pts_to r p1 v0) (fun _ -> ()) let pts_to_perm r = H.pts_to_perm r let alloc_pt x = let r = H.alloc (U.raise_val x) in rewrite_slprop (H.pts_to r full_perm (U.raise_val x)) (pts_to r full_perm x) (fun _ -> ()); return r let read_pt #a #p #v r = let v' = Ghost.hide (U.raise_val (Ghost.reveal v)) in rewrite_slprop (pts_to r p v) (H.pts_to r p v') (fun _ -> ()); let x = H.read r in let v':a = U.downgrade_val x in rewrite_slprop (H.pts_to r p (hide x)) (pts_to r p v') (fun _ -> ()); return v'
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.Reference.fst" }
[ { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.Memory", "short_module": "Mem" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "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.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "Steel", "short_module": null }, { "abbrev": false, "full_module": "Steel", "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
q: (_: a -> Steel.Effect.Common.vprop) -> r: Steel.Reference.ref a -> Steel.Effect.SteelT a
Steel.Effect.SteelT
[]
[]
[ "Steel.FractionalPermission.perm", "Steel.Effect.Common.vprop", "Steel.Reference.ref", "Steel.Effect.Atomic.return", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.VStar", "Steel.Reference.pts_to", "FStar.Universe.downgrade_val", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "FStar.Universe.raise_t", "FStar.Universe.lift_dom", "Steel.Memory.mem", "Steel.HigherReference.read_refine", "Steel.Effect.Atomic.exists_cong", "Steel.Effect.Atomic.lift_exists", "FStar.Classical.forall_intro_2", "Prims.l_iff", "Steel.Effect.Common.equiv", "Steel.Memory.equiv", "Steel.Effect.Common.hp_of", "Steel.Effect.Common.reveal_equiv" ]
[]
false
true
false
false
false
let read_refine_pt #a #p q r =
Classical.forall_intro_2 reveal_equiv; lift_exists (fun (v: a) -> (pts_to r p v) `star` (q v)); exists_cong (fun (v: U.raise_t a) -> (pts_to r p (U.downgrade_val v)) `star` (q (U.downgrade_val v)) ) (fun (v: U.raise_t a) -> (H.pts_to r p v) `star` (U.lift_dom q v)); let x = H.read_refine (U.lift_dom q) r in rewrite_slprop ((H.pts_to r p (hide x)) `star` (U.lift_dom q x)) ((pts_to r p (U.downgrade_val x)) `star` (q (U.downgrade_val x))) (fun _ -> ()); return (U.downgrade_val x)
false
Hacl.Impl.Ed25519.Verify.fst
Hacl.Impl.Ed25519.Verify.verify
val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 z h1 -> modifies0 h0 h1 /\ z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 z h1 -> modifies0 h0 h1 /\ z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify public_key msg_len msg signature = push_frame (); let a' = create 20ul (u64 0) in let h0 = ST.get () in Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 public_key); let b = Hacl.Impl.Ed25519.PointDecompress.point_decompress a' public_key in let res = if b then verify_valid_pk public_key msg_len msg signature a' else false in pop_frame (); res
{ "file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 144, "start_col": 0, "start_line": 136 }
module Hacl.Impl.Ed25519.Verify open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module BSeq = Lib.ByteSequence open Hacl.Bignum25519 module F51 = Hacl.Impl.Ed25519.Field51 module PM = Hacl.Impl.Ed25519.Ladder #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" inline_for_extraction noextract let point_inv_full_t (h:mem) (p:point) = F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) inline_for_extraction noextract val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool (requires fun h -> live h sb /\ live h hb /\ live h a' /\ live h r' /\ point_inv_full_t h a' /\ point_inv_full_t h r') (ensures fun h0 z h1 -> modifies0 h0 h1 /\ (z == Spec.Ed25519.( let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in point_equal exp_d (F51.point_eval h0 r')))) let verify_all_valid_hb sb hb a' r' = push_frame (); let exp_d = create 20ul (u64 0) in PM.point_negate_mul_double_g_vartime exp_d sb hb a'; let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in let h0 = ST.get () in Spec.Ed25519.Lemmas.point_equal_lemma (F51.point_eval h0 exp_d) (Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a')) (F51.point_eval h0 r'); pop_frame (); b inline_for_extraction noextract val verify_sb: sb:lbuffer uint8 32ul -> Stack bool (requires fun h -> live h sb) (ensures fun h0 b h1 -> modifies0 h0 h1 /\ (b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q))) let verify_sb sb = push_frame (); let tmp = create 5ul (u64 0) in Hacl.Impl.Load56.load_32_bytes tmp sb; let b = Hacl.Impl.Ed25519.PointEqual.gte_q tmp in pop_frame (); b inline_for_extraction noextract val verify_valid_pk_rs: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> a':point -> r':point -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\ (Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\ (F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ (Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\ (F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul))))) (ensures fun h0 z h1 -> modifies0 h0 h1 /\ z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) let verify_valid_pk_rs public_key msg_len msg signature a' r' = push_frame (); let hb = create 32ul (u8 0) in let rs = sub signature 0ul 32ul in let sb = sub signature 32ul 32ul in let b = verify_sb sb in let res = if b then false else begin Hacl.Impl.SHA512.ModQ.store_sha512_modq_pre_pre2 hb rs public_key msg_len msg; verify_all_valid_hb sb hb a' r' end in pop_frame (); res inline_for_extraction noextract val verify_valid_pk: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> a':point -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature /\ live h a' /\ (Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\ (F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key)))) (ensures fun h0 z h1 -> modifies0 h0 h1 /\ z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) let verify_valid_pk public_key msg_len msg signature a' = push_frame (); let r' = create 20ul (u64 0) in let rs = sub signature 0ul 32ul in let h0 = ST.get () in Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 rs); let b' = Hacl.Impl.Ed25519.PointDecompress.point_decompress r' rs in let res = if b' then verify_valid_pk_rs public_key msg_len msg signature a' r' else false in pop_frame (); res inline_for_extraction noextract val verify: public_key:lbuffer uint8 32ul -> msg_len:size_t -> msg:lbuffer uint8 msg_len -> signature:lbuffer uint8 64ul -> Stack bool (requires fun h -> live h public_key /\ live h msg /\ live h signature) (ensures fun h0 z h1 -> modifies0 h0 h1 /\ z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
{ "checked_file": "/", "dependencies": [ "Spec.Ed25519.Lemmas.fsti.checked", "Spec.Ed25519.fst.checked", "prims.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Impl.SHA512.ModQ.fst.checked", "Hacl.Impl.Load56.fst.checked", "Hacl.Impl.Ed25519.PointEqual.fst.checked", "Hacl.Impl.Ed25519.PointDecompress.fst.checked", "Hacl.Impl.Ed25519.Ladder.fsti.checked", "Hacl.Impl.Ed25519.Field51.fst.checked", "Hacl.Bignum25519.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Ed25519.Verify.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Ladder", "short_module": "PM" }, { "abbrev": true, "full_module": "Hacl.Impl.Ed25519.Field51", "short_module": "F51" }, { "abbrev": false, "full_module": "Hacl.Bignum25519", "short_module": null }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Ed25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> msg_len: Lib.IntTypes.size_t -> msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len -> signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul -> FStar.HyperStack.ST.Stack Prims.bool
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Prims.bool", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Hacl.Impl.Ed25519.Verify.verify_valid_pk", "Hacl.Impl.Ed25519.PointDecompress.point_decompress", "Spec.Ed25519.Lemmas.point_decompress_lemma", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.uint64", "Lib.IntTypes.u64", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let verify public_key msg_len msg signature =
push_frame (); let a' = create 20ul (u64 0) in let h0 = ST.get () in Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 public_key); let b = Hacl.Impl.Ed25519.PointDecompress.point_decompress a' public_key in let res = if b then verify_valid_pk public_key msg_len msg signature a' else false in pop_frame (); res
false
Steel.ST.GenElim1.fst
Steel.ST.GenElim1.compute_gen_elim_nondep_correct9
val compute_gen_elim_nondep_correct9 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
val compute_gen_elim_nondep_correct9 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9])
let compute_gen_elim_nondep_correct9 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ())))))))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let x5 = elim_exists' () in let x6 = elim_exists' () in let x7 = elim_exists' () in let x8 = elim_exists' () in let x9 = elim_exists' () in let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in elim_pure _; rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res
{ "file_name": "lib/steel/Steel.ST.GenElim1.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 7, "end_line": 637, "start_col": 0, "start_line": 618 }
module Steel.ST.GenElim1 let gen_elim_f (p: vprop) (a: Type) (q: (a -> vprop)) (post: (a -> prop)) : Tot Type = ((opened: inames) -> STGhost a opened p q True post) module U = FStar.Universe let gen_unit_elim_t (i: gen_unit_elim_i) : Tot Type = gen_elim_f (compute_gen_unit_elim_p i) (U.raise_t u#_ u#1 unit) (fun _ -> compute_gen_unit_elim_q i) (fun _ -> compute_gen_unit_elim_post i) let compute_gen_unit_elim_f_id (v: vprop) : Tot (gen_unit_elim_t (GUEId v)) = fun _ -> noop (); U.raise_val () let compute_gen_unit_elim_f_pure (p: prop) : Tot (gen_unit_elim_t (GUEPure p)) = fun _ -> rewrite (compute_gen_unit_elim_p (GUEPure p)) (pure p); elim_pure p; U.raise_val () let compute_gen_unit_elim_f_star (i1 i2: gen_unit_elim_i) (f1: gen_unit_elim_t i1) (f2: gen_unit_elim_t i2) : Tot (gen_unit_elim_t (GUEStar i1 i2)) = fun _ -> rewrite (compute_gen_unit_elim_p (GUEStar i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_unit_elim_p i2); let _ = f1 _ in let _ = f2 _ in rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_unit_elim_q i2) (compute_gen_unit_elim_q (GUEStar i1 i2)); U.raise_val () let rec compute_gen_unit_elim_f (i: gen_unit_elim_i) : GTot (gen_unit_elim_t i) = match i returns (gen_unit_elim_t i) with | GUEId v -> compute_gen_unit_elim_f_id v | GUEPure p -> compute_gen_unit_elim_f_pure p | GUEStar i1 i2 -> compute_gen_unit_elim_f_star i1 i2 (compute_gen_unit_elim_f i1) (compute_gen_unit_elim_f i2) let gen_elim_t (i: gen_elim_i) : Tot Type = gen_elim_f (compute_gen_elim_p i) (compute_gen_elim_a i) (compute_gen_elim_q i) (compute_gen_elim_post i) let compute_gen_elim_f_unit (i: gen_unit_elim_i) : GTot (gen_elim_t (GEUnit i)) = compute_gen_unit_elim_f i let compute_gen_elim_f_star_l (i1: gen_elim_i) (f1: gen_elim_t i1) (i2: gen_unit_elim_i) : GTot (gen_elim_t (GEStarL i1 i2)) = let f2 = compute_gen_unit_elim_f i2 in fun _ -> rewrite (compute_gen_elim_p (GEStarL i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_unit_elim_p i2); let res = f1 _ in let _ = f2 _ in let res' : compute_gen_elim_a (GEStarL i1 i2) = coerce_with_trefl res in rewrite (compute_gen_elim_q i1 res `star` compute_gen_unit_elim_q i2) (compute_gen_elim_q (GEStarL i1 i2) res'); res' let compute_gen_elim_f_star_r (i1: gen_unit_elim_i) (i2: gen_elim_i) (f2: gen_elim_t i2) : GTot (gen_elim_t (GEStarR i1 i2)) = let f1 = compute_gen_unit_elim_f i1 in fun _ -> rewrite (compute_gen_elim_p (GEStarR i1 i2)) (compute_gen_unit_elim_p i1 `star` compute_gen_elim_p i2); let _ = f1 _ in let res = f2 _ in let res' : compute_gen_elim_a (GEStarR i1 i2) = coerce_with_trefl res in rewrite (compute_gen_unit_elim_q i1 `star` compute_gen_elim_q i2 res) (compute_gen_elim_q (GEStarR i1 i2) res'); res' let compute_gen_elim_f_star (i1: gen_elim_i) (f1: gen_elim_t i1) (i2: gen_elim_i) (f2: gen_elim_t i2) : GTot (gen_elim_t (GEStar i1 i2)) = fun _ -> rewrite (compute_gen_elim_p (GEStar i1 i2)) (compute_gen_elim_p i1 `star` compute_gen_elim_p i2); let res1 = f1 _ in let res2 = f2 _ in let res : compute_gen_elim_a (GEStar i1 i2) = coerce_with_trefl (res1, res2) in rewrite (compute_gen_elim_q i1 res1 `star` compute_gen_elim_q i2 res2) (compute_gen_elim_q (GEStar i1 i2) res); res let compute_gen_elim_f_exists_no_abs0 (a: Type0) (body: (a -> vprop)) : GTot (gen_elim_t (GEExistsNoAbs0 body)) = fun _ -> rewrite (compute_gen_elim_p (GEExistsNoAbs0 body)) (exists_ body); let gres = elim_exists () in let res : compute_gen_elim_a (GEExistsNoAbs0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs0 body) res); res let rewrite_with_trefl (#opened:_) (p q:vprop) : STGhost unit opened p (fun _ -> q) (requires T.with_tactic T.trefl (p == q)) (ensures fun _ -> True) = rewrite p q let compute_gen_elim_f_exists_unit0 (a: Type0) (body: a -> gen_unit_elim_i) : Tot (gen_elim_t (GEExistsUnit0 body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit0 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x))); let gres = elim_exists () in let _ = compute_gen_unit_elim_f (body gres) _ in let res : compute_gen_elim_a (GEExistsUnit0 body) = U.raise_val (Ghost.reveal gres) in // coerce_with_trefl (Ghost.reveal gres) in rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit0 body) res); res let compute_gen_elim_f_exists0 (a: Type0) (body: a -> gen_elim_i) (f: (x: a) -> GTot (gen_elim_t (body x))) : Tot (gen_elim_t (GEExists0 body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p (GEExists0 body)) (exists_ (fun x -> compute_gen_elim_p (body x))); let gres1 = elim_exists () in let gres2 = f gres1 _ in let res : compute_gen_elim_a (GEExists0 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists0 body) res); res let compute_gen_elim_f_exists_no_abs1 (a: Type) (body: (a -> vprop)) : GTot (gen_elim_t (GEExistsNoAbs1 body)) = fun _ -> rewrite (compute_gen_elim_p (GEExistsNoAbs1 body)) (exists_ body); let gres = elim_exists () in let res : compute_gen_elim_a (GEExistsNoAbs1 body) = coerce_with_trefl (Ghost.reveal gres) in rewrite (body gres) (compute_gen_elim_q (GEExistsNoAbs1 body) res); res let compute_gen_elim_f_exists_unit1 (a: Type) (body: a -> gen_unit_elim_i) : Tot (gen_elim_t (GEExistsUnit1 body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p (GEExistsUnit1 body)) (exists_ (fun x -> compute_gen_unit_elim_p (body x))); let gres = elim_exists () in let _ = compute_gen_unit_elim_f (body gres) _ in let res : compute_gen_elim_a (GEExistsUnit1 body) = coerce_with_trefl (Ghost.reveal gres) in rewrite (compute_gen_unit_elim_q (body gres)) (compute_gen_elim_q (GEExistsUnit1 body) res); res let compute_gen_elim_f_exists1 (a: Type) (body: a -> gen_elim_i) (f: (x: a) -> GTot (gen_elim_t (body x))) : Tot (gen_elim_t (GEExists1 body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p (GEExists1 body)) (exists_ (fun x -> compute_gen_elim_p (body x))); let gres1 = elim_exists () in let gres2 = f gres1 _ in let res : compute_gen_elim_a (GEExists1 body) = coerce_with_trefl (Mkdtuple2 #a #(fun x -> compute_gen_elim_a (body x)) (Ghost.reveal gres1) (Ghost.reveal gres2)) in rewrite (compute_gen_elim_q (body gres1) gres2) (compute_gen_elim_q (GEExists1 body) res); res let rec compute_gen_elim_f (i: gen_elim_i) : GTot (gen_elim_t i) = match i returns (gen_elim_t i) with | GEUnit i -> compute_gen_elim_f_unit i | GEStarL i1 i2 -> compute_gen_elim_f_star_l i1 (compute_gen_elim_f i1) i2 | GEStarR i1 i2 -> compute_gen_elim_f_star_r i1 i2 (compute_gen_elim_f i2) | GEStar i1 i2 -> compute_gen_elim_f_star i1 (compute_gen_elim_f i1) i2 (compute_gen_elim_f i2) | GEExistsNoAbs0 body -> compute_gen_elim_f_exists_no_abs0 _ body | GEExistsUnit0 body -> compute_gen_elim_f_exists_unit0 _ body | GEExists0 body -> compute_gen_elim_f_exists0 _ body (fun x -> compute_gen_elim_f (body x)) | GEExistsNoAbs1 body -> compute_gen_elim_f_exists_no_abs1 _ body | GEExistsUnit1 body -> compute_gen_elim_f_exists_unit1 _ body | GEExists1 body -> compute_gen_elim_f_exists1 _ body (fun x -> compute_gen_elim_f (body x)) let rec tele_p (x: gen_elim_tele) : Tot vprop = match x with | TRet v p -> v `star` pure p | TExists ty body -> exists_ (fun x -> tele_p (body x)) let elim_exists' (#a:Type) (#opened_invariants:_) (#p:a -> vprop) (_:unit) : STGhostT (a) opened_invariants (exists_ p) (fun x -> p x) = let gx = elim_exists () in let x = Ghost.reveal gx in rewrite (p gx) (p x); x let vprop_rewrite (from to: vprop) : Tot Type = gen_elim_f from unit (fun _ -> to) (fun _ -> True) let tele_star_vprop_correct_ret (v': vprop) (p': prop) (v: vprop) (p: prop) : Tot (vprop_rewrite (tele_p (TRet v' p') `star` v `star` pure p) (tele_p (tele_star_vprop (TRet v' p') v p))) = fun _ -> elim_pure p; rewrite (tele_p _) (v' `star` pure p'); elim_pure p'; intro_pure (p /\ p'); rewrite ((v `star` v') `star` pure (p /\ p')) (tele_p _) let tele_star_vprop_correct_exists (v: vprop) (p: prop) (ty: _) (body: ty -> gen_elim_tele) (ih: (x: ty) -> GTot (vprop_rewrite (tele_p (body x) `star` v `star` pure p) (tele_p (tele_star_vprop (body x) v p)))) : Tot (vprop_rewrite (tele_p (TExists ty body) `star` v `star` pure p) (tele_p (tele_star_vprop (TExists ty body) v p))) = fun _ -> rewrite_with_trefl (tele_p _) (exists_ (fun x -> tele_p (body x))); let x = elim_exists' () in ih x _; intro_exists x (fun x -> tele_p (tele_star_vprop (body x) v p)); rewrite_with_trefl (exists_ (fun x -> tele_p (tele_star_vprop (body x) v p))) (tele_p _) let rec tele_star_vprop_correct (i: gen_elim_tele) (v: vprop) (p: prop) : GTot (vprop_rewrite (tele_p i `star` v `star` pure p) (tele_p (tele_star_vprop i v p)) ) = match i returns vprop_rewrite (tele_p i `star` v `star` pure p) (tele_p (tele_star_vprop i v p)) with | TRet v' p' -> tele_star_vprop_correct_ret v' p' v p | TExists ty body -> tele_star_vprop_correct_exists v p ty body (fun x -> tele_star_vprop_correct (body x) v p) let tele_star_correct_ret_l (v1: vprop) (p1: prop) (i2: gen_elim_tele) : Tot (vprop_rewrite (tele_p (TRet v1 p1) `star` tele_p i2) (tele_p (TRet v1 p1 `tele_star` i2))) = fun _ -> rewrite (tele_p (TRet v1 p1)) (v1 `star` pure p1); tele_star_vprop_correct i2 v1 p1 _; rewrite (tele_p _) (tele_p _) let tele_star_correct_ret_r (i1: gen_elim_tele { ~ (TRet? i1) }) (v2: vprop) (p2: prop) : Tot (vprop_rewrite (tele_p i1 `star` tele_p (TRet v2 p2)) (tele_p (i1 `tele_star` TRet v2 p2))) = fun _ -> rewrite (tele_p (TRet v2 p2)) (v2 `star` pure p2); tele_star_vprop_correct i1 v2 p2 _; rewrite (tele_p _) (tele_p (i1 `tele_star` TRet v2 p2)) let tele_star_correct_exists (ty1: _) (f1: ty1 -> gen_elim_tele) (ty2: _) (f2: ty2 -> gen_elim_tele) (ih: (x1: ty1) -> (x2: ty2) -> GTot (vprop_rewrite (tele_p (f1 x1) `star` tele_p (f2 x2)) (tele_p (f1 x1 `tele_star` f2 x2)))) : Tot (vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p (TExists ty2 f2)) (tele_p (tele_star (TExists ty1 f1) (TExists ty2 f2)))) = fun _ -> rewrite_with_trefl (tele_p (TExists ty1 f1)) (exists_ (fun x1 -> tele_p (f1 x1))); let x1 = elim_exists' () in rewrite_with_trefl (tele_p (TExists ty2 f2)) (exists_ (fun x2 -> tele_p (f2 x2))); let x2 = elim_exists' () in ih x1 x2 _; intro_exists x2 (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2))); intro_exists x1 (fun x1 -> exists_ (fun x2 -> tele_p (tele_star (f1 x1) (f2 x2)))); rewrite_with_trefl (exists_ _) (tele_p _) let rec tele_star_correct (i1 i2: gen_elim_tele) : GTot (vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2))) = match i1 returns vprop_rewrite (tele_p i1 `star` tele_p i2) (tele_p (i1 `tele_star` i2)) with | TRet v1 p1 -> tele_star_correct_ret_l v1 p1 i2 | TExists ty1 f1 -> begin match i2 returns vprop_rewrite (tele_p (TExists ty1 f1) `star` tele_p i2) (tele_p (TExists ty1 f1 `tele_star` i2)) with | TRet v2 p2 -> tele_star_correct_ret_r (TExists ty1 f1) v2 p2 | TExists ty2 f2 -> tele_star_correct_exists ty1 f1 ty2 f2 (fun x1 x2 -> tele_star_correct (f1 x1) (f2 x2)) end [@@noextract_to "Plugin" ] let ge_to_tele_t (i: gen_elim_i) : Tot Type = vprop_rewrite (compute_gen_elim_p i) (tele_p (compute_gen_elim_tele i)) let compute_gen_elim_tele_correct_unit (v: gen_unit_elim_i) : Tot (ge_to_tele_t (GEUnit v)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p v); let _ = compute_gen_unit_elim_f v _ in intro_pure (compute_gen_unit_elim_post v); rewrite_with_trefl (compute_gen_unit_elim_q v `star` pure _) (tele_p _) let compute_gen_elim_tele_correct_star_l (l: gen_elim_i) (ihl: ge_to_tele_t l) (ru: gen_unit_elim_i) : Tot (ge_to_tele_t (GEStarL l ru)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_unit_elim_p ru); ihl _; let _ = compute_gen_unit_elim_f ru _ in intro_pure (compute_gen_unit_elim_post ru); tele_star_vprop_correct _ _ _ _; rewrite_with_trefl (tele_p _) (tele_p _) let compute_gen_elim_tele_correct_star_r (lu: gen_unit_elim_i) (r: gen_elim_i) (ihr: ge_to_tele_t r) : Tot (ge_to_tele_t (GEStarR lu r)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_unit_elim_p lu `star` compute_gen_elim_p r); ihr _; let _ = compute_gen_unit_elim_f lu _ in intro_pure (compute_gen_unit_elim_post lu); tele_star_vprop_correct _ _ _ _; rewrite_with_trefl (tele_p _) (tele_p _) let compute_gen_elim_tele_correct_star (l: gen_elim_i) (ihl: ge_to_tele_t l) (r: gen_elim_i) (ihr: ge_to_tele_t r) : Tot (ge_to_tele_t (GEStar l r)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (compute_gen_elim_p l `star` compute_gen_elim_p r); ihl _; ihr _; tele_star_correct (compute_gen_elim_tele l) (compute_gen_elim_tele r) _; rewrite_with_trefl (tele_p _) (tele_p _) let compute_gen_elim_tele_correct_exists_no_abs0 (ty: _) (body: ty -> vprop) : Tot (ge_to_tele_t (GEExistsNoAbs0 #ty body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (exists_ body); let x = elim_exists' () in intro_pure True; rewrite (body x) (body (U.downgrade_val (U.raise_val x))); intro_exists (U.raise_val u#0 u#1 x) (fun x -> body (U.downgrade_val x) `star` pure True); rewrite_with_trefl (exists_ _) (tele_p _) let compute_gen_elim_tele_correct_exists_unit0 (ty: _) (body: ty -> gen_unit_elim_i) : Tot (ge_to_tele_t (GEExistsUnit0 #ty body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x))); let x = elim_exists' () in let _ = compute_gen_unit_elim_f (body x) _ in intro_pure (compute_gen_unit_elim_post (body (U.downgrade_val (U.raise_val u#0 u#1 x)))); rewrite (compute_gen_unit_elim_q (body x)) (compute_gen_unit_elim_q (body (U.downgrade_val (U.raise_val x)))); intro_exists (U.raise_val u#0 u#1 x) (fun x -> compute_gen_unit_elim_q (body (U.downgrade_val x)) `star` pure (compute_gen_unit_elim_post (body (U.downgrade_val x)))); rewrite_with_trefl (exists_ _) (tele_p _) let compute_gen_elim_tele_correct_exists0 (ty: _) (body: ty -> gen_elim_i) (ih: (x: ty) -> GTot (ge_to_tele_t (body x))) : Tot (ge_to_tele_t (GEExists0 #ty body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x))); let x = elim_exists' () in ih x _; rewrite (tele_p (compute_gen_elim_tele (body x))) (tele_p (compute_gen_elim_tele (body (U.downgrade_val (U.raise_val u#0 u#1 x))))); intro_exists (U.raise_val u#0 u#1 x) (fun x -> tele_p (compute_gen_elim_tele (body (U.downgrade_val u#0 u#1 x)))); rewrite_with_trefl (exists_ _) (tele_p _) let compute_gen_elim_tele_correct_exists_no_abs1 (ty: _) (body: ty -> vprop) : Tot (ge_to_tele_t (GEExistsNoAbs1 #ty body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (exists_ body); let x = elim_exists' () in intro_pure True; intro_exists x (fun x -> body x `star` pure True); rewrite_with_trefl (exists_ _) (tele_p _) let compute_gen_elim_tele_correct_exists_unit1 (ty: _) (body: ty -> gen_unit_elim_i) : Tot (ge_to_tele_t (GEExistsUnit1 #ty body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_unit_elim_p (body x))); let x = elim_exists' () in let _ = compute_gen_unit_elim_f (body x) _ in intro_pure (compute_gen_unit_elim_post (body x)); intro_exists x (fun x -> compute_gen_unit_elim_q (body x) `star` pure (compute_gen_unit_elim_post (body x))); rewrite_with_trefl (exists_ _) (tele_p _) let compute_gen_elim_tele_correct_exists1 (ty: _) (body: ty -> gen_elim_i) (ih: (x: ty) -> GTot (ge_to_tele_t (body x))) : Tot (ge_to_tele_t (GEExists1 #ty body)) = fun _ -> rewrite_with_trefl (compute_gen_elim_p _) (exists_ (fun x -> compute_gen_elim_p (body x))); let x = elim_exists' () in ih x _; intro_exists x (fun x -> tele_p (compute_gen_elim_tele (body x))); rewrite_with_trefl (exists_ _) (tele_p _) let rec compute_gen_elim_tele_correct (x: gen_elim_i) : GTot (ge_to_tele_t x) = match x returns ge_to_tele_t x with | GEUnit v -> compute_gen_elim_tele_correct_unit v | GEStarL l ru -> compute_gen_elim_tele_correct_star_l l (compute_gen_elim_tele_correct l) ru | GEStarR lu r -> compute_gen_elim_tele_correct_star_r lu r (compute_gen_elim_tele_correct r) | GEStar l r -> compute_gen_elim_tele_correct_star l (compute_gen_elim_tele_correct l) r (compute_gen_elim_tele_correct r) | GEExistsNoAbs0 #ty body -> compute_gen_elim_tele_correct_exists_no_abs0 ty body | GEExistsUnit0 #ty body -> compute_gen_elim_tele_correct_exists_unit0 ty body | GEExists0 #ty body -> compute_gen_elim_tele_correct_exists0 ty body (fun x -> compute_gen_elim_tele_correct (body x)) | GEExistsNoAbs1 #ty body -> compute_gen_elim_tele_correct_exists_no_abs1 ty body | GEExistsUnit1 #ty body -> compute_gen_elim_tele_correct_exists_unit1 ty body | GEExists1 #ty body -> compute_gen_elim_tele_correct_exists1 ty body (fun x -> compute_gen_elim_tele_correct (body x)) let rec gen_elim_nondep_p (ty: list (Type u#a)) : Tot (curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop) = match ty as ty' returns curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> vprop) -> curried_function_type ty' (U.raise_t u#_ u#(max 2 a) unit -> prop) -> Tot vprop with | [] -> fun q post -> q (U.raise_val ()) `star` pure (post (U.raise_val ())) | t :: tq -> fun q post -> exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x)) let rec gen_elim_nondep_sem_correct (ty: list (Type u#a)) : Tot ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma (tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post) ) = match ty returns ((q: curried_function_type ty _) -> (post: curried_function_type ty _) -> Lemma (tele_p (gen_elim_nondep_sem ty q post) `equiv` gen_elim_nondep_p ty q post) ) with | [] -> fun q post -> equiv_refl (q (U.raise_val ()) `star` pure (post (U.raise_val ()))) | ta :: tq -> fun q post -> let phi (x: ta) : Lemma (tele_p (gen_elim_nondep_sem tq (q x) (post x)) `equiv` gen_elim_nondep_p tq (q x) (post x)) = gen_elim_nondep_sem_correct tq (q x) (post x) in Classical.forall_intro phi; let prf () : Lemma (exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) `equiv` exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))) = exists_equiv (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x))) (fun x -> gen_elim_nondep_p tq (q x) (post x)) in assert_norm (tele_p (gen_elim_nondep_sem (ta :: tq) q post) == exists_ (fun x -> tele_p (gen_elim_nondep_sem tq (q x) (post x)))); assert_norm (gen_elim_nondep_p (ta :: tq) q post == exists_ (fun x -> gen_elim_nondep_p tq (q x) (post x))); prf () let compute_gen_elim_nondep_correct_t (i0: gen_elim_i) (ty: list (Type u#1)) : Tot Type = (q: _) -> (post: _) -> (intro: vprop_rewrite (compute_gen_elim_p i0) (gen_elim_nondep_p ty q post)) -> GTot (gen_elim_f (compute_gen_elim_p i0) (compute_gen_elim_nondep_a' ty) (fun x -> compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) ty q x (U.raise_val ())) (fun x -> compute_uncurry _ (fun _ -> True) ty post x (U.raise_val ())) ) let compute_gen_elim_nondep_correct0 (i0: gen_elim_i) : Tot (compute_gen_elim_nondep_correct_t i0 []) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (q (U.raise_val ()) `star` pure (post (U.raise_val ()))); let res = U.raise_val () in elim_pure _; rewrite_with_trefl (q (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct1 (i0: gen_elim_i) (t1: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> q x1 (U.raise_val ()) `star` pure (post x1 (U.raise_val ())))); let res = elim_exists' () in elim_pure _; rewrite_with_trefl (q _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct2 (i0: gen_elim_i) (t1 t2: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> q x1 x2 (U.raise_val ()) `star` pure (post x1 x2 (U.raise_val ()))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let res = Mktuple2 x1 x2 in elim_pure _; rewrite_with_trefl (q _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct3 (i0: gen_elim_i) (t1 t2 t3: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> q x1 x2 x3 (U.raise_val ()) `star` pure (post x1 x2 x3 (U.raise_val ())))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let res = Mktuple3 x1 x2 x3 in elim_pure _; rewrite_with_trefl (q _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct4 (i0: gen_elim_i) (t1 t2 t3 t4: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> q x1 x2 x3 x4 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 (U.raise_val ()))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let res = Mktuple4 x1 x2 x3 x4 in elim_pure _; rewrite_with_trefl (q _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct5 (i0: gen_elim_i) (t1 t2 t3 t4 t5: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> q x1 x2 x3 x4 x5 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 (U.raise_val ())))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let x5 = elim_exists' () in let res = Mktuple5 x1 x2 x3 x4 x5 in elim_pure _; rewrite_with_trefl (q _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct6 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> q x1 x2 x3 x4 x5 x6 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 (U.raise_val ()))))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let x5 = elim_exists' () in let x6 = elim_exists' () in let res = Mktuple6 x1 x2 x3 x4 x5 x6 in elim_pure _; rewrite_with_trefl (q _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct7 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> q x1 x2 x3 x4 x5 x6 x7 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 (U.raise_val ())))))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let x5 = elim_exists' () in let x6 = elim_exists' () in let x7 = elim_exists' () in let res = Mktuple7 x1 x2 x3 x4 x5 x6 x7 in elim_pure _; rewrite_with_trefl (q _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res let compute_gen_elim_nondep_correct8 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8]) = fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> q x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()) `star` pure (post x1 x2 x3 x4 x5 x6 x7 x8 (U.raise_val ()))))))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let x5 = elim_exists' () in let x6 = elim_exists' () in let x7 = elim_exists' () in let x8 = elim_exists' () in let res = Mktuple8 x1 x2 x3 x4 x5 x6 x7 x8 in elim_pure _; rewrite_with_trefl (q _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Universe.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.GenElim1.fst" }
[ { "abbrev": true, "full_module": "FStar.Universe", "short_module": "U" }, { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Steel.ST.GenElim1.Base", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST", "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
i0: Steel.ST.GenElim1.Base.gen_elim_i -> t1: Type -> t2: Type -> t3: Type -> t4: Type -> t5: Type -> t6: Type -> t7: Type -> t8: Type -> t9: Type -> Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9]
Prims.Tot
[ "total" ]
[]
[ "Steel.ST.GenElim1.Base.gen_elim_i", "Steel.ST.GenElim1.Base.curried_function_type", "Prims.Cons", "Prims.Nil", "FStar.Universe.raise_t", "Prims.unit", "Steel.Effect.Common.vprop", "Prims.prop", "Steel.ST.GenElim1.vprop_rewrite", "Steel.ST.GenElim1.Base.compute_gen_elim_p", "Steel.ST.GenElim1.gen_elim_nondep_p", "Steel.Memory.inames", "Steel.ST.GenElim1.Base.compute_gen_elim_nondep_a'", "Steel.ST.GenElim1.rewrite_with_trefl", "FStar.Universe.raise_val", "Steel.ST.GenElim1.Base.compute_uncurry", "Steel.ST.GenElim1.Base.compute_gen_elim_p'", "Steel.ST.Util.elim_pure", "FStar.Pervasives.Native.tuple9", "FStar.Pervasives.Native.Mktuple9", "Steel.ST.GenElim1.elim_exists'", "Steel.Effect.Common.VStar", "Steel.ST.Util.pure", "Steel.ST.Util.exists_", "Steel.Effect.Common.star", "Steel.ST.GenElim1.compute_gen_elim_nondep_correct_t" ]
[]
false
false
false
false
false
let compute_gen_elim_nondep_correct9 (i0: gen_elim_i) (t1 t2 t3 t4 t5 t6 t7 t8 t9: Type) : Tot (compute_gen_elim_nondep_correct_t i0 [t1; t2; t3; t4; t5; t6; t7; t8; t9]) =
fun q post intro _ -> intro _; rewrite_with_trefl (gen_elim_nondep_p _ _ _) (exists_ (fun x1 -> exists_ (fun x2 -> exists_ (fun x3 -> exists_ (fun x4 -> exists_ (fun x5 -> exists_ (fun x6 -> exists_ (fun x7 -> exists_ (fun x8 -> exists_ (fun x9 -> (q x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ())) `star` (pure (post x1 x2 x3 x4 x5 x6 x7 x8 x9 (U.raise_val ()))))))))))))); let x1 = elim_exists' () in let x2 = elim_exists' () in let x3 = elim_exists' () in let x4 = elim_exists' () in let x5 = elim_exists' () in let x6 = elim_exists' () in let x7 = elim_exists' () in let x8 = elim_exists' () in let x9 = elim_exists' () in let res = Mktuple9 x1 x2 x3 x4 x5 x6 x7 x8 x9 in elim_pure _; rewrite_with_trefl (q _ _ _ _ _ _ _ _ _ (U.raise_val ())) (compute_uncurry _ (fun _ -> compute_gen_elim_p' i0) _ _ res (U.raise_val ())); res
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.splitAt_length
val splitAt_length (#a: Type) (n: nat) (l: list a) : Lemma (requires True) (ensures (let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n)) (decreases n)
val splitAt_length (#a: Type) (n: nat) (l: list a) : Lemma (requires True) (ensures (let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n)) (decreases n)
let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 42, "start_col": 0, "start_line": 24 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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
n: Prims.nat -> l: Prims.list a -> FStar.Pervasives.Lemma (ensures (let _ = FStar.List.Tot.Base.splitAt n l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l_1 l_2 = _ in (match FStar.List.Tot.Base.length l < n with | true -> FStar.List.Tot.Base.length l_1 == FStar.List.Tot.Base.length l /\ FStar.List.Tot.Base.length l_2 == 0 | _ -> FStar.List.Tot.Base.length l_1 == n /\ FStar.List.Tot.Base.length l_2 = FStar.List.Tot.Base.length l - n) <: Type0) <: Type0)) (decreases n)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.nat", "Prims.list", "Prims.op_Equality", "Prims.int", "Prims.bool", "FStar.List.Pure.Properties.splitAt_length", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.l_and", "Prims.eq2", "Prims.b2t", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec splitAt_length (#a: Type) (n: nat) (l: list a) : Lemma (requires True) (ensures (let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n)) (decreases n) =
if n = 0 then () else match l with | [] -> () | _ :: xs -> splitAt_length (n - 1) xs
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.splitAt_length_total
val splitAt_length_total (#a: Type) (l: list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l)
val splitAt_length_total (#a: Type) (l: list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l)
let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 69, "start_col": 0, "start_line": 64 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 -> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.splitAt (FStar.List.Tot.Base.length l) l == (l, [])) (decreases l)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.list", "FStar.List.Pure.Properties.splitAt_length_total", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "FStar.List.Tot.Base.length", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec splitAt_length_total (#a: Type) (l: list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) =
match l with | [] -> () | x :: xs -> splitAt_length_total xs
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.splitAt_assoc
val splitAt_assoc (#a: Type) (n1 n2: nat) (l: list a) : Lemma (requires True) (ensures (let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1 + n2) l in l1' == l1 @ l2 /\ l2' == l3)) (decreases n1)
val splitAt_assoc (#a: Type) (n1 n2: nat) (l: list a) : Lemma (requires True) (ensures (let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1 + n2) l in l1' == l1 @ l2 /\ l2' == l3)) (decreases n1)
let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 61, "start_col": 0, "start_line": 44 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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
n1: Prims.nat -> n2: Prims.nat -> l: Prims.list a -> FStar.Pervasives.Lemma (ensures (let _ = FStar.List.Tot.Base.splitAt n1 l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in let _ = FStar.List.Tot.Base.splitAt n2 l2 in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l2 l3 = _ in let _ = FStar.List.Tot.Base.splitAt (n1 + n2) l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l1' l2' = _ in l1' == l1 @ l2 /\ l2' == l3) <: Type0) <: Type0) <: Type0)) (decreases n1)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.nat", "Prims.list", "Prims.op_Equality", "Prims.int", "Prims.bool", "FStar.List.Pure.Properties.splitAt_assoc", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.eq2", "FStar.List.Tot.Base.op_At", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.op_Addition", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec splitAt_assoc (#a: Type) (n1 n2: nat) (l: list a) : Lemma (requires True) (ensures (let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1 + n2) l in l1' == l1 @ l2 /\ l2' == l3)) (decreases n1) =
if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1 - 1) n2 xs
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_append_splitAt
val lemma_append_splitAt (#t: Type) (l1 l2: list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2)))
val lemma_append_splitAt (#t: Type) (l1 l2: list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2)))
let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 94, "start_col": 0, "start_line": 89 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> l2: Prims.list t -> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.splitAt (FStar.List.Tot.Base.length l1) (l1 @ l2) == (l1, l2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "FStar.List.Pure.Properties.lemma_append_splitAt", "FStar.List.Tot.Base.tl", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "FStar.List.Tot.Base.length", "FStar.List.Tot.Base.append", "FStar.Pervasives.Native.Mktuple2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_append_splitAt (#t: Type) (l1 l2: list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) =
match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_splitAt
val lemma_splitAt (#t: Type) (l l1 l2: list t) (n: nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n)
val lemma_splitAt (#t: Type) (l l1 l2: list t) (n: nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n)
let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 101, "start_col": 0, "start_line": 98 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> l1: Prims.list t -> l2: Prims.list t -> n: Prims.nat{n <= FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (ensures FStar.List.Tot.Base.splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ FStar.List.Tot.Base.length l1 = n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "FStar.List.Pure.Properties.lemma_append_splitAt", "Prims.unit", "FStar.List.Pure.Properties.lemma_splitAt_append", "Prims.l_True", "Prims.squash", "Prims.l_iff", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "FStar.Pervasives.Native.Mktuple2", "Prims.l_and", "FStar.List.Tot.Base.op_At", "Prims.op_Equality", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_splitAt (#t: Type) (l l1 l2: list t) (n: nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) =
lemma_splitAt_append n l; lemma_append_splitAt l1 l2
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_splitAt_append
val lemma_splitAt_append (#a: Type) (n: nat) (l: list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n))
val lemma_splitAt_append (#a: Type) (n: nat) (l: list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n))
let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 84, "start_col": 0, "start_line": 74 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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
n: Prims.nat -> l: Prims.list a -> FStar.Pervasives.Lemma (requires n <= FStar.List.Tot.Base.length l) (ensures (let _ = FStar.List.Tot.Base.splitAt n l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l1 l2 = _ in l1 @ l2 == l /\ FStar.List.Tot.Base.length l1 = n) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.list", "Prims.int", "FStar.List.Pure.Properties.lemma_splitAt_append", "Prims.op_Subtraction", "Prims.unit", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "Prims.squash", "Prims.l_and", "Prims.eq2", "FStar.List.Tot.Base.append", "Prims.op_Equality", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_splitAt_append (#a: Type) (n: nat) (l: list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) =
match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n - 1) xs
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_splitAt_shorten_left
val lemma_splitAt_shorten_left (#t: Type) (l1 l2: list t) (i: nat{i <= length l1 /\ i <= length l2}) (j: nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2)))
val lemma_splitAt_shorten_left (#t: Type) (l1 l2: list t) (i: nat{i <= length l1 /\ i <= length l2}) (j: nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2)))
let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1)
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 128, "start_col": 0, "start_line": 120 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> l2: Prims.list t -> i: Prims.nat{i <= FStar.List.Tot.Base.length l1 /\ i <= FStar.List.Tot.Base.length l2} -> j: Prims.nat{j <= i} -> FStar.Pervasives.Lemma (requires FStar.Pervasives.Native.fst (FStar.List.Tot.Base.splitAt i l1) == FStar.Pervasives.Native.fst (FStar.List.Tot.Base.splitAt i l2)) (ensures FStar.Pervasives.Native.fst (FStar.List.Tot.Base.splitAt j l1) == FStar.Pervasives.Native.fst (FStar.List.Tot.Base.splitAt j l2))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "Prims.int", "FStar.List.Pure.Properties.lemma_splitAt_shorten_left", "FStar.List.Tot.Base.tl", "Prims.op_Subtraction", "Prims.unit", "Prims.eq2", "FStar.Pervasives.Native.fst", "FStar.List.Tot.Base.splitAt", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_splitAt_shorten_left (#t: Type) (l1 l2: list t) (i: nat{i <= length l1 /\ i <= length l2}) (j: nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) =
match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i - 1) (j - 1)
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_split3_index
val lemma_split3_index (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in b == index l n))
val lemma_split3_index (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in b == index l n))
let lemma_split3_index (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in b == index l n)) = lemma_splitAt_index_hd n l
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 179, "start_col": 0, "start_line": 173 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an [append] and a [cons] *) let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> n: Prims.nat{n < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (ensures (let _ = FStar.List.Tot.Base.split3 l n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ _ b _ = _ in b == FStar.List.Tot.Base.index l n) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "FStar.List.Pure.Properties.lemma_splitAt_index_hd", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.List.Tot.Base.index", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_split3_index (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in b == index l n)) =
lemma_splitAt_index_hd n l
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_splitAt_reindex_left
val lemma_splitAt_reindex_left (#t: Type) (i: nat) (l: list t) (j: nat) : Lemma (requires i <= length l /\ j < i) (ensures (let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j))
val lemma_splitAt_reindex_left (#t: Type) (i: nat) (l: list t) (j: nat) : Lemma (requires i <= length l /\ j < i) (ensures (let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j))
let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1)
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 141, "start_col": 0, "start_line": 132 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> l: Prims.list t -> j: Prims.nat -> FStar.Pervasives.Lemma (requires i <= FStar.List.Tot.Base.length l /\ j < i) (ensures (let _ = FStar.List.Tot.Base.splitAt i l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ left _ = _ in FStar.List.Pure.Properties.splitAt_length i l; j < FStar.List.Tot.Base.length left /\ FStar.List.Tot.Base.index left j == FStar.List.Tot.Base.index l j) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "Prims.int", "FStar.Pervasives.Native.tuple2", "FStar.List.Pure.Properties.lemma_splitAt_reindex_left", "Prims.op_Subtraction", "FStar.List.Tot.Base.tl", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "Prims.op_LessThan", "Prims.squash", "Prims.eq2", "FStar.List.Tot.Base.index", "FStar.List.Pure.Properties.splitAt_length", "FStar.List.Tot.Base.splitAt", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_splitAt_reindex_left (#t: Type) (i: nat) (l: list t) (j: nat) : Lemma (requires i <= length l /\ j < i) (ensures (let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) =
match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1)
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_splitAt_index_hd
val lemma_splitAt_index_hd (#t: Type) (n: nat) (l: list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n))
val lemma_splitAt_index_hd (#t: Type) (n: nat) (l: list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n))
let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l)
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 115, "start_col": 0, "start_line": 106 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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
n: Prims.nat -> l: Prims.list t -> FStar.Pervasives.Lemma (requires n < FStar.List.Tot.Base.length l) (ensures (let _ = FStar.List.Tot.Base.splitAt n l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ _ l2 = _ in FStar.List.Pure.Properties.splitAt_length n l; FStar.List.Tot.Base.length l2 > 0 /\ FStar.List.Tot.Base.hd l2 == FStar.List.Tot.Base.index l n) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.list", "Prims.int", "FStar.List.Pure.Properties.lemma_splitAt_index_hd", "Prims.op_Subtraction", "FStar.List.Tot.Base.tl", "Prims.unit", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.squash", "Prims.l_and", "Prims.op_GreaterThan", "Prims.eq2", "FStar.List.Tot.Base.hd", "FStar.List.Tot.Base.index", "FStar.List.Pure.Properties.splitAt_length", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_splitAt_index_hd (#t: Type) (n: nat) (l: list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) =
let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l)
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_split3_append
val lemma_split3_append (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in l == append a (b :: c)))
val lemma_split3_append (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in l == append a (b :: c)))
let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 169, "start_col": 0, "start_line": 163 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> n: Prims.nat{n < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (ensures (let _ = FStar.List.Tot.Base.split3 l n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a b c = _ in l == a @ b :: c) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "FStar.List.Pure.Properties.lemma_splitAt_append", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.List.Tot.Base.append", "Prims.Cons", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_split3_append (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in l == append a (b :: c))) =
lemma_splitAt_append n l
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_split3_r_hd
val lemma_split3_r_hd (#t: Type) (l: list t) (i: nat{i < length l}) : Lemma (ensures (let a, b, c = split3 l i in lemma_split3_length l i; length c > 0 ==> i + 1 < length l /\ hd c == index l (i + 1)))
val lemma_split3_r_hd (#t: Type) (l: list t) (i: nat{i < length l}) : Lemma (ensures (let a, b, c = split3 l i in lemma_split3_length l i; length c > 0 ==> i + 1 < length l /\ hd c == index l (i + 1)))
let rec lemma_split3_r_hd (#t:Type) (l:list t) (i:nat{i < length l}) : Lemma (ensures (let a, b, c = split3 l i in lemma_split3_length l i; length c > 0 ==> i + 1 < length l /\ hd c == index l (i + 1))) = match i with | 0 -> () | _ -> lemma_split3_r_hd (tl l) (i - 1)
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 275, "start_col": 0, "start_line": 268 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an [append] and a [cons] *) let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l (** The middle element returned via [split3] is the [n]th [index]ed element *) let lemma_split3_index (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in b == index l n)) = lemma_splitAt_index_hd n l (** The lengths of the left and right parts of a [split3] are as expected. *) let lemma_split3_length (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1)) = splitAt_length n l (** If we [split3] on lists with the same left prefix, we get the same element and left prefix. *) let lemma_split3_on_same_leftprefix (#t:Type) (l1 l2:list t) (n:nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n+1) l1) == fst (splitAt (n+1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2)) = let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in lemma_split3_append l1 n; lemma_split3_append l2 n; lemma_split3_length l1 n; lemma_split3_length l2 n; append_l_cons b1 c1 a1; append_l_cons b2 c2 a2; // assert ((a1 @ [b1]) @ c1 == l1); // assert ((a2 @ [b2]) @ c2 == l2); let x1, y1 = splitAt (n+1) l1 in let x2, y2 = splitAt (n+1) l2 in lemma_splitAt_append (n+1) l1; lemma_splitAt_append (n+1) l2; splitAt_length (n+1) l1; splitAt_length (n+1) l2; // assert (x1 @ y1 == (a1 @ [b1]) @ c1); // assert (x2 @ y2 == (a2 @ [b2]) @ c2); append_length_inv_head x1 y1 (append a1 [b1]) c1; append_length_inv_head x2 y2 (append a2 [b2]) c2; // assert (a1 @ [b1] == a2 @ [b2]); append_length_inv_tail a1 [b1] a2 [b2]; // assert (a1 == a2 /\ b1 == b2); () (** If we perform an [unsnoc] on a list, then the left part is the same as an [append]+[cons] on the list after [split3]. *) let rec lemma_split3_unsnoc (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires (n <> length l - 1)) (ensures ( let a, b, c = split3 l n in lemma_split3_length l n; length c > 0 /\ ( let xs, x = unsnoc l in let ys, y = unsnoc c in append a (b :: ys) == xs))) = match n with | 0 -> () | _ -> lemma_split3_unsnoc (tl l) (n-1) (** Doing [unsnoc] and [split3] in either order leads to the same left part, and element. *) let lemma_unsnoc_split3 (#t:Type) (l:list t) (i:nat{i < length l}) : Lemma (requires (i <> length l - 1)) (ensures ( let xs, x = unsnoc l in i < length xs /\ ( let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in a0 == a1 /\ b0 == b1))) = let xs, x = unsnoc l in lemma_unsnoc_length l; let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in splitAt_length_total xs; // assert (fst (splitAt (length xs) xs) == xs); // assert (fst (splitAt (length xs) xs) == fst (splitAt (length xs) l)); // assert (i+1 <= length xs); lemma_splitAt_shorten_left xs l (length xs) (i+1); // assert (fst (splitAt (i+1) xs) == fst (splitAt (i+1) l)); lemma_split3_on_same_leftprefix l xs i
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> i: Prims.nat{i < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (ensures (let _ = FStar.List.Tot.Base.split3 l i in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ _ _ c = _ in FStar.List.Pure.Properties.lemma_split3_length l i; FStar.List.Tot.Base.length c > 0 ==> i + 1 < FStar.List.Tot.Base.length l /\ FStar.List.Tot.Base.hd c == FStar.List.Tot.Base.index l (i + 1)) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.int", "FStar.List.Pure.Properties.lemma_split3_r_hd", "FStar.List.Tot.Base.tl", "Prims.op_Subtraction", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.op_GreaterThan", "Prims.l_and", "Prims.op_Addition", "Prims.eq2", "FStar.List.Tot.Base.hd", "FStar.List.Tot.Base.index", "FStar.List.Pure.Properties.lemma_split3_length", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_split3_r_hd (#t: Type) (l: list t) (i: nat{i < length l}) : Lemma (ensures (let a, b, c = split3 l i in lemma_split3_length l i; length c > 0 ==> i + 1 < length l /\ hd c == index l (i + 1))) =
match i with | 0 -> () | _ -> lemma_split3_r_hd (tl l) (i - 1)
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_splitAt_reindex_right
val lemma_splitAt_reindex_right (#t: Type) (i: nat) (l: list t) (j: nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures (let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i)))
val lemma_splitAt_reindex_right (#t: Type) (i: nat) (l: list t) (j: nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures (let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i)))
let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 155, "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. *) module FStar.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> l: Prims.list t -> j: Prims.nat -> FStar.Pervasives.Lemma (requires i <= FStar.List.Tot.Base.length l /\ j + i < FStar.List.Tot.Base.length l) (ensures (let _ = FStar.List.Tot.Base.splitAt i l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ _ right = _ in FStar.List.Pure.Properties.splitAt_length i l; j < FStar.List.Tot.Base.length right /\ FStar.List.Tot.Base.index right j == FStar.List.Tot.Base.index l (j + i)) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.list", "Prims.int", "FStar.List.Pure.Properties.lemma_splitAt_reindex_right", "Prims.op_Subtraction", "FStar.List.Tot.Base.tl", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "Prims.op_LessThan", "Prims.op_Addition", "Prims.squash", "Prims.eq2", "FStar.List.Tot.Base.index", "FStar.List.Pure.Properties.splitAt_length", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_splitAt_reindex_right (#t: Type) (i: nat) (l: list t) (j: nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures (let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) =
match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_unsnoc_split3
val lemma_unsnoc_split3 (#t: Type) (l: list t) (i: nat{i < length l}) : Lemma (requires (i <> length l - 1)) (ensures (let xs, x = unsnoc l in i < length xs /\ (let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in a0 == a1 /\ b0 == b1)))
val lemma_unsnoc_split3 (#t: Type) (l: list t) (i: nat{i < length l}) : Lemma (requires (i <> length l - 1)) (ensures (let xs, x = unsnoc l in i < length xs /\ (let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in a0 == a1 /\ b0 == b1)))
let lemma_unsnoc_split3 (#t:Type) (l:list t) (i:nat{i < length l}) : Lemma (requires (i <> length l - 1)) (ensures ( let xs, x = unsnoc l in i < length xs /\ ( let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in a0 == a1 /\ b0 == b1))) = let xs, x = unsnoc l in lemma_unsnoc_length l; let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in splitAt_length_total xs; // assert (fst (splitAt (length xs) xs) == xs); // assert (fst (splitAt (length xs) xs) == fst (splitAt (length xs) l)); // assert (i+1 <= length xs); lemma_splitAt_shorten_left xs l (length xs) (i+1); // assert (fst (splitAt (i+1) xs) == fst (splitAt (i+1) l)); lemma_split3_on_same_leftprefix l xs i
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 265, "start_col": 0, "start_line": 246 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an [append] and a [cons] *) let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l (** The middle element returned via [split3] is the [n]th [index]ed element *) let lemma_split3_index (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in b == index l n)) = lemma_splitAt_index_hd n l (** The lengths of the left and right parts of a [split3] are as expected. *) let lemma_split3_length (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1)) = splitAt_length n l (** If we [split3] on lists with the same left prefix, we get the same element and left prefix. *) let lemma_split3_on_same_leftprefix (#t:Type) (l1 l2:list t) (n:nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n+1) l1) == fst (splitAt (n+1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2)) = let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in lemma_split3_append l1 n; lemma_split3_append l2 n; lemma_split3_length l1 n; lemma_split3_length l2 n; append_l_cons b1 c1 a1; append_l_cons b2 c2 a2; // assert ((a1 @ [b1]) @ c1 == l1); // assert ((a2 @ [b2]) @ c2 == l2); let x1, y1 = splitAt (n+1) l1 in let x2, y2 = splitAt (n+1) l2 in lemma_splitAt_append (n+1) l1; lemma_splitAt_append (n+1) l2; splitAt_length (n+1) l1; splitAt_length (n+1) l2; // assert (x1 @ y1 == (a1 @ [b1]) @ c1); // assert (x2 @ y2 == (a2 @ [b2]) @ c2); append_length_inv_head x1 y1 (append a1 [b1]) c1; append_length_inv_head x2 y2 (append a2 [b2]) c2; // assert (a1 @ [b1] == a2 @ [b2]); append_length_inv_tail a1 [b1] a2 [b2]; // assert (a1 == a2 /\ b1 == b2); () (** If we perform an [unsnoc] on a list, then the left part is the same as an [append]+[cons] on the list after [split3]. *) let rec lemma_split3_unsnoc (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires (n <> length l - 1)) (ensures ( let a, b, c = split3 l n in lemma_split3_length l n; length c > 0 /\ ( let xs, x = unsnoc l in let ys, y = unsnoc c in append a (b :: ys) == xs))) = match n with | 0 -> () | _ -> lemma_split3_unsnoc (tl l) (n-1) (** Doing [unsnoc] and [split3] in either order leads to the same left
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> i: Prims.nat{i < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (requires i <> FStar.List.Tot.Base.length l - 1) (ensures (let _ = FStar.List.Tot.Base.unsnoc l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ xs _ = _ in i < FStar.List.Tot.Base.length xs /\ (let _ = FStar.List.Tot.Base.split3 l i in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a0 b0 _ = _ in let _ = FStar.List.Tot.Base.split3 xs i in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a1 b1 _ = _ in a0 == a1 /\ b0 == b1) <: Prims.logical) <: Prims.logical)) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "FStar.List.Pure.Properties.lemma_split3_on_same_leftprefix", "Prims.unit", "FStar.List.Pure.Properties.lemma_splitAt_shorten_left", "Prims.op_Addition", "FStar.List.Pure.Properties.splitAt_length_total", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "FStar.List.Tot.Properties.lemma_unsnoc_length", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.unsnoc", "Prims.op_disEquality", "Prims.int", "Prims.op_Subtraction", "Prims.squash", "Prims.l_and", "Prims.eq2", "Prims.logical", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_unsnoc_split3 (#t: Type) (l: list t) (i: nat{i < length l}) : Lemma (requires (i <> length l - 1)) (ensures (let xs, x = unsnoc l in i < length xs /\ (let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in a0 == a1 /\ b0 == b1))) =
let xs, x = unsnoc l in lemma_unsnoc_length l; let a0, b0, c0 = split3 l i in let a1, b1, c1 = split3 xs i in splitAt_length_total xs; lemma_splitAt_shorten_left xs l (length xs) (i + 1); lemma_split3_on_same_leftprefix l xs i
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_split3_unsnoc
val lemma_split3_unsnoc (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires (n <> length l - 1)) (ensures (let a, b, c = split3 l n in lemma_split3_length l n; length c > 0 /\ (let xs, x = unsnoc l in let ys, y = unsnoc c in append a (b :: ys) == xs)))
val lemma_split3_unsnoc (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires (n <> length l - 1)) (ensures (let a, b, c = split3 l n in lemma_split3_length l n; length c > 0 /\ (let xs, x = unsnoc l in let ys, y = unsnoc c in append a (b :: ys) == xs)))
let rec lemma_split3_unsnoc (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires (n <> length l - 1)) (ensures ( let a, b, c = split3 l n in lemma_split3_length l n; length c > 0 /\ ( let xs, x = unsnoc l in let ys, y = unsnoc c in append a (b :: ys) == xs))) = match n with | 0 -> () | _ -> lemma_split3_unsnoc (tl l) (n-1)
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 241, "start_col": 0, "start_line": 229 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an [append] and a [cons] *) let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l (** The middle element returned via [split3] is the [n]th [index]ed element *) let lemma_split3_index (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in b == index l n)) = lemma_splitAt_index_hd n l (** The lengths of the left and right parts of a [split3] are as expected. *) let lemma_split3_length (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1)) = splitAt_length n l (** If we [split3] on lists with the same left prefix, we get the same element and left prefix. *) let lemma_split3_on_same_leftprefix (#t:Type) (l1 l2:list t) (n:nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n+1) l1) == fst (splitAt (n+1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2)) = let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in lemma_split3_append l1 n; lemma_split3_append l2 n; lemma_split3_length l1 n; lemma_split3_length l2 n; append_l_cons b1 c1 a1; append_l_cons b2 c2 a2; // assert ((a1 @ [b1]) @ c1 == l1); // assert ((a2 @ [b2]) @ c2 == l2); let x1, y1 = splitAt (n+1) l1 in let x2, y2 = splitAt (n+1) l2 in lemma_splitAt_append (n+1) l1; lemma_splitAt_append (n+1) l2; splitAt_length (n+1) l1; splitAt_length (n+1) l2; // assert (x1 @ y1 == (a1 @ [b1]) @ c1); // assert (x2 @ y2 == (a2 @ [b2]) @ c2); append_length_inv_head x1 y1 (append a1 [b1]) c1; append_length_inv_head x2 y2 (append a2 [b2]) c2; // assert (a1 @ [b1] == a2 @ [b2]); append_length_inv_tail a1 [b1] a2 [b2]; // assert (a1 == a2 /\ b1 == b2); () (** If we perform an [unsnoc] on a list, then the left part is the same
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> n: Prims.nat{n < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (requires n <> FStar.List.Tot.Base.length l - 1) (ensures (let _ = FStar.List.Tot.Base.split3 l n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a b c = _ in FStar.List.Pure.Properties.lemma_split3_length l n; FStar.List.Tot.Base.length c > 0 /\ (let _ = FStar.List.Tot.Base.unsnoc l in (let FStar.Pervasives.Native.Mktuple2 #_ #_ xs _ = _ in let _ = FStar.List.Tot.Base.unsnoc c in (let FStar.Pervasives.Native.Mktuple2 #_ #_ ys _ = _ in a @ b :: ys == xs) <: Prims.logical) <: Prims.logical)) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.int", "FStar.List.Pure.Properties.lemma_split3_unsnoc", "FStar.List.Tot.Base.tl", "Prims.op_Subtraction", "Prims.unit", "Prims.op_disEquality", "Prims.squash", "Prims.l_and", "Prims.op_GreaterThan", "Prims.eq2", "FStar.List.Tot.Base.append", "Prims.Cons", "Prims.logical", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.unsnoc", "FStar.List.Pure.Properties.lemma_split3_length", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_split3_unsnoc (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires (n <> length l - 1)) (ensures (let a, b, c = split3 l n in lemma_split3_length l n; length c > 0 /\ (let xs, x = unsnoc l in let ys, y = unsnoc c in append a (b :: ys) == xs))) =
match n with | 0 -> () | _ -> lemma_split3_unsnoc (tl l) (n - 1)
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.sel
val sel (#a #b: _) (m: map' a b) (x: a) : Tot (option (b x))
val sel (#a #b: _) (m: map' a b) (x: a) : Tot (option (b x))
let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 39, "start_col": 0, "start_line": 37 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.map' a b -> x: a -> FStar.Pervasives.Native.option (b x)
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.Map.map'", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let sel #a #b (m: map' a b) (x: a) : Tot (option (b x)) =
m x
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_split3_on_same_leftprefix
val lemma_split3_on_same_leftprefix (#t: Type) (l1 l2: list t) (n: nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n + 1) l1) == fst (splitAt (n + 1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2))
val lemma_split3_on_same_leftprefix (#t: Type) (l1 l2: list t) (n: nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n + 1) l1) == fst (splitAt (n + 1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2))
let lemma_split3_on_same_leftprefix (#t:Type) (l1 l2:list t) (n:nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n+1) l1) == fst (splitAt (n+1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2)) = let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in lemma_split3_append l1 n; lemma_split3_append l2 n; lemma_split3_length l1 n; lemma_split3_length l2 n; append_l_cons b1 c1 a1; append_l_cons b2 c2 a2; // assert ((a1 @ [b1]) @ c1 == l1); // assert ((a2 @ [b2]) @ c2 == l2); let x1, y1 = splitAt (n+1) l1 in let x2, y2 = splitAt (n+1) l2 in lemma_splitAt_append (n+1) l1; lemma_splitAt_append (n+1) l2; splitAt_length (n+1) l1; splitAt_length (n+1) l2; // assert (x1 @ y1 == (a1 @ [b1]) @ c1); // assert (x2 @ y2 == (a2 @ [b2]) @ c2); append_length_inv_head x1 y1 (append a1 [b1]) c1; append_length_inv_head x2 y2 (append a2 [b2]) c2; // assert (a1 @ [b1] == a2 @ [b2]); append_length_inv_tail a1 [b1] a2 [b2]; // assert (a1 == a2 /\ b1 == b2); ()
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 224, "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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an [append] and a [cons] *) let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l (** The middle element returned via [split3] is the [n]th [index]ed element *) let lemma_split3_index (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in b == index l n)) = lemma_splitAt_index_hd n l (** The lengths of the left and right parts of a [split3] are as expected. *) let lemma_split3_length (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1)) = splitAt_length n l (** If we [split3] on lists with the same left prefix, we get the same
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> l2: Prims.list t -> n: Prims.nat{n < FStar.List.Tot.Base.length l1 /\ n < FStar.List.Tot.Base.length l2} -> FStar.Pervasives.Lemma (requires FStar.Pervasives.Native.fst (FStar.List.Tot.Base.splitAt (n + 1) l1) == FStar.Pervasives.Native.fst (FStar.List.Tot.Base.splitAt (n + 1) l2)) (ensures (let _ = FStar.List.Tot.Base.split3 l1 n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a1 b1 _ = _ in let _ = FStar.List.Tot.Base.split3 l2 n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a2 b2 _ = _ in a1 == a2 /\ b1 == b2) <: Type0) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "Prims.unit", "FStar.List.Tot.Properties.append_length_inv_tail", "Prims.Cons", "Prims.Nil", "FStar.List.Tot.Properties.append_length_inv_head", "FStar.List.Tot.Base.append", "FStar.List.Pure.Properties.splitAt_length", "Prims.op_Addition", "FStar.List.Pure.Properties.lemma_splitAt_append", "FStar.Pervasives.Native.tuple2", "FStar.List.Tot.Base.splitAt", "FStar.List.Tot.Properties.append_l_cons", "FStar.List.Pure.Properties.lemma_split3_length", "FStar.List.Pure.Properties.lemma_split3_append", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "Prims.eq2", "FStar.Pervasives.Native.fst", "Prims.squash", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lemma_split3_on_same_leftprefix (#t: Type) (l1 l2: list t) (n: nat{n < length l1 /\ n < length l2}) : Lemma (requires (fst (splitAt (n + 1) l1) == fst (splitAt (n + 1) l2))) (ensures (let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in a1 == a2 /\ b1 == b2)) =
let a1, b1, c1 = split3 l1 n in let a2, b2, c2 = split3 l2 n in lemma_split3_append l1 n; lemma_split3_append l2 n; lemma_split3_length l1 n; lemma_split3_length l2 n; append_l_cons b1 c1 a1; append_l_cons b2 c2 a2; let x1, y1 = splitAt (n + 1) l1 in let x2, y2 = splitAt (n + 1) l2 in lemma_splitAt_append (n + 1) l1; lemma_splitAt_append (n + 1) l2; splitAt_length (n + 1) l1; splitAt_length (n + 1) l2; append_length_inv_head x1 y1 (append a1 [b1]) c1; append_length_inv_head x2 y2 (append a2 [b2]) c2; append_length_inv_tail a1 [b1] a2 [b2]; ()
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.grows
val grows : FStar.Preorder.preorder (FStar.Monotonic.Map.map a b inv)
let grows #a #b #inv = grows_aux #a #b #inv
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 47, "start_col": 0, "start_line": 47 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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.Preorder.preorder (FStar.Monotonic.Map.map a b inv)
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.grows_aux", "FStar.Preorder.preorder", "FStar.Monotonic.Map.map" ]
[]
false
false
false
false
false
let grows #a #b #inv =
grows_aux #a #b #inv
false
FStar.List.Pure.Properties.fst
FStar.List.Pure.Properties.lemma_split3_length
val lemma_split3_length (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1))
val lemma_split3_length (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1))
let lemma_split3_length (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1)) = splitAt_length n l
{ "file_name": "ulib/FStar.List.Pure.Properties.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 189, "start_col": 0, "start_line": 183 }
(* 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.List.Pure.Properties open FStar.List.Tot.Base open FStar.List.Pure.Base open FStar.List.Tot.Properties (** Properties of splitAt *) let rec splitAt_length (#a:Type) (n:nat) (l:list a) : Lemma (requires True) (ensures begin let l_1, l_2 = splitAt n l in if length l < n then length l_1 == length l /\ length l_2 == 0 else length l_1 == n /\ length l_2 = length l - n end) (decreases n) = if n = 0 then () else match l with | [] -> () | _::xs -> splitAt_length (n-1) xs let rec splitAt_assoc (#a:Type) (n1 n2:nat) (l:list a) : Lemma (requires True) (ensures begin let l1, l2 = splitAt n1 l in let l2, l3 = splitAt n2 l2 in let l1', l2' = splitAt (n1+n2) l in l1' == l1 @ l2 /\ l2' == l3 end) (decreases n1) = if n1 = 0 then () else match l with | [] -> () | x :: xs -> splitAt_assoc (n1-1) n2 xs let rec splitAt_length_total (#a:Type) (l:list a) : Lemma (requires True) (ensures (splitAt (length l) l == (l, []))) (decreases l) = match l with | [] -> () | x :: xs -> splitAt_length_total xs (** If we [append] the two lists produced using a [splitAt], then we get back the original list *) let rec lemma_splitAt_append (#a:Type) (n:nat) (l:list a) : Lemma (requires n <= length l) (ensures (let l1, l2 = splitAt n l in append l1 l2 == l /\ length l1 = n)) = match n with | 0 -> () | _ -> match l with | [] -> () | x :: xs -> lemma_splitAt_append (n-1) xs (** If we [splitAt] the point at which two lists have been [append]ed, then we get back the original lists. *) let rec lemma_append_splitAt (#t:Type) (l1 l2:list t) : Lemma (ensures (splitAt (length l1) (append l1 l2) == (l1, l2))) = match l1 with | [] -> () | _ -> lemma_append_splitAt (tl l1) l2 (** Fully characterize behavior of [splitAt] in terms of more standard list concepts *) let lemma_splitAt (#t: Type) (l l1 l2:list t) (n:nat{n <= length l}) : Lemma (splitAt n l == (l1, l2) <==> l == l1 @ l2 /\ length l1 = n) = lemma_splitAt_append n l; lemma_append_splitAt l1 l2 (** The [hd] of the second list returned via [splitAt] is the [n]th element of the original list *) let rec lemma_splitAt_index_hd (#t:Type) (n:nat) (l:list t) : Lemma (requires (n < length l)) (ensures (let l1, l2 = splitAt n l in splitAt_length n l; length l2 > 0 /\ hd l2 == index l n)) = let x :: xs = l in match n with | 0 -> () | _ -> lemma_splitAt_index_hd (n - 1) (tl l) (** If two lists have the same left prefix, then shorter left prefixes are also the same. *) let rec lemma_splitAt_shorten_left (#t:Type) (l1 l2:list t) (i:nat{i <= length l1 /\ i <= length l2}) (j:nat{j <= i}) : Lemma (requires (fst (splitAt i l1) == fst (splitAt i l2))) (ensures (fst (splitAt j l1) == fst (splitAt j l2))) = match j with | 0 -> () | _ -> lemma_splitAt_shorten_left (tl l1) (tl l2) (i-1) (j-1) (** Doing an [index] on the left-part of a [splitAt] is same as doing it on the original list *) let rec lemma_splitAt_reindex_left (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j < i) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length left /\ index left j == index l j)) = match i, j with | 1, _ | _, 0 -> () | _ -> lemma_splitAt_reindex_left (i - 1) (tl l) (j - 1) (** Doing an [index] on the right-part of a [splitAt] is same as doing it on the original list, but shifted *) let rec lemma_splitAt_reindex_right (#t:Type) (i:nat) (l:list t) (j:nat) : Lemma (requires i <= length l /\ j + i < length l) (ensures ( let left, right = splitAt i l in splitAt_length i l; j < length right /\ index right j == index l (j + i))) = match i with | 0 -> () | _ -> lemma_splitAt_reindex_right (i - 1) (tl l) j (** Properties of split3 *) (** The 3 pieces returned via [split3] can be joined together via an [append] and a [cons] *) let lemma_split3_append (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in l == append a (b :: c))) = lemma_splitAt_append n l (** The middle element returned via [split3] is the [n]th [index]ed element *) let lemma_split3_index (#t:Type) (l:list t) (n:nat{n < length l}) : Lemma (requires True) (ensures ( let a, b, c = split3 l n in b == index l n)) = lemma_splitAt_index_hd n l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.Properties.fst.checked", "FStar.List.Tot.Base.fst.checked", "FStar.List.Pure.Base.fst.checked" ], "interface_file": false, "source_file": "FStar.List.Pure.Properties.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot.Properties", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Tot.Base", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.List.Pure", "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 t -> n: Prims.nat{n < FStar.List.Tot.Base.length l} -> FStar.Pervasives.Lemma (ensures (let _ = FStar.List.Tot.Base.split3 l n in (let FStar.Pervasives.Native.Mktuple3 #_ #_ #_ a _ c = _ in FStar.List.Tot.Base.length a = n /\ FStar.List.Tot.Base.length c = FStar.List.Tot.Base.length l - n - 1) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.list", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "FStar.List.Pure.Properties.splitAt_length", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_and", "Prims.op_Equality", "Prims.int", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple3", "FStar.List.Tot.Base.split3", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let lemma_split3_length (#t: Type) (l: list t) (n: nat{n < length l}) : Lemma (requires True) (ensures (let a, b, c = split3 l n in length a = n /\ length c = length l - n - 1)) =
splitAt_length n l
false
FStar.Fin.fsti
FStar.Fin.fin
val fin : n: Prims.nat -> Type0
let fin (n: nat) = k: int {0 <= k /\ k < n}
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 36, "start_col": 0, "start_line": 36 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
n: Prims.nat -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan" ]
[]
false
false
false
true
true
let fin (n: nat) =
k: int{0 <= k /\ k < n}
false
FStar.Fin.fsti
FStar.Fin.under
val under : p: Prims.nat -> Type0
let under (p:nat) = x:nat {x<p}
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 42, "start_col": 0, "start_line": 42 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *) inline_for_extraction let fin (n: nat) = k: int {0 <= k /\ k < n} (** Newer synonym. We perhaps should choose one over another globally. [under] is also defined in IntegerIntervals.fst, along with other often used finite intervals. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
p: Prims.nat -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan" ]
[]
false
false
false
true
true
let under (p: nat) =
x: nat{x < p}
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.empty_map
val empty_map (a b: _) : Tot (map' a b)
val empty_map (a b: _) : Tot (map' a b)
let empty_map a b : Tot (map' a b) = fun x -> None
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 54, "start_col": 0, "start_line": 52 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv?
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
a: Type -> b: (_: a -> Type) -> FStar.Monotonic.Map.map' a b
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "FStar.Monotonic.Map.map'" ]
[]
false
false
false
false
false
let empty_map a b : Tot (map' a b) =
fun x -> None
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.fresh
val fresh (#r #a #b #inv: _) (m: t r a b inv) (x: a) (h: HS.mem) : GTot Type0
val fresh (#r #a #b #inv: _) (m: t r a b inv) (x: a) (h: HS.mem) : GTot Type0
let fresh #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = None? (sel (HS.sel h m) x)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 80, "start_col": 0, "start_line": 78 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) (** A library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b) let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) let contains #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y let value #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem{defined m x h}) : GTot (r:b x{contains m x r h}) = Some?.v (sel (HS.sel h m) x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.HyperStack.ST.erid", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.Monotonic.HyperStack.mem", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "FStar.Monotonic.Map.sel", "FStar.Monotonic.HyperStack.sel", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows" ]
[]
false
false
false
false
true
let fresh #r #a #b #inv (m: t r a b inv) (x: a) (h: HS.mem) : GTot Type0 =
None? (sel (HS.sel h m) x)
false
FStar.Fin.fsti
FStar.Fin.in_
val in_ : s: FStar.Seq.Base.seq a -> Type0
let in_ (#a: Type) (s: S.seq a) = n: nat{n < S.length s}
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 54, "start_col": 0, "start_line": 54 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *) inline_for_extraction let fin (n: nat) = k: int {0 <= k /\ k < n} (** Newer synonym. We perhaps should choose one over another globally. [under] is also defined in IntegerIntervals.fst, along with other often used finite intervals. *) inline_for_extraction let under (p:nat) = x:nat {x<p} (** Length-indexed list *) inline_for_extraction let vect (n: nat) (a: Type) = l: list a {L.length l = n} (** Length-indexed sequence *) inline_for_extraction let seqn (n: nat) (a: Type) = s: S.seq a {S.length s = n} (** [in_ s] is the type of a valid index into the sequence [s] *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
s: FStar.Seq.Base.seq a -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Seq.Base.length" ]
[]
false
false
false
true
true
let in_ (#a: Type) (s: S.seq a) =
n: nat{n < S.length s}
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.defined
val defined (#r #a #b #inv: _) (m: t r a b inv) (x: a) (h: HS.mem) : GTot Type0
val defined (#r #a #b #inv: _) (m: t r a b inv) (x: a) (h: HS.mem) : GTot Type0
let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 68, "start_col": 0, "start_line": 66 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.HyperStack.ST.erid", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.Monotonic.HyperStack.mem", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Monotonic.Map.sel", "FStar.Monotonic.HyperStack.sel", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows" ]
[]
false
false
false
false
true
let defined #r #a #b #inv (m: t r a b inv) (x: a) (h: HS.mem) : GTot Type0 =
Some? (sel (HS.sel h m) x)
false
FStar.Fin.fsti
FStar.Fin.items_of
val items_of : eq: FStar.Fin.equivalence_relation a -> s: FStar.Seq.Base.seq a -> Type
let items_of #a (eq: equivalence_relation a) (s: S.seq a) = x:a { contains_eq eq s x }
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 133, "start_col": 0, "start_line": 132 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *) inline_for_extraction let fin (n: nat) = k: int {0 <= k /\ k < n} (** Newer synonym. We perhaps should choose one over another globally. [under] is also defined in IntegerIntervals.fst, along with other often used finite intervals. *) inline_for_extraction let under (p:nat) = x:nat {x<p} (** Length-indexed list *) inline_for_extraction let vect (n: nat) (a: Type) = l: list a {L.length l = n} (** Length-indexed sequence *) inline_for_extraction let seqn (n: nat) (a: Type) = s: S.seq a {S.length s = n} (** [in_ s] is the type of a valid index into the sequence [s] *) inline_for_extraction let in_ (#a: Type) (s: S.seq a) = n: nat{n < S.length s} (** Find an index of an element in [s] starting from [i] that validates [p] *) val find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) : Pure (option (in_ s)) (requires True) (ensures (function | None -> (forall (k: nat{i <= k /\ k < S.length s}). p (S.index s k) == false) | Some j -> i <= j /\ p (S.index s j))) (decreases (S.length s - i)) (** Given a sequence [s] all of whose elements are at most [n], if the length of [s] is greater than [n], then there are two distinct indexes in [s] that contain the same element *) val pigeonhole (#n: pos) (s: S.seq (under n)) : Pure (in_ s * in_ s) (requires S.length s = n + 1) (ensures (fun (i1, i2) -> i1 < i2 /\ S.index s i1 = S.index s i2)) (decreases n) (** Here we prepare to prove pigeonhole principle for a finite sequence with a custom equivalence relation (as opposed to eqtype). Think setoids. *) (** Following code is extracted from CuteCAS, which will eventually make its way into F* -- when I wrap things up with most important notions of abstract algebra. As I port more code from my CAS project to F*, such things will be moved to separate modules. -- Alex Rozanov *) inline_for_extraction type binary_relation (a: Type) = a -> a -> bool (** For performance reasons, forall definitions are best kept hidden from SMT. Use reveal_opaque when you really need it. Or use refl/trans/symm lemmas below to keep the context clean. *) val is_reflexive (#a:Type) (r: binary_relation a) : Type0 val is_symmetric (#a:Type) (r: binary_relation a) : Type0 val is_transitive (#a:Type) (r: binary_relation a) : Type0 val is_reflexive_intro (#a:Type) (r: binary_relation a) : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) val is_symmetric_intro (#a:Type) (r: binary_relation a) : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) val is_transitive_intro (#a:Type) (r: binary_relation a) : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) (** Textbook stuff on equivalence relations *) type equivalence_relation (a: Type) = r:binary_relation a { is_reflexive r /\ is_symmetric r /\ is_transitive r } val refl_lemma (#a:Type) (eq: equivalence_relation a) (x:a) : Lemma (eq x x) val symm_lemma (#a:Type) (eq:equivalence_relation a) (x y:a) : Lemma (eq x y == eq y x) val trans_lemma (#a:Type) (eq: equivalence_relation a) (x y z:a) : Lemma (requires (eq x y \/ eq y x) /\ (eq y z \/ eq z y)) (ensures (x `eq` z) && (z `eq` x)) (** (contains) predicate, but with custom comparison operation (a->a->bool) *) [@@"opaque_to_smt"] let contains_eq #a (eq: equivalence_relation a) (s: S.seq a) (x:a) = exists (i:under (S.length s)). eq x (S.index s i) val contains_eq_means_nonempty (#a:Type) (eq:equivalence_relation a) (s: S.seq a) (x:a) : Lemma (requires contains_eq eq s x) (ensures S.length s > 0) [SMTPat(contains_eq eq s x)]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
eq: FStar.Fin.equivalence_relation a -> s: FStar.Seq.Base.seq a -> Type
Prims.Tot
[ "total" ]
[]
[ "FStar.Fin.equivalence_relation", "FStar.Seq.Base.seq", "FStar.Fin.contains_eq" ]
[]
false
false
false
true
true
let items_of #a (eq: equivalence_relation a) (s: S.seq a) =
x: a{contains_eq eq s x}
false
FStar.Fin.fsti
FStar.Fin.contains_eq
val contains_eq : eq: FStar.Fin.equivalence_relation a -> s: FStar.Seq.Base.seq a -> x: a -> Prims.logical
let contains_eq #a (eq: equivalence_relation a) (s: S.seq a) (x:a) = exists (i:under (S.length s)). eq x (S.index s i)
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 124, "start_col": 0, "start_line": 123 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *) inline_for_extraction let fin (n: nat) = k: int {0 <= k /\ k < n} (** Newer synonym. We perhaps should choose one over another globally. [under] is also defined in IntegerIntervals.fst, along with other often used finite intervals. *) inline_for_extraction let under (p:nat) = x:nat {x<p} (** Length-indexed list *) inline_for_extraction let vect (n: nat) (a: Type) = l: list a {L.length l = n} (** Length-indexed sequence *) inline_for_extraction let seqn (n: nat) (a: Type) = s: S.seq a {S.length s = n} (** [in_ s] is the type of a valid index into the sequence [s] *) inline_for_extraction let in_ (#a: Type) (s: S.seq a) = n: nat{n < S.length s} (** Find an index of an element in [s] starting from [i] that validates [p] *) val find (#a: Type) (s: S.seq a) (p: (a -> bool)) (i: under (S.length s)) : Pure (option (in_ s)) (requires True) (ensures (function | None -> (forall (k: nat{i <= k /\ k < S.length s}). p (S.index s k) == false) | Some j -> i <= j /\ p (S.index s j))) (decreases (S.length s - i)) (** Given a sequence [s] all of whose elements are at most [n], if the length of [s] is greater than [n], then there are two distinct indexes in [s] that contain the same element *) val pigeonhole (#n: pos) (s: S.seq (under n)) : Pure (in_ s * in_ s) (requires S.length s = n + 1) (ensures (fun (i1, i2) -> i1 < i2 /\ S.index s i1 = S.index s i2)) (decreases n) (** Here we prepare to prove pigeonhole principle for a finite sequence with a custom equivalence relation (as opposed to eqtype). Think setoids. *) (** Following code is extracted from CuteCAS, which will eventually make its way into F* -- when I wrap things up with most important notions of abstract algebra. As I port more code from my CAS project to F*, such things will be moved to separate modules. -- Alex Rozanov *) inline_for_extraction type binary_relation (a: Type) = a -> a -> bool (** For performance reasons, forall definitions are best kept hidden from SMT. Use reveal_opaque when you really need it. Or use refl/trans/symm lemmas below to keep the context clean. *) val is_reflexive (#a:Type) (r: binary_relation a) : Type0 val is_symmetric (#a:Type) (r: binary_relation a) : Type0 val is_transitive (#a:Type) (r: binary_relation a) : Type0 val is_reflexive_intro (#a:Type) (r: binary_relation a) : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) val is_symmetric_intro (#a:Type) (r: binary_relation a) : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) val is_transitive_intro (#a:Type) (r: binary_relation a) : Lemma (requires forall (x:a). r x x) (ensures is_reflexive r) (** Textbook stuff on equivalence relations *) type equivalence_relation (a: Type) = r:binary_relation a { is_reflexive r /\ is_symmetric r /\ is_transitive r } val refl_lemma (#a:Type) (eq: equivalence_relation a) (x:a) : Lemma (eq x x) val symm_lemma (#a:Type) (eq:equivalence_relation a) (x y:a) : Lemma (eq x y == eq y x) val trans_lemma (#a:Type) (eq: equivalence_relation a) (x y z:a) : Lemma (requires (eq x y \/ eq y x) /\ (eq y z \/ eq z y)) (ensures (x `eq` z) && (z `eq` x)) (** (contains) predicate, but with custom comparison operation (a->a->bool) *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
eq: FStar.Fin.equivalence_relation a -> s: FStar.Seq.Base.seq a -> x: a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Fin.equivalence_relation", "FStar.Seq.Base.seq", "Prims.l_Exists", "FStar.Fin.under", "FStar.Seq.Base.length", "Prims.b2t", "FStar.Seq.Base.index", "Prims.logical" ]
[]
false
false
false
true
true
let contains_eq #a (eq: equivalence_relation a) (s: S.seq a) (x: a) =
exists (i: under (S.length s)). eq x (S.index s i)
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.upd
val upd (#a: eqtype) (#b: _) (m: map' a b) (x: a) (y: b x) : Tot (map' a b)
val upd (#a: eqtype) (#b: _) (m: map' a b) (x: a) (y: b x) : Tot (map' a b)
let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 35, "start_col": 0, "start_line": 33 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) (** A library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.map' a b -> x: a -> y: b x -> FStar.Monotonic.Map.map' a b
Prims.Tot
[ "total" ]
[]
[ "Prims.eqtype", "FStar.Monotonic.Map.map'", "Prims.op_Equality", "FStar.Pervasives.Native.Some", "Prims.bool", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let upd (#a: eqtype) #b (m: map' a b) (x: a) (y: b x) : Tot (map' a b) =
fun z -> if x = z then Some y else m z
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.grows_aux
val grows_aux (#a #b #inv: _) : Preorder.preorder (map a b inv)
val grows_aux (#a #b #inv: _) : Preorder.preorder (map a b inv)
let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 71, "end_line": 44, "start_col": 0, "start_line": 41 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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.Preorder.preorder (FStar.Monotonic.Map.map a b inv)
Prims.Tot
[ "total" ]
[]
[ "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.map", "Prims.l_Forall", "Prims.l_imp", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.__proj__Some__item__v", "Prims.logical", "FStar.Preorder.preorder" ]
[]
false
false
false
false
false
let grows_aux #a #b #inv : Preorder.preorder (map a b inv) =
fun (m1: map a b inv) (m2: map a b inv) -> forall x. {:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x)
false
FStar.UInt.fsti
FStar.UInt.max_int
val max_int (n: nat) : Tot int
val max_int (n: nat) : Tot int
let max_int (n:nat) : Tot int = pow2 n - 1
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 46, "start_col": 0, "start_line": 46 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
n: Prims.nat -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.op_Subtraction", "Prims.pow2", "Prims.int" ]
[]
false
false
false
true
false
let max_int (n: nat) : Tot int =
pow2 n - 1
false
FStar.UInt.fsti
FStar.UInt.min_int
val min_int (n: nat) : Tot int
val min_int (n: nat) : Tot int
let min_int (n:nat) : Tot int = 0
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 47, "start_col": 0, "start_line": 47 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
n: Prims.nat -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.int" ]
[]
false
false
false
true
false
let min_int (n: nat) : Tot int =
0
false
FStar.UInt.fsti
FStar.UInt.fits
val fits (x: int) (n: nat) : Tot bool
val fits (x: int) (n: nat) : Tot bool
let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 70, "end_line": 49, "start_col": 0, "start_line": 49 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
x: Prims.int -> n: Prims.nat -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.nat", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "FStar.UInt.min_int", "FStar.UInt.max_int", "Prims.bool" ]
[]
false
false
false
true
false
let fits (x: int) (n: nat) : Tot bool =
min_int n <= x && x <= max_int n
false
FStar.UInt.fsti
FStar.UInt.size
val size (x: int) (n: nat) : Tot Type0
val size (x: int) (n: nat) : Tot Type0
let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 52, "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. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
x: Prims.int -> n: Prims.nat -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.nat", "Prims.b2t", "FStar.UInt.fits" ]
[]
false
false
false
true
true
let size (x: int) (n: nat) : Tot Type0 =
b2t (fits x n)
false
FStar.Fin.fsti
FStar.Fin.vect
val vect : n: Prims.nat -> a: Type -> Type
let vect (n: nat) (a: Type) = l: list a {L.length l = n}
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 46, "start_col": 0, "start_line": 46 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *) inline_for_extraction let fin (n: nat) = k: int {0 <= k /\ k < n} (** Newer synonym. We perhaps should choose one over another globally. [under] is also defined in IntegerIntervals.fst, along with other often used finite intervals. *) inline_for_extraction let under (p:nat) = x:nat {x<p} (** Length-indexed list *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
n: Prims.nat -> a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.list", "Prims.b2t", "Prims.op_Equality", "FStar.List.Tot.Base.length" ]
[]
false
false
false
true
true
let vect (n: nat) (a: Type) =
l: list a {L.length l = n}
false
FStar.Fin.fsti
FStar.Fin.seqn
val seqn : n: Prims.nat -> a: Type -> Type
let seqn (n: nat) (a: Type) = s: S.seq a {S.length s = n}
{ "file_name": "ulib/FStar.Fin.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 57, "end_line": 50, "start_col": 0, "start_line": 50 }
(* Copyright 2008-2022 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.Fin /// This module is supposed to contain various lemmas about /// finiteness. For now, it mainly provides a basic pigeonhole /// principle /// /// TODO: We might generalize this to also support general utilities /// for reasoning about cardinality, relation with injections and /// surjections, etc. /// /// UPD. November 8, 2022 -- added support for custom equivalence relation-aware /// pigeon principle lemma. /// UPD. November 23, 2022 -- added interface file module L = FStar.List.Tot module S = FStar.Seq (** The type of natural numbers bounded by [n] *) inline_for_extraction let fin (n: nat) = k: int {0 <= k /\ k < n} (** Newer synonym. We perhaps should choose one over another globally. [under] is also defined in IntegerIntervals.fst, along with other often used finite intervals. *) inline_for_extraction let under (p:nat) = x:nat {x<p} (** Length-indexed list *) inline_for_extraction let vect (n: nat) (a: Type) = l: list a {L.length l = n} (** Length-indexed sequence *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "FStar.Fin.fsti" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "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
n: Prims.nat -> a: Type -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Seq.Base.seq", "Prims.b2t", "Prims.op_Equality", "FStar.Seq.Base.length" ]
[]
false
false
false
true
true
let seqn (n: nat) (a: Type) =
s: S.seq a {S.length s = n}
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.contains_stable
val contains_stable (#r #a #b #inv: _) (m: t r a b inv) (x: a) (y: b x) : Lemma (ensures (stable_on_t m (contains m x y)))
val contains_stable (#r #a #b #inv: _) (m: t r a b inv) (x: a) (y: b x) : Lemma (ensures (stable_on_t m (contains m x y)))
let contains_stable #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) : Lemma (ensures (stable_on_t m (contains m x y))) = reveal_opaque (`%grows) (grows #a #b #inv)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 46, "end_line": 84, "start_col": 0, "start_line": 82 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b) let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) let contains #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y let value #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem{defined m x h}) : GTot (r:b x{contains m x r h}) = Some?.v (sel (HS.sel h m) x) let fresh #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = None? (sel (HS.sel h m) x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> y: b x -> FStar.Pervasives.Lemma (ensures FStar.HyperStack.ST.stable_on_t m (FStar.Monotonic.Map.contains m x y))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.HyperStack.ST.erid", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.Pervasives.reveal_opaque", "FStar.Preorder.preorder", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.HyperStack.ST.stable_on_t", "FStar.Monotonic.Map.contains", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let contains_stable #r #a #b #inv (m: t r a b inv) (x: a) (y: b x) : Lemma (ensures (stable_on_t m (contains m x y))) =
reveal_opaque (`%grows) (grows #a #b #inv)
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.contains
val contains (#r #a #b #inv: _) (m: t r a b inv) (x: a) (y: b x) (h: HS.mem) : GTot Type0
val contains (#r #a #b #inv: _) (m: t r a b inv) (x: a) (y: b x) (h: HS.mem) : GTot Type0
let contains #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 67, "end_line": 72, "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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b) let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> y: b x -> h: FStar.Monotonic.HyperStack.mem -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.HyperStack.ST.erid", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Monotonic.Map.sel", "FStar.Monotonic.HyperStack.sel", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows", "Prims.eq2", "FStar.Pervasives.Native.__proj__Some__item__v" ]
[]
false
false
false
false
true
let contains #r #a #b #inv (m: t r a b inv) (x: a) (y: b x) (h: HS.mem) : GTot Type0 =
Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.value
val value (#r #a #b #inv: _) (m: t r a b inv) (x: a) (h: HS.mem{defined m x h}) : GTot (r: b x {contains m x r h})
val value (#r #a #b #inv: _) (m: t r a b inv) (x: a) (h: HS.mem{defined m x h}) : GTot (r: b x {contains m x r h})
let value #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem{defined m x h}) : GTot (r:b x{contains m x r h}) = Some?.v (sel (HS.sel h m) x)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 76, "start_col": 0, "start_line": 74 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b) let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) let contains #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> h: FStar.Monotonic.HyperStack.mem{FStar.Monotonic.Map.defined m x h} -> Prims.GTot (r: b x {FStar.Monotonic.Map.contains m x r h})
Prims.GTot
[ "sometrivial" ]
[]
[ "FStar.HyperStack.ST.erid", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.Monotonic.HyperStack.mem", "FStar.Monotonic.Map.defined", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.Monotonic.Map.sel", "FStar.Monotonic.HyperStack.sel", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows", "FStar.Monotonic.Map.contains" ]
[]
false
false
false
false
false
let value #r #a #b #inv (m: t r a b inv) (x: a) (h: HS.mem{defined m x h}) : GTot (r: b x {contains m x r h}) =
Some?.v (sel (HS.sel h m) x)
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.lookup
val lookup (#r #a #b #inv: _) (m: t r a b inv) (x: a) : ST (option (b x)) (requires (fun h -> True)) (ensures (fun h0 y h1 -> h0 == h1 /\ y == sel (HS.sel h1 m) x /\ (None? y ==> fresh m x h1) /\ (Some? y ==> defined m x h1 /\ contains m x (Some?.v y) h1 /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x (Some?.v y)))))
val lookup (#r #a #b #inv: _) (m: t r a b inv) (x: a) : ST (option (b x)) (requires (fun h -> True)) (ensures (fun h0 y h1 -> h0 == h1 /\ y == sel (HS.sel h1 m) x /\ (None? y ==> fresh m x h1) /\ (Some? y ==> defined m x h1 /\ contains m x (Some?.v y) h1 /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x (Some?.v y)))))
let lookup #r #a #b #inv (m:t r a b inv) (x:a) : ST (option (b x)) (requires (fun h -> True)) (ensures (fun h0 y h1 -> h0==h1 /\ y == sel (HS.sel h1 m) x /\ (None? y ==> fresh m x h1) /\ (Some? y ==> defined m x h1 /\ contains m x (Some?.v y) h1 /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x (Some?.v y))))) = reveal_opaque (`%grows) (grows #a #b #inv); let y = sel !m x in match y with | None -> y | Some b -> contains_stable m x b; mr_witness m (defined m x); mr_witness m (contains m x b); y
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 126, "start_col": 0, "start_line": 106 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b) let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) let contains #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y let value #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem{defined m x h}) : GTot (r:b x{contains m x r h}) = Some?.v (sel (HS.sel h m) x) let fresh #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = None? (sel (HS.sel h m) x) let contains_stable #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) : Lemma (ensures (stable_on_t m (contains m x y))) = reveal_opaque (`%grows) (grows #a #b #inv) let extend (#r:rid) (#a:eqtype) (#b:a -> Type) (#inv:(map' a b -> Type0)) (m:t r a b inv) (x:a) (y:b x) : ST unit (requires (fun h -> let cur = HS.sel h m in inv (upd cur x y) /\ sel cur x == None)) (ensures (fun h0 u h1 -> let cur = HS.sel h0 m in let hsref = m in HS.contains h1 m /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r (Set.singleton (HS.as_addr hsref)) h0 h1 /\ HS.sel h1 m == upd cur x y /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x y))) = recall m; reveal_opaque (`%grows) (grows #a #b #inv); let cur = !m in m := upd cur x y; contains_stable m x y; mr_witness m (defined m x); mr_witness m (contains m x y)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> FStar.HyperStack.ST.ST (FStar.Pervasives.Native.option (b x))
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.HyperStack.ST.erid", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.Pervasives.Native.option", "Prims.unit", "FStar.HyperStack.ST.mr_witness", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows", "FStar.Monotonic.Map.contains", "FStar.Monotonic.Map.defined", "FStar.Monotonic.Map.contains_stable", "FStar.Monotonic.Map.sel", "FStar.HyperStack.ST.op_Bang", "FStar.Pervasives.reveal_opaque", "FStar.Preorder.preorder", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "Prims.l_and", "Prims.eq2", "FStar.Monotonic.HyperStack.sel", "Prims.l_imp", "Prims.b2t", "FStar.Pervasives.Native.uu___is_None", "FStar.Monotonic.Map.fresh", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.__proj__Some__item__v", "FStar.HyperStack.ST.witnessed" ]
[]
false
true
false
false
false
let lookup #r #a #b #inv (m: t r a b inv) (x: a) : ST (option (b x)) (requires (fun h -> True)) (ensures (fun h0 y h1 -> h0 == h1 /\ y == sel (HS.sel h1 m) x /\ (None? y ==> fresh m x h1) /\ (Some? y ==> defined m x h1 /\ contains m x (Some?.v y) h1 /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x (Some?.v y))))) =
reveal_opaque (`%grows) (grows #a #b #inv); let y = sel !m x in match y with | None -> y | Some b -> contains_stable m x b; mr_witness m (defined m x); mr_witness m (contains m x b); y
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.alloc
val alloc (#r: rid) (#a #b #inv: _) : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1))
val alloc (#r: rid) (#a #b #inv: _) : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1))
let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 64, "start_col": 0, "start_line": 58 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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.HyperStack.ST.ST (FStar.Monotonic.Map.t r a b inv)
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Monotonic.Map.rid", "FStar.Monotonic.Map.map'", "FStar.HyperStack.ST.ralloc", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows", "FStar.Monotonic.Map.empty_map", "FStar.HyperStack.ST.mref", "FStar.Monotonic.Map.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.HyperStack.ST.witnessed", "FStar.HyperStack.ST.region_contains_pred", "FStar.HyperStack.ST.ralloc_post" ]
[]
false
true
false
false
false
let alloc (#r: rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) =
ralloc r (empty_map a b)
false
FStar.Monotonic.Map.fst
FStar.Monotonic.Map.extend
val extend (#r: rid) (#a: eqtype) (#b: (a -> Type)) (#inv: (map' a b -> Type0)) (m: t r a b inv) (x: a) (y: b x) : ST unit (requires (fun h -> let cur = HS.sel h m in inv (upd cur x y) /\ sel cur x == None)) (ensures (fun h0 u h1 -> let cur = HS.sel h0 m in let hsref = m in HS.contains h1 m /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r (Set.singleton (HS.as_addr hsref)) h0 h1 /\ HS.sel h1 m == upd cur x y /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x y)))
val extend (#r: rid) (#a: eqtype) (#b: (a -> Type)) (#inv: (map' a b -> Type0)) (m: t r a b inv) (x: a) (y: b x) : ST unit (requires (fun h -> let cur = HS.sel h m in inv (upd cur x y) /\ sel cur x == None)) (ensures (fun h0 u h1 -> let cur = HS.sel h0 m in let hsref = m in HS.contains h1 m /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r (Set.singleton (HS.as_addr hsref)) h0 h1 /\ HS.sel h1 m == upd cur x y /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x y)))
let extend (#r:rid) (#a:eqtype) (#b:a -> Type) (#inv:(map' a b -> Type0)) (m:t r a b inv) (x:a) (y:b x) : ST unit (requires (fun h -> let cur = HS.sel h m in inv (upd cur x y) /\ sel cur x == None)) (ensures (fun h0 u h1 -> let cur = HS.sel h0 m in let hsref = m in HS.contains h1 m /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r (Set.singleton (HS.as_addr hsref)) h0 h1 /\ HS.sel h1 m == upd cur x y /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x y))) = recall m; reveal_opaque (`%grows) (grows #a #b #inv); let cur = !m in m := upd cur x y; contains_stable m x y; mr_witness m (defined m x); mr_witness m (contains m x y)
{ "file_name": "ulib/FStar.Monotonic.Map.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 104, "start_col": 0, "start_line": 86 }
(* 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 library for monotonic references to partial, dependent maps, with a whole-map invariant *) module FStar.Monotonic.Map open FStar.HyperStack open FStar.HyperStack.ST module HS = FStar.HyperStack module HST = FStar.HyperStack.ST (* Partial, dependent maps *) type map' (a:Type) (b:a -> Type) = (x:a -> Tot (option (b x))) (* Partial, dependent maps, with a whole-map invariant *) type map (a:Type) (b:a -> Type) (inv:map' a b -> Type0) = m:map' a b{inv m} let upd (#a:eqtype) #b (m:map' a b) (x:a) (y:b x) : Tot (map' a b) = fun z -> if x = z then Some y else m z let sel #a #b (m:map' a b) (x:a) : Tot (option (b x)) = m x let grows_aux #a #b #inv :Preorder.preorder (map a b inv) = fun (m1 m2:map a b inv) -> forall x.{:pattern (Some? (m1 x))} Some? (m1 x) ==> Some? (m2 x) /\ Some?.v (m1 x) == Some?.v (m2 x) [@@"opaque_to_smt"] let grows #a #b #inv = grows_aux #a #b #inv (* Monotone, partial, dependent maps, with a whole-map invariant *) type t r a b inv = m_rref r (map a b inv) grows //maybe grows can include the inv? let empty_map a b : Tot (map' a b) = fun x -> None type rid = HST.erid let alloc (#r:rid) #a #b #inv : ST (t r a b inv) (requires (fun h -> inv (empty_map a b) /\ witnessed (region_contains_pred r))) (ensures (fun h0 x h1 -> inv (empty_map a b) /\ ralloc_post r (empty_map a b) h0 x h1)) = ralloc r (empty_map a b) let defined #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) let contains #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) (h:HS.mem) : GTot Type0 = Some? (sel (HS.sel h m) x) /\ Some?.v (sel (HS.sel h m) x) == y let value #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem{defined m x h}) : GTot (r:b x{contains m x r h}) = Some?.v (sel (HS.sel h m) x) let fresh #r #a #b #inv (m:t r a b inv) (x:a) (h:HS.mem) : GTot Type0 = None? (sel (HS.sel h m) x) let contains_stable #r #a #b #inv (m:t r a b inv) (x:a) (y:b x) : Lemma (ensures (stable_on_t m (contains m x y))) = reveal_opaque (`%grows) (grows #a #b #inv)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Preorder.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.Map.fst" }
[ { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic", "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
m: FStar.Monotonic.Map.t r a b inv -> x: a -> y: b x -> FStar.HyperStack.ST.ST Prims.unit
FStar.HyperStack.ST.ST
[]
[]
[ "FStar.Monotonic.Map.rid", "Prims.eqtype", "FStar.Monotonic.Map.map'", "FStar.Monotonic.Map.t", "FStar.HyperStack.ST.mr_witness", "FStar.Monotonic.Map.map", "FStar.Monotonic.Map.grows", "FStar.Monotonic.Map.contains", "Prims.unit", "FStar.Monotonic.Map.defined", "FStar.Monotonic.Map.contains_stable", "FStar.HyperStack.ST.op_Colon_Equals", "FStar.Monotonic.Map.upd", "FStar.HyperStack.ST.op_Bang", "FStar.Pervasives.reveal_opaque", "FStar.Preorder.preorder", "FStar.HyperStack.ST.recall", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Monotonic.Map.sel", "FStar.Pervasives.Native.None", "FStar.Monotonic.HyperStack.sel", "FStar.Monotonic.HyperStack.contains", "FStar.Monotonic.HyperStack.modifies", "FStar.Set.singleton", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperStack.modifies_ref", "Prims.nat", "FStar.Monotonic.HyperStack.as_addr", "FStar.HyperStack.ST.witnessed" ]
[]
false
true
false
false
false
let extend (#r: rid) (#a: eqtype) (#b: (a -> Type)) (#inv: (map' a b -> Type0)) (m: t r a b inv) (x: a) (y: b x) : ST unit (requires (fun h -> let cur = HS.sel h m in inv (upd cur x y) /\ sel cur x == None)) (ensures (fun h0 u h1 -> let cur = HS.sel h0 m in let hsref = m in HS.contains h1 m /\ modifies (Set.singleton r) h0 h1 /\ modifies_ref r (Set.singleton (HS.as_addr hsref)) h0 h1 /\ HS.sel h1 m == upd cur x y /\ HST.witnessed (defined m x) /\ HST.witnessed (contains m x y))) =
recall m; reveal_opaque (`%grows) (grows #a #b #inv); let cur = !m in m := upd cur x y; contains_stable m x y; mr_witness m (defined m x); mr_witness m (contains m x y)
false
FStar.UInt.fsti
FStar.UInt.ones
val ones (n: nat) : Tot (uint_t n)
val ones (n: nat) : Tot (uint_t n)
let ones (n:nat) : Tot (uint_t n) = max_int n
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 64, "start_col": 0, "start_line": 64 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
n: Prims.nat -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.max_int", "FStar.UInt.uint_t" ]
[]
false
false
false
false
false
let ones (n: nat) : Tot (uint_t n) =
max_int n
false
FStar.UInt.fsti
FStar.UInt.zero
val zero (n: nat) : Tot (uint_t n)
val zero (n: nat) : Tot (uint_t n)
let zero (n:nat) : Tot (uint_t n) = 0
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 57, "start_col": 0, "start_line": 57 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
n: Prims.nat -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t" ]
[]
false
false
false
false
false
let zero (n: nat) : Tot (uint_t n) =
0
false
FStar.UInt.fsti
FStar.UInt.pow2_n
val pow2_n (#n: pos) (p: nat{p < n}) : Tot (uint_t n)
val pow2_n (#n: pos) (p: nat{p < n}) : Tot (uint_t n)
let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 60, "start_col": 0, "start_line": 59 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
p: Prims.nat{p < n} -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "Prims.pow2", "Prims.unit", "FStar.Math.Lemmas.pow2_le_compat", "Prims.op_Subtraction", "FStar.UInt.uint_t" ]
[]
false
false
false
false
false
let pow2_n (#n: pos) (p: nat{p < n}) : Tot (uint_t n) =
pow2_le_compat (n - 1) p; pow2 p
false
FStar.UInt.fsti
FStar.UInt.decr_mod
val decr_mod (#n: nat) (a: uint_t n) : Tot (uint_t n)
val decr_mod (#n: nat) (a: uint_t n) : Tot (uint_t n)
let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 72, "end_line": 85, "start_col": 0, "start_line": 85 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Modulus", "Prims.op_Subtraction", "Prims.pow2" ]
[]
false
false
false
false
false
let decr_mod (#n: nat) (a: uint_t n) : Tot (uint_t n) =
(a - 1) % (pow2 n)
false
FStar.UInt.fsti
FStar.UInt.incr
val incr (#n: nat) (a: uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True))
val incr (#n: nat) (a: uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True))
let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 69, "start_col": 0, "start_line": 67 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n)
Prims.Pure
[]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Addition", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt.max_int", "Prims.l_True" ]
[]
false
false
false
false
false
let incr (#n: nat) (a: uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) =
a + 1
false
FStar.UInt.fsti
FStar.UInt.incr_mod
val incr_mod (#n: nat) (a: uint_t n) : Tot (uint_t n)
val incr_mod (#n: nat) (a: uint_t n) : Tot (uint_t n)
let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 72, "end_line": 83, "start_col": 0, "start_line": 83 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Modulus", "Prims.op_Addition", "Prims.pow2" ]
[]
false
false
false
false
false
let incr_mod (#n: nat) (a: uint_t n) : Tot (uint_t n) =
(a + 1) % (pow2 n)
false
FStar.UInt.fsti
FStar.UInt.add
val add (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True))
val add (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True))
let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 91, "start_col": 0, "start_line": 88 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n)
Prims.Pure
[]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Addition", "FStar.UInt.size", "Prims.l_True" ]
[]
false
false
false
false
false
let add (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) =
a + b
false
FStar.UInt.fsti
FStar.UInt.one
val one (n: pos) : Tot (uint_t n)
val one (n: pos) : Tot (uint_t n)
let one (n:pos) : Tot (uint_t n) = 1
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 62, "start_col": 0, "start_line": 62 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
n: Prims.pos -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.UInt.uint_t" ]
[]
false
false
false
false
false
let one (n: pos) : Tot (uint_t n) =
1
false
FStar.UInt.fsti
FStar.UInt.gt
val gt (#n: _) (a b: uint_t n) : Tot bool
val gt (#n: _) (a b: uint_t n) : Tot bool
let gt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a > b)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 166, "start_col": 0, "start_line": 166 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b) (* Comparison operators *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_GreaterThan", "Prims.bool" ]
[]
false
false
false
false
false
let gt #n (a: uint_t n) (b: uint_t n) : Tot bool =
(a > b)
false
FStar.UInt.fsti
FStar.UInt.sub_mod
val sub_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n)
val sub_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n)
let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 113, "start_col": 0, "start_line": 112 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Modulus", "Prims.op_Subtraction", "Prims.pow2" ]
[]
false
false
false
false
false
let sub_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n) =
(a - b) % (pow2 n)
false
FStar.UInt.fsti
FStar.UInt.gte
val gte (#n: _) (a b: uint_t n) : Tot bool
val gte (#n: _) (a b: uint_t n) : Tot bool
let gte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a >= b)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 167, "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. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:uint_t n) (b:uint_t n) : Tot bool = (a = b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_GreaterThanOrEqual", "Prims.bool" ]
[]
false
false
false
false
false
let gte #n (a: uint_t n) (b: uint_t n) : Tot bool =
(a >= b)
false
FStar.UInt.fsti
FStar.UInt.add_mod
val add_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n)
val add_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n)
let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 99, "start_col": 0, "start_line": 98 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Modulus", "Prims.op_Addition", "Prims.pow2" ]
[]
false
false
false
false
false
let add_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n) =
(a + b) % (pow2 n)
false
FStar.UInt.fsti
FStar.UInt.decr
val decr (#n: nat) (a: uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True))
val decr (#n: nat) (a: uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True))
let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 73, "start_col": 0, "start_line": 71 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n)
Prims.Pure
[]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Subtraction", "Prims.b2t", "Prims.op_GreaterThan", "FStar.UInt.min_int", "Prims.l_True" ]
[]
false
false
false
false
false
let decr (#n: nat) (a: uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) =
a - 1
false
FStar.UInt.fsti
FStar.UInt.lt
val lt (#n: _) (a b: uint_t n) : Tot bool
val lt (#n: _) (a b: uint_t n) : Tot bool
let lt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a < b)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 168, "start_col": 0, "start_line": 168 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:uint_t n) (b:uint_t n) : Tot bool = (a = b) let gt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a > b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_LessThan", "Prims.bool" ]
[]
false
false
false
false
false
let lt #n (a: uint_t n) (b: uint_t n) : Tot bool =
(a < b)
false
FStar.UInt.fsti
FStar.UInt.lte
val lte (#n: _) (a b: uint_t n) : Tot bool
val lte (#n: _) (a b: uint_t n) : Tot bool
let lte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a <= b)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 58, "end_line": 169, "start_col": 0, "start_line": 169 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:uint_t n) (b:uint_t n) : Tot bool = (a = b) let gt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a > b) let gte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a >= b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_LessThanOrEqual", "Prims.bool" ]
[]
false
false
false
false
false
let lte #n (a: uint_t n) (b: uint_t n) : Tot bool =
(a <= b)
false
FStar.UInt.fsti
FStar.UInt.mod
val mod (#n: nat) (a: uint_t n) (b: uint_t n {b <> 0}) : Tot (uint_t n)
val mod (#n: nat) (a: uint_t n) (b: uint_t n {b <> 0}) : Tot (uint_t n)
let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 162, "start_col": 0, "start_line": 161 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n {b <> 0} -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Prims.op_Subtraction", "FStar.Mul.op_Star", "Prims.op_Division" ]
[]
false
false
false
false
false
let mod (#n: nat) (a: uint_t n) (b: uint_t n {b <> 0}) : Tot (uint_t n) =
a - ((a / b) * b)
false
FStar.UInt.fsti
FStar.UInt.mul_mod
val mul_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n)
val mul_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n)
let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 127, "start_col": 0, "start_line": 126 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.pow2" ]
[]
false
false
false
false
false
let mul_mod (#n: nat) (a b: uint_t n) : Tot (uint_t n) =
(a * b) % (pow2 n)
false
FStar.UInt.fsti
FStar.UInt.mul
val mul (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True))
val mul (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True))
let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 119, "start_col": 0, "start_line": 116 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n)
Prims.Pure
[]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "FStar.Mul.op_Star", "FStar.UInt.size", "Prims.l_True" ]
[]
false
false
false
false
false
let mul (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) =
a * b
false
FStar.UInt.fsti
FStar.UInt.sub
val sub (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True))
val sub (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True))
let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 105, "start_col": 0, "start_line": 102 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.Pure (FStar.UInt.uint_t n)
Prims.Pure
[]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Subtraction", "FStar.UInt.size", "Prims.l_True" ]
[]
false
false
false
false
false
let sub (#n: nat) (a b: uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) =
a - b
false
FStar.UInt.fsti
FStar.UInt.div
val div (#n: nat) (a: uint_t n) (b: uint_t n {b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c))
val div (#n: nat) (a: uint_t n) (b: uint_t n {b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c))
let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 9, "end_line": 145, "start_col": 0, "start_line": 142 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n {b <> 0} -> Prims.Pure (FStar.UInt.uint_t n)
Prims.Pure
[]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Prims.op_Division", "FStar.UInt.size", "Prims.l_imp", "Prims.op_Equality" ]
[]
false
false
false
false
false
let div (#n: nat) (a: uint_t n) (b: uint_t n {b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) =
a / b
false
FStar.UInt.fsti
FStar.UInt.mul_div
val mul_div (#n: nat) (a b: uint_t n) : Tot (uint_t n)
val mul_div (#n: nat) (a b: uint_t n) : Tot (uint_t n)
let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "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. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Division", "FStar.Mul.op_Star", "Prims.pow2", "Prims.unit", "FStar.UInt.lt_square_div_lt", "FStar.Math.Lemmas.lemma_mult_lt_sqr" ]
[]
false
false
false
false
false
let mul_div (#n: nat) (a b: uint_t n) : Tot (uint_t n) =
FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n)
false
FStar.UInt.fsti
FStar.UInt.xor
val xor (b b': bool) : Tot bool
val xor (b b': bool) : Tot bool
let xor (b:bool) (b':bool) : Tot bool = b <> b'
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 55, "end_line": 380, "start_col": 8, "start_line": 380 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:uint_t n) (b:uint_t n) : Tot bool = (a = b) let gt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a > b) let gte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a >= b) let lt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a < b) let lte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a <= b) /// Casts let to_uint_t (m:nat) (a:int) : Tot (uint_t m) = a % pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) (* Casts *) let rec to_vec (#n:nat) (num:uint_t n) : Tot (bv_t n) = if n = 0 then Seq.empty #bool else Seq.append (to_vec #(n - 1) (num / 2)) (Seq.create 1 (num % 2 = 1)) let rec from_vec (#n:nat) (vec:bv_t n) : Tot (uint_t n) = if n = 0 then 0 else 2 * from_vec #(n - 1) (slice vec 0 (n - 1)) + (if index vec (n - 1) then 1 else 0) val to_vec_lemma_1: #n:nat -> a:uint_t n -> b:uint_t n -> Lemma (requires a = b) (ensures equal (to_vec a) (to_vec b)) val to_vec_lemma_2: #n:nat -> a:uint_t n -> b:uint_t n -> Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} -> Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i) [SMTPat (index (to_vec (from_vec vec)) i)] val inverse_vec_lemma: #n:nat -> vec:bv_t n -> Lemma (requires True) (ensures equal vec (to_vec (from_vec vec))) [SMTPat (to_vec (from_vec vec))] val inverse_num_lemma: #n:nat -> num:uint_t n -> Lemma (requires True) (ensures num = from_vec (to_vec num)) [SMTPat (from_vec (to_vec num))] val from_vec_lemma_1: #n:nat -> a:bv_t n -> b:bv_t n -> Lemma (requires equal a b) (ensures from_vec a = from_vec b) val from_vec_lemma_2: #n:nat -> a:bv_t n -> b:bv_t n -> Lemma (requires from_vec a = from_vec b) (ensures equal a b) val from_vec_aux: #n:nat -> a:bv_t n -> s1:nat{s1 < n} -> s2:nat{s2 < s1} -> Lemma (requires True) (ensures (from_vec #s2 (slice a 0 s2)) * pow2 (n - s2) + (from_vec #(s1 - s2) (slice a s2 s1)) * pow2 (n - s1) + (from_vec #(n - s1) (slice a s1 n)) = ((from_vec #s2 (slice a 0 s2)) * pow2 (s1 - s2) + (from_vec #(s1 - s2) (slice a s2 s1))) * pow2 (n - s1) + (from_vec #(n - s1) (slice a s1 n))) val seq_slice_lemma: #n:nat -> a:bv_t n -> s1:nat{s1 < n} -> t1:nat{t1 >= s1 && t1 <= n} -> s2:nat{s2 < t1 - s1} -> t2:nat{t2 >= s2 && t2 <= t1 - s1} -> Lemma (equal (slice (slice a s1 t1) s2 t2) (slice a (s1 + s2) (s1 + t2))) val from_vec_propriety: #n:pos -> a:bv_t n -> s:nat{s < n} -> Lemma (requires True) (ensures from_vec a = (from_vec #s (slice a 0 s)) * pow2 (n - s) + from_vec #(n - s) (slice a s n)) (decreases (n - s)) val append_lemma: #n:pos -> #m:pos -> a:bv_t n -> b:bv_t m -> Lemma (from_vec #(n + m) (append a b) = (from_vec #n a) * pow2 m + (from_vec #m b)) val slice_left_lemma: #n:pos -> a:bv_t n -> s:pos{s < n} -> Lemma (requires True) (ensures from_vec #s (slice a 0 s) = (from_vec #n a) / (pow2 (n - s))) val slice_right_lemma: #n:pos -> a:bv_t n -> s:pos{s < n} -> Lemma (requires True) (ensures from_vec #s (slice a (n - s) n) = (from_vec #n a) % (pow2 s)) (* Relations between constants in BitVector and in UInt. *) val zero_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i) [SMTPat (index (to_vec (zero n)) i)] val zero_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n) [SMTPat (from_vec (zero_vec #n))] val one_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i) [SMTPat (index (to_vec (one n)) i)] val pow2_to_vec_lemma: #n:pos -> p:nat{p < n} -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i) [SMTPat (index (to_vec (pow2_n #n p)) i)] val pow2_from_vec_lemma: #n:pos -> p:nat{p < n} -> Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1)) [SMTPat (from_vec (elem_vec #n p))] val ones_to_vec_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures index (to_vec (ones n)) i = index (ones_vec #n) i) [SMTPat (index (to_vec (ones n)) i)] val ones_from_vec_lemma: #n:pos -> Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n) [SMTPat (from_vec (ones_vec #n))] (* (nth a i) returns a boolean indicating the i-th bit of a. *) let nth (#n:pos) (a:uint_t n) (i:nat{i < n}) : Tot bool = index (to_vec #n a) i val nth_lemma: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma (requires forall (i:nat{i < n}). nth a i = nth b i) (ensures a = b) (* Lemmas for constants *) val zero_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures nth (zero n) i = false) [SMTPat (nth (zero n) i)] val pow2_nth_lemma: #n:pos -> p:nat{p < n} -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - p - 1 ==> nth (pow2_n #n p) i = true) /\ (i <> n - p - 1 ==> nth (pow2_n #n p) i = false)) [SMTPat (nth (pow2_n #n p) i)] val one_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (i = n - 1 ==> nth (one n) i = true) /\ (i < n - 1 ==> nth (one n) i = false)) [SMTPat (nth (one n) i)] val ones_nth_lemma: #n:pos -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (ones n) i) = true) [SMTPat (nth (ones n) i)] (* Bitwise operators *) let logand (#n:pos) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = from_vec #n (logand_vec #n (to_vec #n a) (to_vec #n b)) let logxor (#n:pos) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = from_vec #n (logxor_vec #n (to_vec #n a) (to_vec #n b)) let logor (#n:pos) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = from_vec #n (logor_vec #n (to_vec #n a) (to_vec #n b)) let lognot (#n:pos) (a:uint_t n) : Tot (uint_t n) = from_vec #n (lognot_vec #n (to_vec #n a)) (* Bitwise operators definitions *) val logand_definition: #n:pos -> a:uint_t n -> b:uint_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logand a b) i = (nth a i && nth b i))) [SMTPat (nth (logand a b) i)] val logxor_definition: #n:pos -> a:uint_t n -> b:uint_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logxor a b) i = (nth a i <> nth b i))) [SMTPat (nth (logxor a b) i)] val logor_definition: #n:pos -> a:uint_t n -> b:uint_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (logor a b) i = (nth a i || nth b i))) [SMTPat (nth (logor a b) i)] val lognot_definition: #n:pos -> a:uint_t n -> i:nat{i < n} -> Lemma (requires True) (ensures (nth (lognot a) i = not(nth a i))) [SMTPat (nth (lognot a) i)] (* Two's complement unary minus *) inline_for_extraction let minus (#n:pos) (a:uint_t n) : Tot (uint_t n) = add_mod (lognot a) 1 (* Bitwise operators lemmas *) (* TODO: lemmas about the relations between different operators *) (* Bitwise AND operator *) val logand_commutative: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma (requires True) (ensures (logand #n a b = logand #n b a)) val logand_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n -> Lemma (requires True) (ensures (logand #n (logand #n a b) c = logand #n a (logand #n b c))) val logand_self: #n:pos -> a:uint_t n -> Lemma (requires True) (ensures (logand #n a a = a)) val logand_lemma_1: #n:pos -> a:uint_t n -> Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) val logand_lemma_2: #n:pos -> a:uint_t n -> Lemma (requires True) (ensures (logand #n a (ones n) = a)) (* subset_vec_le_lemma proves that a subset of bits is numerically smaller or equal. *) val subset_vec_le_lemma: #n:pos -> a:bv_t n -> b:bv_t n -> Lemma (requires is_subset_vec #n a b) (ensures (from_vec a) <= (from_vec b)) (* logand_le proves the the result of AND is less than or equal to both arguments. *) val logand_le: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma (requires True) (ensures (logand a b) <= a /\ (logand a b) <= b) (* Bitwise XOR operator *) val logxor_commutative: #n:pos -> a:uint_t n -> b:uint_t n -> Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) val logxor_associative: #n:pos -> a:uint_t n -> b:uint_t n -> c:uint_t n -> Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) val logxor_self: #n:pos -> a:uint_t n -> Lemma (requires True) (ensures (logxor #n a a = zero n)) val logxor_lemma_1: #n:pos -> a:uint_t n -> Lemma (requires True) (ensures (logxor #n a (zero n) = a)) val logxor_lemma_2: #n:pos -> a:uint_t n -> Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
b: Prims.bool -> b': Prims.bool -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.op_disEquality" ]
[]
false
false
false
true
false
let xor (b b': bool) : Tot bool =
b <> b'
false
FStar.UInt.fsti
FStar.UInt.eq
val eq (#n: _) (a b: uint_t n) : Tot bool
val eq (#n: _) (a b: uint_t n) : Tot bool
let eq #n (a:uint_t n) (b:uint_t n) : Tot bool = (a = b)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 56, "end_line": 165, "start_col": 0, "start_line": 165 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt.uint_t", "Prims.op_Equality", "Prims.bool" ]
[]
false
false
false
false
false
let eq #n (a: uint_t n) (b: uint_t n) : Tot bool =
(a = b)
false
FStar.UInt.fsti
FStar.UInt.udiv
val udiv (#n: pos) (a: uint_t n) (b: uint_t n {b <> 0}) : Tot (c: uint_t n {b <> 0 ==> a / b = c})
val udiv (#n: pos) (a: uint_t n) (b: uint_t n {b <> 0}) : Tot (c: uint_t n {b <> 0 ==> a / b = c})
let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 157, "start_col": 0, "start_line": 155 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
a: FStar.UInt.uint_t n -> b: FStar.UInt.uint_t n {b <> 0} -> c: FStar.UInt.uint_t n {b <> 0 ==> a / b = c}
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "FStar.UInt.uint_t", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Prims.op_Division", "Prims.unit", "FStar.UInt.div_size", "Prims.l_imp", "Prims.op_Equality" ]
[]
false
false
false
false
false
let udiv (#n: pos) (a: uint_t n) (b: uint_t n {b <> 0}) : Tot (c: uint_t n {b <> 0 ==> a / b = c}) =
div_size #n a b; a / b
false
FStar.UInt.fsti
FStar.UInt.from_vec
val from_vec (#n: nat) (vec: bv_t n) : Tot (uint_t n)
val from_vec (#n: nat) (vec: bv_t n) : Tot (uint_t n)
let rec from_vec (#n:nat) (vec:bv_t n) : Tot (uint_t n) = if n = 0 then 0 else 2 * from_vec #(n - 1) (slice vec 0 (n - 1)) + (if index vec (n - 1) then 1 else 0)
{ "file_name": "ulib/FStar.UInt.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 89, "end_line": 186, "start_col": 0, "start_line": 184 }
(* 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.UInt (* NOTE: anything that you fix/update here should be reflected in [FStar.Int.fsti], which is mostly * a copy-paste of this module. *) open FStar.Mul open FStar.BitVector open FStar.Math.Lemmas val pow2_values: x:nat -> Lemma (let p = pow2 x in match x with | 0 -> p=1 | 1 -> p=2 | 8 -> p=256 | 16 -> p=65536 | 31 -> p=2147483648 | 32 -> p=4294967296 | 63 -> p=9223372036854775808 | 64 -> p=18446744073709551616 | 128 -> p=0x100000000000000000000000000000000 | _ -> True) [SMTPat (pow2 x)] /// Specs /// /// Note: lacking any type of functors for F*, this is a copy/paste of [FStar.Int.fst], where the relevant bits that changed are: /// - definition of max and min /// - use of regular integer modulus instead of wrap-around modulus let max_int (n:nat) : Tot int = pow2 n - 1 let min_int (n:nat) : Tot int = 0 let fits (x:int) (n:nat) : Tot bool = min_int n <= x && x <= max_int n let size (x:int) (n:nat) : Tot Type0 = b2t(fits x n) (* Machine integer type *) type uint_t (n:nat) = x:int{size x n} /// Constants let zero (n:nat) : Tot (uint_t n) = 0 let pow2_n (#n:pos) (p:nat{p < n}) : Tot (uint_t n) = pow2_le_compat (n - 1) p; pow2 p let one (n:pos) : Tot (uint_t n) = 1 let ones (n:nat) : Tot (uint_t n) = max_int n (* Increment and decrement *) let incr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun _ -> True)) = a + 1 let decr (#n:nat) (a:uint_t n) : Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun _ -> True)) = a - 1 val incr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a < max_int n))) (ensures (fun b -> a + 1 = b)) val decr_underspec: #n:nat -> a:uint_t n -> Pure (uint_t n) (requires (b2t (a > min_int n))) (ensures (fun b -> a - 1 = b)) let incr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a + 1) % (pow2 n) let decr_mod (#n:nat) (a:uint_t n) : Tot (uint_t n) = (a - 1) % (pow2 n) (* Addition primitives *) let add (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a + b) n)) (ensures (fun _ -> True)) = a + b val add_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a + b) n ==> a + b = c)) let add_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a + b) % (pow2 n) (* Subtraction primitives *) let sub (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a - b) n)) (ensures (fun _ -> True)) = a - b val sub_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a - b) n ==> a - b = c)) let sub_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a - b) % (pow2 n) (* Multiplication primitives *) let mul (#n:nat) (a:uint_t n) (b:uint_t n) : Pure (uint_t n) (requires (size (a * b) n)) (ensures (fun _ -> True)) = a * b val mul_underspec: #n:nat -> a:uint_t n -> b:uint_t n -> Pure (uint_t n) (requires True) (ensures (fun c -> size (a * b) n ==> a * b = c)) let mul_mod (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = (a * b) % (pow2 n) private val lt_square_div_lt (a:nat) (b:pos) : Lemma (requires (a < b * b)) (ensures (a / b < b)) #push-options "--fuel 0 --ifuel 0" let mul_div (#n:nat) (a:uint_t n) (b:uint_t n) : Tot (uint_t n) = FStar.Math.Lemmas.lemma_mult_lt_sqr a b (pow2 n); lt_square_div_lt (a * b) (pow2 n); (a * b) / (pow2 n) #pop-options (* Division primitives *) let div (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Pure (uint_t n) (requires (size (a / b) n)) (ensures (fun c -> b <> 0 ==> a / b = c)) = a / b val div_underspec: #n:nat -> a:uint_t n -> b:uint_t n{b <> 0} -> Pure (uint_t n) (requires True) (ensures (fun c -> (b <> 0 /\ size (a / b) n) ==> a / b = c)) val div_size: #n:pos -> a:uint_t n -> b:uint_t n{b <> 0} -> Lemma (requires (size a n)) (ensures (size (a / b) n)) let udiv (#n:pos) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (c:uint_t n{b <> 0 ==> a / b = c}) = div_size #n a b; a / b (* Modulo primitives *) let mod (#n:nat) (a:uint_t n) (b:uint_t n{b <> 0}) : Tot (uint_t n) = a - ((a/b) * b) (* Comparison operators *) let eq #n (a:uint_t n) (b:uint_t n) : Tot bool = (a = b) let gt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a > b) let gte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a >= b) let lt #n (a:uint_t n) (b:uint_t n) : Tot bool = (a < b) let lte #n (a:uint_t n) (b:uint_t n) : Tot bool = (a <= b) /// Casts let to_uint_t (m:nat) (a:int) : Tot (uint_t m) = a % pow2 m open FStar.Seq (* WARNING: Mind the big endian vs little endian definition *) (* Casts *) let rec to_vec (#n:nat) (num:uint_t n) : Tot (bv_t n) = if n = 0 then Seq.empty #bool else Seq.append (to_vec #(n - 1) (num / 2)) (Seq.create 1 (num % 2 = 1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.BitVector.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt.fsti" }
[ { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.Math.Lemmas", "short_module": null }, { "abbrev": false, "full_module": "FStar.BitVector", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "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
vec: FStar.BitVector.bv_t n -> FStar.UInt.uint_t n
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.BitVector.bv_t", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.UInt.from_vec", "Prims.op_Subtraction", "FStar.Seq.Base.slice", "FStar.Seq.Base.index", "FStar.UInt.uint_t" ]
[ "recursion" ]
false
false
false
false
false
let rec from_vec (#n: nat) (vec: bv_t n) : Tot (uint_t n) =
if n = 0 then 0 else 2 * from_vec #(n - 1) (slice vec 0 (n - 1)) + (if index vec (n - 1) then 1 else 0)
false