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
ID5.fst
ID5.weaken
val weaken (#a #w: _) (p: Type0) (f: repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True))
val weaken (#a #w: _) (p: Type0) (f: repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True))
let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post ()
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 88, "start_col": 0, "start_line": 85 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type0 -> f: ID5.repr a w -> Prims.Pure (ID5.repr a (ID5.weaken_wp w p))
Prims.Pure
[]
[]
[ "ID5.wp", "ID5.repr", "FStar.Ghost.erased", "Prims.squash", "ID5.weaken_wp", "FStar.Ghost.reveal", "Prims.l_True" ]
[]
false
false
false
false
false
let weaken #a #w (p: Type0) (f: repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) =
fun post _ -> f post ()
false
ID5.fst
ID5.i_tot
val i_tot (#a: _) (f: (unit -> I a)) : Tot a
val i_tot (#a: _) (f: (unit -> I a)) : Tot a
let i_tot #a (f : unit -> I a) : Tot a = reify (f ()) (fun _ -> True) ()
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 222, "start_col": 0, "start_line": 221 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or // subtyping fails to kick in? "expected int, got nat". let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y //else fib (i-1) + fib (i-2) let test_assert () : ID unit (as_pure_wp (fun p -> p ())) = (); iassume False; (); iassert False; () let rec idiv (a b : nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a) = if a < b then 0 else 1 + idiv (a-b) b let rec ack (m n : nat) : I nat = match m, n with | 0, n -> n+1 | m, 0 -> ack (m-1) 1 | m, n -> ack (m-1) (ack m (n-1)) let add1 (x:int) : Id int (requires (x > 0)) (ensures (fun r -> r == x+1)) = x + 1 let tot_i #a (f : unit -> Tot a) : I a = f ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> ID5.I a) -> a
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.Ghost.hide", "Prims.l_True" ]
[]
false
false
false
false
false
let i_tot #a (f: (unit -> I a)) : Tot a =
reify (f ()) (fun _ -> True) ()
false
ID5.fst
ID5.strengthen_wp
val strengthen_wp (#a: Type) (w: wp a) (p: Type0) : wp a
val strengthen_wp (#a: Type) (w: wp a) (p: Type0) : wp a
let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post)
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 75, "start_col": 0, "start_line": 73 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: ID5.wp a -> p: Type0 -> ID5.wp a
Prims.Tot
[ "total" ]
[]
[ "ID5.wp", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.l_and", "Prims.pure_pre", "Prims.unit", "FStar.Monotonic.Pure.elim_pure_wp_monotonicity_forall" ]
[]
false
false
false
true
false
let strengthen_wp (#a: Type) (w: wp a) (p: Type0) : wp a =
elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post)
false
ID5.fst
ID5.map
val map (#a #b #pre: _) (f: (x: a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l: list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True))
val map (#a #b #pre: _) (f: (x: a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l: list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True))
let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 157, "start_col": 0, "start_line": 149 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (x: a -> ID5.Id b) -> l: Prims.list a -> ID5.Id (Prims.list b)
ID5.Id
[]
[]
[ "Prims.l_True", "Prims.list", "Prims.Nil", "Prims.Cons", "ID5.map", "Prims.l_Forall", "Prims.l_imp", "FStar.List.Tot.Base.memP" ]
[ "recursion" ]
false
true
false
false
false
let rec map #a #b #pre (f: (x: a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l: list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) =
match l with | [] -> [] | x :: xs -> f x :: map #_ #_ #pre f xs
false
ID5.fst
ID5.test_f
val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3))
val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3))
let test_f () = 3
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 143, "start_col": 0, "start_line": 143 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> ID5.ID Prims.int
ID5.ID
[]
[]
[ "Prims.unit", "Prims.int" ]
[]
false
true
false
false
false
let test_f () =
3
false
ID5.fst
ID5.lift_pure_nd
val lift_pure_nd (a: Type) (wp: wp a) (f: (unit -> PURE a wp)) : Pure (repr a wp) (requires True) (ensures (fun _ -> True))
val lift_pure_nd (a: Type) (wp: wp a) (f: (unit -> PURE a wp)) : Pure (repr a wp) (requires True) (ensures (fun _ -> True))
let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 122, "start_col": 0, "start_line": 119 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> wp: ID5.wp a -> f: (_: Prims.unit -> Prims.PURE a) -> Prims.Pure (ID5.repr a wp)
Prims.Pure
[]
[]
[ "ID5.wp", "Prims.unit", "FStar.Ghost.erased", "Prims.squash", "FStar.Ghost.reveal", "FStar.Monotonic.Pure.elim_pure", "ID5.repr", "Prims.l_True" ]
[]
false
false
false
false
false
let lift_pure_nd (a: Type) (wp: wp a) (f: (unit -> PURE a wp)) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) =
fun p _ -> elim_pure f p
false
ID5.fst
ID5.cut
val cut (#a #w: _) (p: Type0) (f: repr a w) : repr a (cut_wp w p)
val cut (#a #w: _) (p: Type0) (f: repr a w) : repr a (cut_wp w p)
let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f)
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 36, "end_line": 96, "start_col": 0, "start_line": 95 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Type0 -> f: ID5.repr a w -> ID5.repr a (ID5.cut_wp w p)
Prims.Tot
[ "total" ]
[]
[ "ID5.wp", "ID5.repr", "ID5.strengthen", "ID5.weaken_wp", "Prims.squash", "ID5.weaken", "ID5.cut_wp" ]
[]
false
false
false
false
false
let cut #a #w (p: Type0) (f: repr a w) : repr a (cut_wp w p) =
strengthen p (fun _ -> weaken p f)
false
ID5.fst
ID5.pow2
val pow2 (n: nat) : I int
val pow2 (n: nat) : I int
let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1)
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 173, "start_col": 0, "start_line": 172 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> ID5.I Prims.int
ID5.I
[]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "Prims.op_Addition", "ID5.pow2", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec pow2 (n: nat) : I int =
if n = 0 then 1 else pow2 (n - 1) + pow2 (n - 1)
false
ID5.fst
ID5.count
val count (n: nat) : I int
val count (n: nat) : I int
let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1)
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 170, "start_col": 0, "start_line": 169 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.nat -> ID5.I Prims.int
ID5.I
[]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "ID5.count", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec count (n: nat) : I int =
if n = 0 then 0 else count (n - 1)
false
Hacl.Impl.Curve25519.Field51.fst
Hacl.Impl.Curve25519.Field51.fsqr2
val fsqr2: C.(fsqr2_t M51 True)
val fsqr2: C.(fsqr2_t M51 True)
let fsqr2 out f _ = let f10 = f.(0ul) in let f11 = f.(1ul) in let f12 = f.(2ul) in let f13 = f.(3ul) in let f14 = f.(4ul) in let f20 = f.(5ul) in let f21 = f.(6ul) in let f22 = f.(7ul) in let f23 = f.(8ul) in let f24 = f.(9ul) in let ((o10,o11,o12,o13,o14),(o20,o21,o22,o23,o24)) = fsqr25 (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in out.(0ul) <- o10; out.(1ul) <- o11; out.(2ul) <- o12; out.(3ul) <- o13; out.(4ul) <- o14; out.(5ul) <- o20; out.(6ul) <- o21; out.(7ul) <- o22; out.(8ul) <- o23; out.(9ul) <- o24
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 303, "start_col": 0, "start_line": 278 }
module Hacl.Impl.Curve25519.Field51 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer include Hacl.Spec.Curve25519.Field51 include Hacl.Spec.Curve25519.Field51.Definition module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field51.Definition module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.Curve25519.Field51.Lemmas module C = Hacl.Impl.Curve25519.Fields.Core #reset-options "--z3rlimit 20" let felem = lbuffer uint64 5ul let felem2 = lbuffer uint64 10ul let felem_wide = lbuffer uint128 5ul noextract let as_nat = C.f51_as_nat noextract val wide_as_nat: h:mem -> e:felem_wide -> GTot nat let wide_as_nat h e = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in let s4 = s.[4] in S.wide_as_nat5 (s0, s1, s2, s3, s4) noextract val fevalh: h:mem -> f:felem -> GTot P.elem let fevalh h f = (as_nat h f) % P.prime noextract val feval_wideh: h:mem -> f:felem_wide -> GTot P.elem let feval_wideh h f = (wide_as_nat h f) % P.prime noextract let felem_fits = C.f51_felem_fits noextract val felem_wide_fits: h:mem -> f:felem_wide -> m:S.scale128_5 -> Type0 let felem_wide_fits h f m = let s = as_seq h f in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in let s4 = s.[4] in S.felem_wide_fits5 (s0, s1, s2, s3, s4) m noextract let as_felem = C.f51_as_felem noextract let mul_inv_t = C.f51_mul_inv_t inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 5ul (u64 0) inline_for_extraction noextract val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero f = f.(0ul) <- u64 0; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0; f.(4ul) <- u64 0 inline_for_extraction noextract val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1) let set_one f = f.(0ul) <- u64 1; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0; f.(4ul) <- u64 0 inline_for_extraction noextract val copy_felem: f1:felem -> f2:felem -> Stack unit (requires fun h -> live h f1 /\ live h f2 /\ disjoint f1 f2) (ensures fun h0 _ h1 -> modifies (loc f1) h0 h1 /\ as_seq h1 f1 == as_seq h0 f2) let copy_felem f1 f2 = f1.(0ul) <- f2.(0ul); f1.(1ul) <- f2.(1ul); f1.(2ul) <- f2.(2ul); f1.(3ul) <- f2.(3ul); f1.(4ul) <- f2.(4ul); let h1 = ST.get () in LSeq.eq_intro (as_seq h1 f1) (as_seq h1 f2) #set-options "--max_fuel 0 --max_ifuel 0" val fadd: C.(fadd_t M51 True) [@ CInline] let fadd out f1 f2 = let h0 = ST.get () in let f10 = f1.(0ul) in let f20 = f2.(0ul) in let f11 = f1.(1ul) in let f21 = f2.(1ul) in let f12 = f1.(2ul) in let f22 = f2.(2ul) in let f13 = f1.(3ul) in let f23 = f2.(3ul) in let f14 = f1.(4ul) in let f24 = f2.(4ul) in out.(0ul) <- f10 +! f20; out.(1ul) <- f11 +! f21; out.(2ul) <- f12 +! f22; out.(3ul) <- f13 +! f23; out.(4ul) <- f14 +! f24; let h1 = ST.get () in assert (as_nat h1 out == as_nat h0 f1 + as_nat h0 f2); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat h0 f1) (as_nat h0 f2) P.prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat h0 f1 % P.prime) (as_nat h0 f2) P.prime val fsub: C.(fsub_t M51 True) [@ CInline] let fsub out f1 f2 = let f10 = f1.(0ul) in let f20 = f2.(0ul) in let f11 = f1.(1ul) in let f21 = f2.(1ul) in let f12 = f1.(2ul) in let f22 = f2.(2ul) in let f13 = f1.(3ul) in let f23 = f2.(3ul) in let f14 = f1.(4ul) in let f24 = f2.(4ul) in out.(0ul) <- f10 +! u64 0x3fffffffffff68 -! f20; out.(1ul) <- f11 +! u64 0x3ffffffffffff8 -! f21; out.(2ul) <- f12 +! u64 0x3ffffffffffff8 -! f22; out.(3ul) <- f13 +! u64 0x3ffffffffffff8 -! f23; out.(4ul) <- f14 +! u64 0x3ffffffffffff8 -! f24; lemma_fsub (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) val fmul: C.(fmul_t M51 True) [@ CInline] let fmul out f1 f2 _ = let f10 = f1.(0ul) in let f11 = f1.(1ul) in let f12 = f1.(2ul) in let f13 = f1.(3ul) in let f14 = f1.(4ul) in let f20 = f2.(0ul) in let f21 = f2.(1ul) in let f22 = f2.(2ul) in let f23 = f2.(3ul) in let f24 = f2.(4ul) in let (o0,o1,o2,o3,o4) = fmul5 (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in out.(0ul) <- o0; out.(1ul) <- o1; out.(2ul) <- o2; out.(3ul) <- o3; out.(4ul) <- o4 val fmul2: C.(fmul2_t M51 True) #set-options "--z3rlimit 100" [@ CInline] let fmul2 out f1 f2 _ = let f10 = f1.(0ul) in let f11 = f1.(1ul) in let f12 = f1.(2ul) in let f13 = f1.(3ul) in let f14 = f1.(4ul) in let f20 = f2.(0ul) in let f21 = f2.(1ul) in let f22 = f2.(2ul) in let f23 = f2.(3ul) in let f24 = f2.(4ul) in let f30 = f1.(5ul) in let f31 = f1.(6ul) in let f32 = f1.(7ul) in let f33 = f1.(8ul) in let f34 = f1.(9ul) in let f40 = f2.(5ul) in let f41 = f2.(6ul) in let f42 = f2.(7ul) in let f43 = f2.(8ul) in let f44 = f2.(9ul) in let ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) = fmul25 (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) (f30,f31,f32,f33,f34) (f40,f41,f42,f43,f44) in out.(0ul) <- o10; out.(1ul) <- o11; out.(2ul) <- o12; out.(3ul) <- o13; out.(4ul) <- o14; out.(5ul) <- o20; out.(6ul) <- o21; out.(7ul) <- o22; out.(8ul) <- o23; out.(9ul) <- o24 val fmul1: C.(fmul1_t M51 True) [@ CInline] let fmul1 out f1 f2 = let f10 = f1.(0ul) in let f11 = f1.(1ul) in let f12 = f1.(2ul) in let f13 = f1.(3ul) in let f14 = f1.(4ul) in let (o0,o1,o2,o3,o4) = fmul15 (f10,f11,f12,f13,f14) f2 in out.(0ul) <- o0; out.(1ul) <- o1; out.(2ul) <- o2; out.(3ul) <- o3; out.(4ul) <- o4 val fsqr: C.(fsqr_t M51 True) [@ CInline] let fsqr out f _ = let f0 = f.(0ul) in let f1 = f.(1ul) in let f2 = f.(2ul) in let f3 = f.(3ul) in let f4 = f.(4ul) in let (o0,o1,o2,o3,o4) = fsqr5 (f0,f1,f2,f3,f4) in out.(0ul) <- o0; out.(1ul) <- o1; out.(2ul) <- o2; out.(3ul) <- o3; out.(4ul) <- o4 val fsqr2: C.(fsqr2_t M51 True)
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "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": "Lib.Sequence", "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.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Curve25519.Fields.Core.fsqr2_t Hacl.Impl.Curve25519.Fields.Core.M51 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.felem2", "Hacl.Impl.Curve25519.Fields.Core.M51", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "Lib.IntTypes.uint64", "Lib.Buffer.op_Array_Assignment", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.fsqr25", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT" ]
[]
false
false
false
true
false
let fsqr2 out f _ =
let f10 = f.(0ul) in let f11 = f.(1ul) in let f12 = f.(2ul) in let f13 = f.(3ul) in let f14 = f.(4ul) in let f20 = f.(5ul) in let f21 = f.(6ul) in let f22 = f.(7ul) in let f23 = f.(8ul) in let f24 = f.(9ul) in let (o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24) = fsqr25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) in out.(0ul) <- o10; out.(1ul) <- o11; out.(2ul) <- o12; out.(3ul) <- o13; out.(4ul) <- o14; out.(5ul) <- o20; out.(6ul) <- o21; out.(7ul) <- o22; out.(8ul) <- o23; out.(9ul) <- o24
false
ID5.fst
ID5.fibl
val fibl (i: nat) : I nat
val fibl (i: nat) : I nat
let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1)
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 178, "start_col": 0, "start_line": 175 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> ID5.I Prims.nat
ID5.I
[]
[]
[ "Prims.nat", "Prims.op_BarBar", "Prims.op_Equality", "Prims.int", "Prims.bool", "ID5.fibl", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec fibl (i: nat) : I nat =
if i = 0 || i = 1 then 1 else fibl (i - 1)
false
ID5.fst
ID5.idiv
val idiv (a b: nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a)
val idiv (a b: nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a)
let rec idiv (a b : nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a) = if a < b then 0 else 1 + idiv (a-b) b
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 23, "end_line": 208, "start_col": 0, "start_line": 202 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or // subtyping fails to kick in? "expected int, got nat". let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y //else fib (i-1) + fib (i-2) let test_assert () : ID unit (as_pure_wp (fun p -> p ())) = (); iassume False; (); iassert False; ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.nat -> b: Prims.nat -> ID5.Id Prims.int
ID5.Id
[ "" ]
[]
[ "Prims.nat", "Prims.op_LessThan", "Prims.int", "Prims.bool", "Prims.op_Addition", "ID5.idiv", "Prims.op_Subtraction", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_GreaterThan" ]
[ "recursion" ]
false
true
false
false
false
let rec idiv (a b: nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a) =
if a < b then 0 else 1 + idiv (a - b) b
false
ID5.fst
ID5.add1
val add1 (x: int) : Id int (requires (x > 0)) (ensures (fun r -> r == x + 1))
val add1 (x: int) : Id int (requires (x > 0)) (ensures (fun r -> r == x + 1))
let add1 (x:int) : Id int (requires (x > 0)) (ensures (fun r -> r == x+1)) = x + 1
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 82, "end_line": 216, "start_col": 0, "start_line": 216 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or // subtyping fails to kick in? "expected int, got nat". let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y //else fib (i-1) + fib (i-2) let test_assert () : ID unit (as_pure_wp (fun p -> p ())) = (); iassume False; (); iassert False; () let rec idiv (a b : nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a) = if a < b then 0 else 1 + idiv (a-b) b let rec ack (m n : nat) : I nat = match m, n with | 0, n -> n+1 | m, 0 -> ack (m-1) 1 | m, n -> ack (m-1) (ack m (n-1))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> ID5.Id Prims.int
ID5.Id
[]
[]
[ "Prims.int", "Prims.op_Addition", "Prims.b2t", "Prims.op_GreaterThan", "Prims.eq2" ]
[]
false
true
false
false
false
let add1 (x: int) : Id int (requires (x > 0)) (ensures (fun r -> r == x + 1)) =
x + 1
false
ID5.fst
ID5.fmap
val fmap (x: nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x))
val fmap (x: nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x))
let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 79, "end_line": 163, "start_col": 0, "start_line": 163 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) =
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.nat -> ID5.Id Prims.nat
ID5.Id
[]
[]
[ "Prims.nat", "Prims.op_Division", "ID5.even", "Prims.b2t", "Prims.op_LessThanOrEqual" ]
[]
false
true
false
false
false
let fmap (x: nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) =
x / 2
false
ID5.fst
ID5.fib
val fib (i: nat) : I nat
val fib (i: nat) : I nat
let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 192, "start_col": 0, "start_line": 187 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> ID5.I Prims.nat
ID5.I
[]
[]
[ "Prims.nat", "Prims.op_LessThan", "Prims.bool", "Prims.op_Addition", "ID5.fib", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec fib (i: nat) : I nat =
if i < 2 then 1 else let x = fib (i - 1) in let y = fib (i - 2) in x + y
false
ID5.fst
ID5.fibr
val fibr (i: nat) : I nat
val fibr (i: nat) : I nat
let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2)
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 183, "start_col": 0, "start_line": 180 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
i: Prims.nat -> ID5.I Prims.nat
ID5.I
[]
[]
[ "Prims.nat", "Prims.op_BarBar", "Prims.op_Equality", "Prims.int", "Prims.bool", "ID5.fibr", "Prims.op_Subtraction" ]
[ "recursion" ]
false
true
false
false
false
let rec fibr (i: nat) : I nat =
if i = 0 || i = 1 then 1 else fibr (i - 2)
false
Hacl.SHA2.Vec128.fst
Hacl.SHA2.Vec128.sha256_update_last4
val sha256_update_last4 : Hacl.Impl.SHA2.Generic.update_last_vec_t' Spec.Hash.Definitions.SHA2_256 Hacl.Spec.SHA2.Vec.M128
let sha256_update_last4 = update_last #SHA2_256 #M128 sha256_update4
{ "file_name": "code/sha2-mb/Hacl.SHA2.Vec128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 87, "end_line": 62, "start_col": 19, "start_line": 62 }
module Hacl.SHA2.Vec128 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Buffer open Lib.MultiBuffer open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST module Spec = Spec.Agile.Hash module SpecVec = Hacl.Spec.SHA2.Vec #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" [@CInline] private let sha224_init4 = init #SHA2_224 #M128 [@CInline] private let sha224_update4 = update #SHA2_224 #M128 [@CInline] private let sha224_update_nblocks4 = update_nblocks #SHA2_224 #M128 sha224_update4 [@CInline] private let sha224_update_last4 = update_last #SHA2_224 #M128 sha224_update4 [@CInline] private let sha224_finish4 = finish #SHA2_224 #M128 val sha224_4 (dst0 dst1 dst2 dst3: lbuffer uint8 28ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3)) let sha224_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 = let ib = ntup4 (input0,(input1,(input2,input3))) in let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in let h0 = ST.get() in assert (live_multi h0 ib); assert (live_multi h0 rb); assert (internally_disjoint rb); loc_multi4 rb; hash #SHA2_224 #M128 sha224_init4 sha224_update_nblocks4 sha224_update_last4 sha224_finish4 rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M128 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0); assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1); assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2); assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3) [@CInline] private let sha256_init4 = init #SHA2_256 #M128 [@CInline] private let sha256_update4 = update #SHA2_256 #M128
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.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.SHA2.Vec128.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": "SpecVec" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.SHA2.Generic.update_last_vec_t' Spec.Hash.Definitions.SHA2_256 Hacl.Spec.SHA2.Vec.M128
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.SHA2.Generic.update_last", "Spec.Hash.Definitions.SHA2_256", "Hacl.Spec.SHA2.Vec.M128", "Hacl.SHA2.Vec128.sha256_update4" ]
[]
false
false
false
true
false
let sha256_update_last4 =
update_last #SHA2_256 #M128 sha256_update4
false
ID5.fst
ID5.test_assert
val test_assert: Prims.unit -> ID unit (as_pure_wp (fun p -> p ()))
val test_assert: Prims.unit -> ID unit (as_pure_wp (fun p -> p ()))
let test_assert () : ID unit (as_pure_wp (fun p -> p ())) = (); iassume False; (); iassert False; ()
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 4, "end_line": 200, "start_col": 0, "start_line": 195 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or // subtyping fails to kick in? "expected int, got nat". let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y //else fib (i-1) + fib (i-2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> ID5.ID Prims.unit
ID5.ID
[]
[]
[ "Prims.unit", "ID5.iassert", "Prims.l_False", "ID5.iassume", "FStar.Monotonic.Pure.as_pure_wp", "Prims.pure_post", "Prims.pure_pre" ]
[]
false
true
false
false
false
let test_assert () : ID unit (as_pure_wp (fun p -> p ())) =
(); iassume False; (); iassert False; ()
false
ID5.fst
ID5.ack
val ack (m n: nat) : I nat
val ack (m n: nat) : I nat
let rec ack (m n : nat) : I nat = match m, n with | 0, n -> n+1 | m, 0 -> ack (m-1) 1 | m, n -> ack (m-1) (ack m (n-1))
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 214, "start_col": 0, "start_line": 210 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or // subtyping fails to kick in? "expected int, got nat". let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y //else fib (i-1) + fib (i-2) let test_assert () : ID unit (as_pure_wp (fun p -> p ())) = (); iassume False; (); iassert False; () let rec idiv (a b : nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a) = if a < b then 0 else 1 + idiv (a-b) b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: Prims.nat -> n: Prims.nat -> ID5.I Prims.nat
ID5.I
[]
[]
[ "Prims.nat", "FStar.Pervasives.Native.Mktuple2", "Prims.int", "Prims.op_Addition", "ID5.ack", "Prims.op_Subtraction", "Prims.l_or", "Prims.precedes", "Prims.l_and", "Prims.op_Equals_Equals_Equals" ]
[ "recursion" ]
false
true
false
false
false
let rec ack (m n: nat) : I nat =
match m, n with | 0, n -> n + 1 | m, 0 -> ack (m - 1) 1 | m, n -> ack (m - 1) (ack m (n - 1))
false
ID5.fst
ID5.callmap
val callmap: Prims.unit -> Id (list nat) True (fun _ -> True)
val callmap: Prims.unit -> Id (list nat) True (fun _ -> True)
let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 167, "start_col": 0, "start_line": 165 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> ID5.Id (Prims.list Prims.nat)
ID5.Id
[]
[]
[ "Prims.unit", "ID5.map", "Prims.nat", "ID5.even", "ID5.fmap", "Prims.list", "Prims.Cons", "Prims.Nil", "Prims.l_True" ]
[]
false
true
false
false
false
let callmap () : Id (list nat) True (fun _ -> True) =
let lmap:list nat = [2; 4; 6; 8] in map #_ #_ #even fmap lmap
false
ID5.fst
ID5.sum
val sum (l: list int) : I int
val sum (l: list int) : I int
let rec sum (l : list int) : I int = match l with | [] -> 0 | x::xs -> sum xs
{ "file_name": "examples/layeredeffects/ID5.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 20, "end_line": 227, "start_col": 0, "start_line": 224 }
module ID5 open FStar.Ghost // The base type of WPs val wp0 (a : Type u#a) : Type u#(max 1 a) let wp0 a = (a -> Type0) -> Type0 val wp (a : Type u#a) : Type u#(max 1 a) let wp a = pure_wp a let repr (a : Type u#aa) (w : wp a) : Type u#(max 1 aa) = // Hmmm, the explicit post bumps the universe level p:erased (a -> Type0) -> squash (w p) -> v:a{reveal p v} open FStar.Monotonic.Pure unfold let return_wp #a (x:a) : wp a = as_pure_wp (fun p -> p x) let return (a : Type) (x : a) : repr a (return_wp x) = // Fun fact: using () instead of _ below makes us // lose the refinement and then this proof fails. // Keep that in mind all ye who enter here. fun p _ -> x unfold let bind_wp #a #b (wp_v : wp a) (wp_f : (x:a -> wp b)) : wp b = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun p -> wp_v (fun x -> wp_f x p)) let bind (a b : Type) (wp_v : wp a) (wp_f: a -> wp b) (v : repr a wp_v) (f : (x:a -> repr b (wp_f x))) : repr b (bind_wp wp_v wp_f) = fun p _ -> let x = v (fun x -> wp_f x p) () in f x p () irreducible let refine : unit = () let subcomp (a:Type u#uu) (w1 w2:wp a) (f : repr a w1) : Pure (repr a w2) (requires forall p. w2 p ==> w1 p) (ensures fun _ -> True) = f // useful? //let subcomp (a b:Type u#uu) (w1:wp a) (w2: wp b) // (f : repr a w1) //: Pure (repr b w2) // (requires a `subtype_of` b /\ (forall (p:b->Type0). w2 p ==> w1 (fun x -> p x))) // (ensures fun _ -> True) //= fun p pf -> f (hide (fun x -> reveal p x)) () unfold let ite_wp #a (wp1 wp2 : wp a) (b : bool) : wp a = elim_pure_wp_monotonicity_forall (); (as_pure_wp (fun (p:a -> Type) -> (b ==> wp1 p) /\ ((~b) ==> wp2 p))) let if_then_else (a : Type) (wp1 wp2 : wp a) (f : repr a wp1) (g : repr a wp2) (p : bool) : Type = repr a (ite_wp wp1 wp2 p) let default_if_then_else (a:Type) (wp:wp a) (f:repr a wp) (g:repr a wp) (p:bool) : Type = repr a wp unfold let strengthen_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ w post) let strengthen #a #w (p:Type0) (f : squash p -> repr a w) : repr a (strengthen_wp w p) = fun post _ -> f () post () unfold let weaken_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p ==> w post) let weaken #a #w (p:Type0) (f : repr a w) : Pure (repr a (weaken_wp w p)) (requires p) (ensures (fun _ -> True)) = fun post _ -> f post () unfold let cut_wp (#a:Type) (w:wp a) (p:Type0) : wp a = elim_pure_wp_monotonicity_forall (); as_pure_wp (fun post -> p /\ (p ==> w post)) let cut #a #w (p:Type0) (f : repr a w) : repr a (cut_wp w p) = strengthen p (fun _ -> weaken p f) // requires to prove that // p ==> f <: (if_then_else p f g) // ~p ==> g <: (if_then_else p f g) // if the effect definition fails, add lemmas for the // above with smtpats total reifiable reflectable effect { ID (a:Type) (_:wp a) with {repr; return; bind; subcomp; if_then_else} } effect Id (a:Type) (pre:Type0) (post:a->Type0) = ID a (as_pure_wp (fun p -> pre /\ (forall x. post x ==> p x))) effect I (a:Type) = Id a True (fun _ -> True) open FStar.Tactics.V2 let lift_pure_nd (a:Type) (wp:wp a) (f:unit -> PURE a wp) : Pure (repr a wp) (requires True) (ensures (fun _ -> True)) = fun p _ -> elim_pure f p sub_effect PURE ~> ID = lift_pure_nd //tests to make sure we are actually checking subcomp even now let apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 2) = f () [@@expect_failure] let incorrect_apply (f:unit -> Id int True (fun x -> x > 3)) : Id int True (fun x -> x > 5) = f () [@@expect_failure] let another_one (n:int) (f:(x:int -> Id int (x > 0) (fun _ -> True))) : Id int True (fun _ -> True) = f n let iassert (q:Type0) : ID unit (as_pure_wp (fun p -> q /\ (q ==> p ()))) = () assume val iassume (q:Type0) : ID unit (as_pure_wp (fun p -> q ==> p ())) (* Checking that it's kind of usable *) val test_f : unit -> ID int (as_pure_wp (fun p -> p 5 /\ p 3)) let test_f () = 3 let l () : int = reify (test_f ()) (fun _ -> True) () open FStar.List.Tot let rec map #a #b #pre (f : (x:a -> Id b (requires (pre x)) (ensures (fun _ -> True)))) (l : list a) : Id (list b) (requires (forall x. memP x l ==> pre x)) (ensures (fun _ -> True)) = match l with | [] -> [] | x::xs -> f x :: map #_ #_ #pre f xs let even x = x % 2 == 0 //let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r > x)) = // I cannot have a stronger post, subeffecting doesn't kick in in callmap? let fmap (x:nat) : Id nat (requires (even x)) (ensures (fun r -> r <= x)) = x/2 let callmap () : Id (list nat) True (fun _ -> True) = let lmap : list nat = [2;4;6;8] in map #_ #_ #even fmap lmap let rec count (n:nat) : I int = if n = 0 then 0 else count (n-1) let rec pow2 (n:nat) : I int = if n = 0 then 1 else pow2 (n-1) + pow2 (n-1) let rec fibl (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibl (i-1) let rec fibr (i:nat) : I nat = if i = 0 || i = 1 then 1 else fibr (i-2) // TODO: I cannot use direct syntax and nat for the return type, or // subtyping fails to kick in? "expected int, got nat". let rec fib (i:nat) : I nat = if i < 2 then 1 else let x = fib (i-1) in let y = fib (i-2) in x+y //else fib (i-1) + fib (i-2) let test_assert () : ID unit (as_pure_wp (fun p -> p ())) = (); iassume False; (); iassert False; () let rec idiv (a b : nat) : Id int (requires (a >= 0 /\ b > 0)) (ensures (fun r -> r >= 0)) (decreases a) = if a < b then 0 else 1 + idiv (a-b) b let rec ack (m n : nat) : I nat = match m, n with | 0, n -> n+1 | m, 0 -> ack (m-1) 1 | m, n -> ack (m-1) (ack m (n-1)) let add1 (x:int) : Id int (requires (x > 0)) (ensures (fun r -> r == x+1)) = x + 1 let tot_i #a (f : unit -> Tot a) : I a = f () let i_tot #a (f : unit -> I a) : Tot a = reify (f ()) (fun _ -> True) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Pure.fst.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "ID5.fst" }
[ { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Pure", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Prims.list Prims.int -> ID5.I Prims.int
ID5.I
[]
[]
[ "Prims.list", "Prims.int", "ID5.sum" ]
[ "recursion" ]
false
true
false
false
false
let rec sum (l: list int) : I int =
match l with | [] -> 0 | x :: xs -> sum xs
false
Hacl.Impl.SecretBox.fst
Hacl.Impl.SecretBox.secretbox_open_detached
val secretbox_open_detached: mlen:size_t -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg))
val secretbox_open_detached: mlen:size_t -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg))
let secretbox_open_detached mlen m k n c tag = push_frame(); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in let tag' = create 16ul (u8 0) in Hacl.Streaming.Poly1305_32.mac tag' c mlen mkey; let res = if lbytes_eq tag tag' then ( secretbox_open_detached_plain mlen m xkeys n c; 0ul) else 0xfffffffful in pop_frame (); res
{ "file_name": "code/nacl-box/Hacl.Impl.SecretBox.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 225, "start_col": 0, "start_line": 209 }
module Hacl.Impl.SecretBox open FStar.HyperStack.All open FStar.HyperStack open FStar.Mul open Lib.IntTypes open Lib.Buffer open Lib.ByteBuffer open Hacl.Salsa20 open Hacl.Poly1305_32 module ST = FStar.HyperStack.ST module Spec = Spec.SecretBox module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --max_fuel 0 --max_ifuel 0" val secretbox_init: xkeys:lbuffer uint8 96ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> Stack unit (requires fun h -> live h xkeys /\ live h k /\ live h n /\ disjoint k xkeys /\ disjoint n xkeys) (ensures fun h0 _ h1 -> modifies (loc xkeys) h0 h1 /\ (let xkeys = as_seq h1 xkeys in let subkey : Spec.key = LSeq.sub xkeys 0 32 in let aekey : Spec.aekey = LSeq.sub xkeys 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h0 k) (as_seq h0 n))) let secretbox_init xkeys k n = let h0 = ST.get() in let subkey = sub xkeys 0ul 32ul in let aekey = sub xkeys 32ul 64ul in let n0 = sub n 0ul 16ul in let n1 = sub n 16ul 8ul in hsalsa20 subkey k n0; salsa20_key_block0 aekey subkey n1 inline_for_extraction noextract let get_len0 (len:size_t) : Tot (r:size_t{v r <= 32 /\ v r == Spec.get_len0 (v len)}) = if len <=. 32ul then len else 32ul #set-options "--z3rlimit 100" inline_for_extraction noextract val secretbox_detached_cipher: mlen:size_t -> c:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> xkeys:lbuffer uint8 96ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h xkeys /\ live h n /\ live h k /\ eq_or_disjoint m c /\ disjoint xkeys c /\ disjoint xkeys m /\ disjoint n m /\ disjoint n c /\ (let subkey : Spec.key = LSeq.sub (as_seq h xkeys) 0 32 in let aekey : Spec.aekey = LSeq.sub (as_seq h xkeys) 32 64 in (subkey, aekey) == Spec.secretbox_init (as_seq h k) (as_seq h n))) (ensures fun h0 _ h1 -> modifies (loc c) h0 h1 /\ (let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in as_seq h1 c == cipher)) let secretbox_detached_cipher mlen c k xkeys n m = let h0 = ST.get () in push_frame (); let n1 = sub n 16ul 8ul in let subkey = sub xkeys 0ul 32ul in let mkey = sub xkeys 32ul 32ul in let ekey0 = sub xkeys 64ul 32ul in let mlen0 = get_len0 mlen in let mlen1 = mlen -! mlen0 in let m0 = sub m 0ul mlen0 in let m1 = sub m mlen0 mlen1 in let block0 = create 32ul (u8 0) in update_sub block0 0ul mlen0 m0; map2T 32ul block0 ( ^. ) block0 ekey0; let c0 = sub c 0ul mlen0 in let c1 = sub c mlen0 mlen1 in let h1 = ST.get () in copy c0 (sub block0 0ul mlen0); let h2 = ST.get () in //assert (as_seq h2 c0 == LSeq.sub (as_seq h1 block0) 0 (v mlen0)); salsa20_encrypt mlen1 c1 m1 subkey n1 1ul; let h3 = ST.get () in //assert (as_seq h3 c1 == Spec.Salsa20.salsa20_encrypt_bytes (as_seq h2 subkey) (as_seq h2 n1) 1 (as_seq h2 m1)); FStar.Seq.Properties.lemma_split (as_seq h3 c) (v mlen0); //FStar.Seq.Properties.lemma_split (Seq.append (as_seq h2 c0) (as_seq h3 c1)) (v mlen0); assert (as_seq h3 c == Seq.append (as_seq h2 c0) (as_seq h3 c1)); assert ( let (tag, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in as_seq h3 c == cipher); pop_frame () val secretbox_detached: mlen:size_t -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> m:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ eq_or_disjoint m c /\ disjoint n m /\ disjoint n c) (ensures fun h0 _ h1 -> modifies (loc c |+| loc tag) h0 h1 /\ (as_seq h1 tag, as_seq h1 c) == Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m)) let secretbox_detached mlen c tag k n m = let h0 = ST.get () in push_frame(); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in secretbox_detached_cipher mlen c k xkeys n m; Hacl.Streaming.Poly1305_32.mac tag c mlen mkey; let h1 = ST.get () in assert ( let (tag1, cipher) = Spec.secretbox_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 m) in (as_seq h1 tag, as_seq h1 c) == (tag1, cipher)); pop_frame() inline_for_extraction noextract val secretbox_open_detached_plain: mlen:size_t -> m:lbuffer uint8 mlen -> xkeys:lbuffer uint8 96ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> Stack unit (requires fun h -> live h c /\ live h m /\ live h xkeys /\ live h n /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c /\ disjoint xkeys m /\ disjoint xkeys c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let subkey = LSeq.sub (as_seq h0 xkeys) 0 32 in let ekey0 = LSeq.sub (as_seq h0 xkeys) 64 32 in let n1 = LSeq.sub (as_seq h0 n) 16 8 in let clen0 = Spec.get_len0 (v mlen) in let clen1 = v mlen - clen0 in let c0 = LSeq.sub (as_seq h0 c) 0 clen0 in let c1 = LSeq.sub (as_seq h0 c) clen0 clen1 in let block0 = LSeq.create 32 (u8 0) in let block0 = LSeq.update_sub block0 0 clen0 c0 in let block0 = LSeq.map2 (^.) block0 ekey0 in let m0 = LSeq.sub block0 0 clen0 in let m1 = Spec.Salsa20.salsa20_decrypt_bytes subkey n1 1 c1 in let msg = Seq.append m0 m1 in as_seq h1 m == msg)) let secretbox_open_detached_plain mlen m xkeys n c = push_frame (); let subkey = sub xkeys 0ul 32ul in let ekey0 = sub xkeys 64ul 32ul in let n1 = sub n 16ul 8ul in let mlen0 = get_len0 mlen in let mlen1 = mlen -! mlen0 in let c0 = sub c 0ul mlen0 in let c1 = sub c mlen0 mlen1 in let block0 = create 32ul (u8 0) in update_sub block0 0ul mlen0 c0; map2T 32ul block0 ( ^. ) block0 ekey0; let m0 = sub m 0ul mlen0 in let m1 = sub m mlen0 mlen1 in copy m0 (sub block0 0ul mlen0); salsa20_decrypt mlen1 m1 c1 subkey n1 1ul; let h1 = ST.get () in FStar.Seq.Properties.lemma_split (as_seq h1 m) (v mlen0); pop_frame () val secretbox_open_detached: mlen:size_t -> m:lbuffer uint8 mlen -> k:lbuffer uint8 32ul -> n:lbuffer uint8 24ul -> c:lbuffer uint8 mlen -> tag:lbuffer uint8 16ul -> Stack size_t (requires fun h -> live h c /\ live h m /\ live h k /\ live h n /\ live h tag /\ disjoint tag c /\ disjoint tag m /\ disjoint m n /\ disjoint c n /\ eq_or_disjoint m c) (ensures fun h0 r h1 -> modifies (loc m) h0 h1 /\ (let msg = Spec.secretbox_open_detached (as_seq h0 k) (as_seq h0 n) (as_seq h0 tag) (as_seq h0 c) in match r with | 0ul -> Some? msg /\ as_seq h1 m == Some?.v msg | _ -> None? msg))
{ "checked_file": "/", "dependencies": [ "Spec.SecretBox.fst.checked", "Spec.Salsa20.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteBuffer.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Streaming.Poly1305_32.fsti.checked", "Hacl.Salsa20.fst.checked", "Hacl.Poly1305_32.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.Properties.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.SecretBox.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Spec.SecretBox", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Poly1305_32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Salsa20", "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.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "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": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
mlen: Lib.IntTypes.size_t -> m: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen -> k: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> n: Lib.Buffer.lbuffer Lib.IntTypes.uint8 24ul -> c: Lib.Buffer.lbuffer Lib.IntTypes.uint8 mlen -> tag: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul -> FStar.HyperStack.ST.Stack Lib.IntTypes.size_t
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.IntTypes.size_t", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Lib.IntTypes.int_t", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.SecretBox.secretbox_open_detached_plain", "Prims.bool", "Lib.ByteBuffer.lbytes_eq", "Hacl.Streaming.Poly1305_32.mac", "Lib.Buffer.lbuffer_t", "Lib.Buffer.MUT", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.u8", "Lib.Buffer.sub", "Hacl.Impl.SecretBox.secretbox_init", "FStar.HyperStack.ST.push_frame" ]
[]
false
true
false
false
false
let secretbox_open_detached mlen m k n c tag =
push_frame (); let xkeys = create 96ul (u8 0) in secretbox_init xkeys k n; let mkey = sub xkeys 32ul 32ul in let tag' = create 16ul (u8 0) in Hacl.Streaming.Poly1305_32.mac tag' c mlen mkey; let res = if lbytes_eq tag tag' then (secretbox_open_detached_plain mlen m xkeys n c; 0ul) else 0xfffffffful in pop_frame (); res
false
FStar.Integers.fst
FStar.Integers.norm
val norm : x: a -> a
let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 70, "end_line": 24, "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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> a
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.iota", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let norm (#a: Type) (x: a) =
norm [iota; delta_attr [`%mark_for_norm]] x
false
FStar.Integers.fst
FStar.Integers.within_bounds
val within_bounds : sw: FStar.Integers.signed_width -> x: Prims.int -> Type0
let within_bounds sw x = norm (within_bounds' sw x)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 86, "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. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sw: FStar.Integers.signed_width -> x: Prims.int -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "Prims.int", "FStar.Integers.norm", "FStar.Integers.within_bounds'" ]
[]
false
false
false
true
true
let within_bounds sw x =
norm (within_bounds' sw x)
false
FStar.Integers.fst
FStar.Integers.nat_of_width
val nat_of_width : _: FStar.Integers.width -> FStar.Pervasives.Native.option Prims.int
let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 21, "end_line": 41, "start_col": 0, "start_line": 35 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: FStar.Integers.width -> FStar.Pervasives.Native.option Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.width", "FStar.Pervasives.Native.Some", "Prims.int", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option" ]
[]
false
false
false
true
false
let nat_of_width =
function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None
false
FStar.Integers.fst
FStar.Integers.cast_ok
val cast_ok : to: FStar.Integers.signed_width -> x: FStar.Integers.int_t from -> Type0
let cast_ok #from to (x:int_t from) = within_bounds to (v x)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 60, "end_line": 143, "start_col": 0, "start_line": 143 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
to: FStar.Integers.signed_width -> x: FStar.Integers.int_t from -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "FStar.Integers.int_t", "FStar.Integers.within_bounds", "FStar.Integers.v" ]
[]
false
false
false
false
true
let cast_ok #from to (x: int_t from) =
within_bounds to (v x)
false
FStar.Integers.fst
FStar.Integers.nat_of_fixed_width
val nat_of_fixed_width : w: FStar.Integers.fixed_width -> Prims.int
let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "end_line": 48, "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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite}
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
w: FStar.Integers.fixed_width -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.fixed_width", "FStar.Integers.nat_of_width", "Prims.int" ]
[]
false
false
false
true
false
let nat_of_fixed_width (w: fixed_width) =
match nat_of_width w with | Some v -> v
false
FStar.Integers.fst
FStar.Integers.fixed_width
val fixed_width : Type0
let fixed_width = w:width{w <> Winfinite}
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 43, "start_col": 0, "start_line": 43 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.width", "Prims.b2t", "Prims.op_disEquality", "FStar.Integers.Winfinite" ]
[]
false
false
false
true
true
let fixed_width =
w: width{w <> Winfinite}
false
FStar.Integers.fst
FStar.Integers.width_of_sw
val width_of_sw : _: FStar.Integers.signed_width -> FStar.Integers.width
let width_of_sw = function | Signed w -> w | Unsigned w -> w
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 57, "start_col": 0, "start_line": 55 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: FStar.Integers.signed_width -> FStar.Integers.width
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "FStar.Integers.width", "FStar.Integers.fixed_width" ]
[]
false
false
false
true
false
let width_of_sw =
function | Signed w -> w | Unsigned w -> w
false
FStar.Integers.fst
FStar.Integers.within_bounds'
val within_bounds' : sw: FStar.Integers.signed_width -> x: Prims.int -> Type0
let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 83, "start_col": 0, "start_line": 79 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sw: FStar.Integers.signed_width -> x: Prims.int -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "Prims.int", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Integers.nat_of_width", "FStar.Integers.width_of_sw", "FStar.Integers.width", "Prims.l_True", "FStar.Int.size", "FStar.Integers.fixed_width", "FStar.UInt.size" ]
[]
false
false
false
true
true
let within_bounds' sw (x: int) =
match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n
false
FStar.Integers.fst
FStar.Integers.v
val v (#sw: _) (x: int_t sw) : Tot (y: int_t (Signed Winfinite) {within_bounds sw y})
val v (#sw: _) (x: int_t sw) : Tot (y: int_t (Signed Winfinite) {within_bounds sw y})
let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 108, "start_col": 0, "start_line": 91 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int_t sw -> y: FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite) {FStar.Integers.within_bounds sw y}
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "FStar.Integers.int_t", "FStar.Integers.fixed_width", "FStar.UInt8.v", "FStar.UInt16.v", "FStar.UInt32.v", "FStar.UInt64.v", "FStar.UInt128.v", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.within_bounds", "FStar.Integers.width", "FStar.Int8.v", "FStar.Int16.v", "FStar.Int32.v", "FStar.Int64.v", "FStar.Int128.v" ]
[]
false
false
false
false
false
let v #sw (x: int_t sw) : Tot (y: int_t (Signed Winfinite) {within_bounds sw y}) =
match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x)
false
Hacl.SHA2.Vec128.fst
Hacl.SHA2.Vec128.sha224_4
val sha224_4 (dst0 dst1 dst2 dst3: lbuffer uint8 28ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3))
val sha224_4 (dst0 dst1 dst2 dst3: lbuffer uint8 28ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3))
let sha224_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 = let ib = ntup4 (input0,(input1,(input2,input3))) in let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in let h0 = ST.get() in assert (live_multi h0 ib); assert (live_multi h0 rb); assert (internally_disjoint rb); loc_multi4 rb; hash #SHA2_224 #M128 sha224_init4 sha224_update_nblocks4 sha224_update_last4 sha224_finish4 rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M128 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0); assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1); assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2); assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3)
{ "file_name": "code/sha2-mb/Hacl.SHA2.Vec128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 56, "start_col": 0, "start_line": 42 }
module Hacl.SHA2.Vec128 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Buffer open Lib.MultiBuffer open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST module Spec = Spec.Agile.Hash module SpecVec = Hacl.Spec.SHA2.Vec #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" [@CInline] private let sha224_init4 = init #SHA2_224 #M128 [@CInline] private let sha224_update4 = update #SHA2_224 #M128 [@CInline] private let sha224_update_nblocks4 = update_nblocks #SHA2_224 #M128 sha224_update4 [@CInline] private let sha224_update_last4 = update_last #SHA2_224 #M128 sha224_update4 [@CInline] private let sha224_finish4 = finish #SHA2_224 #M128 val sha224_4 (dst0 dst1 dst2 dst3: lbuffer uint8 28ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.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.SHA2.Vec128.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": "SpecVec" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dst0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 28ul -> dst1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 28ul -> dst2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 28ul -> dst3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 28ul -> input_len: Lib.IntTypes.size_t -> input0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> input1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> input2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> input3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Hash.Definitions.hash_len", "Spec.Hash.Definitions.SHA2_224", "Lib.MultiBuffer.op_Lens_Access", "FStar.Seq.Properties.lseq", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Vec.M128", "Lib.MultiBuffer.as_seq_multi", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "Hacl.Spec.SHA2.Equiv.hash_agile_lemma", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.SHA2.Generic.hash", "Hacl.SHA2.Vec128.sha224_init4", "Hacl.SHA2.Vec128.sha224_update_nblocks4", "Hacl.SHA2.Vec128.sha224_update_last4", "Hacl.SHA2.Vec128.sha224_finish4", "Lib.MultiBuffer.loc_multi4", "Lib.MultiBuffer.internally_disjoint", "Lib.MultiBuffer.live_multi", "Lib.NTuple.ntuple", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.NTuple.ntup4", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2" ]
[]
false
true
false
false
false
let sha224_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
let ib = ntup4 (input0, (input1, (input2, input3))) in let rb = ntup4 (dst0, (dst1, (dst2, dst3))) in let h0 = ST.get () in assert (live_multi h0 ib); assert (live_multi h0 rb); assert (internally_disjoint rb); loc_multi4 rb; hash #SHA2_224 #M128 sha224_init4 sha224_update_nblocks4 sha224_update_last4 sha224_finish4 rb input_len ib; let h1 = ST.get () in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M128 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(| 0 |) == as_seq h1 dst0); assert ((as_seq_multi h1 rb).(| 1 |) == as_seq h1 dst1); assert ((as_seq_multi h1 rb).(| 2 |) == as_seq h1 dst2); assert ((as_seq_multi h1 rb).(| 3 |) == as_seq h1 dst3)
false
FStar.Integers.fst
FStar.Integers.cast
val cast (#sw #sw': _) (from: int_t sw {within_bounds sw' (v from)}) : Tot (to: int_t sw' {norm (v from == v to)})
val cast (#sw #sw': _) (from: int_t sw {within_bounds sw' (v from)}) : Tot (to: int_t sw' {norm (v from == v to)})
let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 15, "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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
from: FStar.Integers.int_t sw {FStar.Integers.within_bounds sw' (FStar.Integers.v from)} -> to: FStar.Integers.int_t sw' {FStar.Integers.norm (FStar.Integers.v from == FStar.Integers.v to)}
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "FStar.Integers.int_t", "FStar.Integers.within_bounds", "FStar.Integers.v", "FStar.Integers.u", "FStar.Integers.norm", "Prims.eq2", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "Prims.l_or" ]
[]
false
false
false
false
false
let cast #sw #sw' (from: int_t sw {within_bounds sw' (v from)}) : Tot (to: int_t sw' {norm (v from == v to)}) =
u (v from)
false
FStar.Integers.fst
FStar.Integers.modulo
val modulo : sw: FStar.Integers.signed_width -> x: Prims.int -> y: Prims.pos{Signed? sw ==> y % 2 = 0} -> Prims.int
let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 184, "start_col": 0, "start_line": 181 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
sw: FStar.Integers.signed_width -> x: Prims.int -> y: Prims.pos{Signed? sw ==> y % 2 = 0} -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "Prims.int", "Prims.pos", "Prims.l_imp", "Prims.b2t", "FStar.Integers.uu___is_Signed", "Prims.op_Equality", "Prims.op_Modulus", "FStar.Integers.fixed_width", "FStar.Int.op_At_Percent" ]
[]
false
false
false
false
false
let modulo sw (x: int) (y: pos{Signed? sw ==> y % 2 = 0}) =
match sw with | Unsigned _ -> x % y | _ -> let open FStar.Int in x @% y
false
FStar.Integers.fst
FStar.Integers.op_Subtraction_Question
val ( -? ) (#sw: _{Unsigned? sw}) (x y: int_t sw) : Tot (int_t sw)
val ( -? ) (#sw: _{Unsigned? sw}) (x y: int_t sw) : Tot (int_t sw)
let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 235, "start_col": 0, "start_line": 224 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int_t sw -> y: FStar.Integers.int_t sw -> FStar.Integers.int_t sw
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "Prims.b2t", "FStar.Integers.uu___is_Unsigned", "FStar.Integers.int_t", "FStar.Integers.fixed_width", "FStar.UInt8.op_Subtraction_Question_Hat", "FStar.UInt16.op_Subtraction_Question_Hat", "FStar.UInt32.op_Subtraction_Question_Hat", "FStar.UInt64.op_Subtraction_Question_Hat", "FStar.UInt128.op_Subtraction_Question_Hat" ]
[]
false
false
false
false
false
let ( -? ) (#sw: _{Unsigned? sw}) (x y: int_t sw) : Tot (int_t sw) =
let Unsigned w = sw in match w with | W8 -> let open FStar.UInt8 in x -?^ y | W16 -> let open FStar.UInt16 in x -?^ y | W32 -> let open FStar.UInt32 in x -?^ y | W64 -> let open FStar.UInt64 in x -?^ y | W128 -> let open FStar.UInt128 in x -?^ y
false
FStar.Integers.fst
FStar.Integers.u
val u (#sw: _) (x: int_t (Signed Winfinite) {within_bounds sw x}) : Tot (y: int_t sw {norm (v x == v y)})
val u (#sw: _) (x: int_t (Signed Winfinite) {within_bounds sw x}) : Tot (y: int_t sw {norm (v x == v y)})
let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 131, "start_col": 0, "start_line": 113 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite) {FStar.Integers.within_bounds sw x} -> y: FStar.Integers.int_t sw {FStar.Integers.norm (FStar.Integers.v x == FStar.Integers.v y)}
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.within_bounds", "FStar.Integers.fixed_width", "FStar.UInt8.uint_to_t", "FStar.UInt16.uint_to_t", "FStar.UInt32.uint_to_t", "FStar.UInt64.uint_to_t", "FStar.UInt128.uint_to_t", "FStar.Integers.norm", "Prims.eq2", "Prims.l_or", "FStar.Integers.v", "FStar.Integers.width", "FStar.Int8.int_to_t", "FStar.Int16.int_to_t", "FStar.Int32.int_to_t", "FStar.Int64.int_to_t", "FStar.Int128.int_to_t" ]
[]
false
false
false
false
false
let u #sw (x: int_t (Signed Winfinite) {within_bounds sw x}) : Tot (y: int_t sw {norm (v x == v y)}) =
match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x)
false
FStar.Integers.fst
FStar.Integers.uint_8
val uint_8 : Type0
let uint_8 = int_t (Unsigned W8)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 521, "start_col": 0, "start_line": 521 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Unsigned", "FStar.Integers.W8" ]
[]
false
false
false
true
true
let uint_8 =
int_t (Unsigned W8)
false
FStar.Integers.fst
FStar.Integers.op_Subtraction_Percent
val ( -% ) (#sw: _{Unsigned? sw}) (x y: int_t sw) : Tot (int_t sw)
val ( -% ) (#sw: _{Unsigned? sw}) (x y: int_t sw) : Tot (int_t sw)
let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 37, "end_line": 251, "start_col": 0, "start_line": 240 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int_t sw -> y: FStar.Integers.int_t sw -> FStar.Integers.int_t sw
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "Prims.b2t", "FStar.Integers.uu___is_Unsigned", "FStar.Integers.int_t", "FStar.Integers.fixed_width", "FStar.UInt8.op_Subtraction_Percent_Hat", "FStar.UInt16.op_Subtraction_Percent_Hat", "FStar.UInt32.op_Subtraction_Percent_Hat", "FStar.UInt64.op_Subtraction_Percent_Hat", "FStar.UInt128.op_Subtraction_Percent_Hat" ]
[]
false
false
false
false
false
let ( -% ) (#sw: _{Unsigned? sw}) (x y: int_t sw) : Tot (int_t sw) =
let Unsigned w = sw in match w with | W8 -> let open FStar.UInt8 in x -%^ y | W16 -> let open FStar.UInt16 in x -%^ y | W32 -> let open FStar.UInt32 in x -%^ y | W64 -> let open FStar.UInt64 in x -%^ y | W128 -> let open FStar.UInt128 in x -%^ y
false
FStar.Integers.fst
FStar.Integers.uint_64
val uint_64 : Type0
let uint_64 = int_t (Unsigned W64)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 533, "start_col": 0, "start_line": 533 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Unsigned", "FStar.Integers.W64" ]
[]
false
false
false
true
true
let uint_64 =
int_t (Unsigned W64)
false
FStar.Integers.fst
FStar.Integers.uint_32
val uint_32 : Type0
let uint_32 = int_t (Unsigned W32)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 529, "start_col": 0, "start_line": 529 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Unsigned", "FStar.Integers.W32" ]
[]
false
false
false
true
true
let uint_32 =
int_t (Unsigned W32)
false
FStar.Integers.fst
FStar.Integers.uint_16
val uint_16 : Type0
let uint_16 = int_t (Unsigned W16)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 525, "start_col": 0, "start_line": 525 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Unsigned", "FStar.Integers.W16" ]
[]
false
false
false
true
true
let uint_16 =
int_t (Unsigned W16)
false
FStar.Integers.fst
FStar.Integers.int_8
val int_8 : Type0
let int_8 = int_t (Signed W8)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 541, "start_col": 0, "start_line": 541 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.W8" ]
[]
false
false
false
true
true
let int_8 =
int_t (Signed W8)
false
FStar.Integers.fst
FStar.Integers.int
val int : Type0
let int = int_t (Signed Winfinite)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 537, "start_col": 0, "start_line": 537 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.Winfinite" ]
[]
false
false
false
true
true
let int =
int_t (Signed Winfinite)
false
FStar.Integers.fst
FStar.Integers.int_16
val int_16 : Type0
let int_16 = int_t (Signed W16)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 545, "start_col": 0, "start_line": 545 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.W16" ]
[]
false
false
false
true
true
let int_16 =
int_t (Signed W16)
false
FStar.Integers.fst
FStar.Integers.int_32
val int_32 : Type0
let int_32 = int_t (Signed W32)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 549, "start_col": 0, "start_line": 549 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.W32" ]
[]
false
false
false
true
true
let int_32 =
int_t (Signed W32)
false
FStar.Integers.fst
FStar.Integers.int_64
val int_64 : Type0
let int_64 = int_t (Signed W64)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 553, "start_col": 0, "start_line": 553 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.W64" ]
[]
false
false
false
true
true
let int_64 =
int_t (Signed W64)
false
FStar.Integers.fst
FStar.Integers.nat
val nat : Type0
let nat = i:int{ i >= 0 }
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 571, "start_col": 0, "start_line": 571 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int", "Prims.b2t", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite" ]
[]
false
false
false
true
true
let nat =
i: int{i >= 0}
false
FStar.Integers.fst
FStar.Integers.int_128
val int_128 : Type0
let int_128 = int_t (Signed W128)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 557, "start_col": 0, "start_line": 557 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.W128" ]
[]
false
false
false
true
true
let int_128 =
int_t (Signed W128)
false
FStar.Integers.fst
FStar.Integers.ok
val ok : op: ( _: FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite) -> _: FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite) -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)) -> x: FStar.Integers.int_t sw -> y: FStar.Integers.int_t sw -> Type0
let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y))
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 567, "start_col": 0, "start_line": 561 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
op: ( _: FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite) -> _: FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite) -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)) -> x: FStar.Integers.int_t sw -> y: FStar.Integers.int_t sw -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "FStar.Integers.int_t", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.within_bounds", "FStar.Integers.v" ]
[]
false
false
false
false
true
let ok #sw (op: (int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x: int_t sw) (y: int_t sw) =
within_bounds sw (op (v x) (v y))
false
FStar.Integers.fst
FStar.Integers.pos
val pos : Type0
let pos = i:nat{ 0 < i }
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 575, "start_col": 0, "start_line": 575 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.nat", "Prims.b2t", "FStar.Integers.op_Less", "FStar.Integers.Signed", "FStar.Integers.Winfinite" ]
[]
false
false
false
true
true
let pos =
i: nat{0 < i}
false
FStar.Integers.fst
FStar.Integers.f_nat
val f_nat : x: FStar.Integers.nat -> y: FStar.Integers.nat -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
let f_nat (x:nat) (y:nat) = x + y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 581, "start_col": 0, "start_line": 581 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.nat -> y: FStar.Integers.nat -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.nat", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
true
false
let f_nat (x y: nat) =
x + y
false
FStar.Integers.fst
FStar.Integers.f_int
val f_int : x: FStar.Integers.int -> y: FStar.Integers.int -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
let f_int (x:int) (y:int) = x + y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 580, "start_col": 0, "start_line": 580 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int -> y: FStar.Integers.int -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
true
false
let f_int (x y: int) =
x + y
false
FStar.Integers.fst
FStar.Integers.f_int_16
val f_int_16 : x: FStar.Integers.int_16 -> y: FStar.Integers.int_16{FStar.Integers.ok FStar.Integers.op_Plus x y} -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.W16)
let f_int_16 (x:int_16) (y:int_16{ok (+) x y}) = x + y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 584, "start_col": 0, "start_line": 584 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int_16 -> y: FStar.Integers.int_16{FStar.Integers.ok FStar.Integers.op_Plus x y} -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.W16)
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.int_16", "FStar.Integers.ok", "FStar.Integers.Signed", "FStar.Integers.W16", "FStar.Integers.op_Plus", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
false
false
let f_int_16 (x: int_16) (y: int_16{ok ( + ) x y}) =
x + y
false
FStar.Integers.fst
FStar.Integers.op_Slash
val ( / ) (#sw: signed_width{sw <> Unsigned W128}) (x: int_t sw) (y: int_t sw { 0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw ((v x) `FStar.Int.op_Slash` (v y))) }) : Tot (int_t sw)
val ( / ) (#sw: signed_width{sw <> Unsigned W128}) (x: int_t sw) (y: int_t sw { 0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw ((v x) `FStar.Int.op_Slash` (v y))) }) : Tot (int_t sw)
let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y)
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 43, "end_line": 406, "start_col": 0, "start_line": 389 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.int_t sw -> y: FStar.Integers.int_t sw { 0 <> FStar.Integers.v y /\ (match sw with | FStar.Integers.Unsigned _ -> FStar.Integers.within_bounds sw (FStar.Integers.v x / FStar.Integers.v y) | FStar.Integers.Signed _ -> FStar.Integers.within_bounds sw (FStar.Integers.v x / FStar.Integers.v y)) } -> FStar.Integers.int_t sw
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.signed_width", "Prims.b2t", "Prims.op_disEquality", "FStar.Integers.Unsigned", "FStar.Integers.W128", "FStar.Integers.int_t", "Prims.l_and", "Prims.int", "FStar.Integers.v", "FStar.Integers.fixed_width", "FStar.Integers.within_bounds", "Prims.op_Division", "FStar.Integers.width", "FStar.Int.op_Slash", "Prims.logical", "FStar.UInt8.op_Slash_Hat", "FStar.UInt16.op_Slash_Hat", "FStar.UInt32.op_Slash_Hat", "FStar.UInt64.op_Slash_Hat", "FStar.Int8.op_Slash_Hat", "FStar.Int16.op_Slash_Hat", "FStar.Int32.op_Slash_Hat", "FStar.Int64.op_Slash_Hat", "FStar.Int128.op_Slash_Hat" ]
[]
false
false
false
false
false
let ( / ) (#sw: signed_width{sw <> Unsigned W128}) (x: int_t sw) (y: int_t sw { 0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw ((v x) `FStar.Int.op_Slash` (v y))) }) : Tot (int_t sw) =
match sw with | Signed Winfinite -> x / y | Unsigned W8 -> let open FStar.UInt8 in x /^ y | Unsigned W16 -> let open FStar.UInt16 in x /^ y | Unsigned W32 -> let open FStar.UInt32 in x /^ y | Unsigned W64 -> let open FStar.UInt64 in x /^ y | Signed W8 -> let open FStar.Int8 in x /^ y | Signed W16 -> let open FStar.Int16 in x /^ y | Signed W32 -> let open FStar.Int32 in x /^ y | Signed W64 -> let open FStar.Int64 in x /^ y | Signed W128 -> let open FStar.Int128 in x /^ y
false
FStar.Integers.fst
FStar.Integers.f_nat_int_pos
val f_nat_int_pos : x: FStar.Integers.nat -> y: FStar.Integers.int -> z: FStar.Integers.pos -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 53, "end_line": 582, "start_col": 0, "start_line": 582 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.nat -> y: FStar.Integers.int -> z: FStar.Integers.pos -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.nat", "FStar.Integers.int", "FStar.Integers.pos", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
true
false
let f_nat_int_pos (x: nat) (y: int) (z: pos) =
x + y + z
false
FStar.Integers.fst
FStar.Integers.f_uint_8
val f_uint_8 : x: FStar.Integers.uint_8 -> y: FStar.Integers.uint_8{FStar.Integers.ok FStar.Integers.op_Plus x y} -> FStar.Integers.int_t (FStar.Integers.Unsigned FStar.Integers.W8)
let f_uint_8 (x:uint_8) (y:uint_8{ok (+) x y}) = x + y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 583, "start_col": 0, "start_line": 583 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.uint_8 -> y: FStar.Integers.uint_8{FStar.Integers.ok FStar.Integers.op_Plus x y} -> FStar.Integers.int_t (FStar.Integers.Unsigned FStar.Integers.W8)
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.uint_8", "FStar.Integers.ok", "FStar.Integers.Unsigned", "FStar.Integers.W8", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
false
false
let f_uint_8 (x: uint_8) (y: uint_8{ok ( + ) x y}) =
x + y
false
FStar.Integers.fst
FStar.Integers.i
val i : x: Prims.nat -> y: Prims.nat -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
let i (x:Prims.nat) (y:Prims.nat) = x + y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 587, "start_col": 0, "start_line": 587 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z let f_uint_8 (x:uint_8) (y:uint_8{ok (+) x y}) = x + y let f_int_16 (x:int_16) (y:int_16{ok (+) x y}) = x + y let g (x:uint_32) (y:uint_32{ok ( * ) y y /\ ok (+) x (y * y)}) = x + y * y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.nat -> y: Prims.nat -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
true
false
let i (x y: Prims.nat) =
x + y
false
FStar.Integers.fst
FStar.Integers.j
val j : x: Prims.int -> y: Prims.nat -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
let j (x:Prims.int) (y:Prims.nat) = x - y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 588, "start_col": 0, "start_line": 588 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z let f_uint_8 (x:uint_8) (y:uint_8{ok (+) x y}) = x + y let f_int_16 (x:int_16) (y:int_16{ok (+) x y}) = x + y let g (x:uint_32) (y:uint_32{ok ( * ) y y /\ ok (+) x (y * y)}) = x + y * y let h (x:Prims.nat) (y:Prims.nat): nat = u x + u y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> y: Prims.nat -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "Prims.nat", "FStar.Integers.op_Subtraction", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
true
false
let j (x: Prims.int) (y: Prims.nat) =
x - y
false
Spec.Hash.Incremental.fst
Spec.Hash.Incremental._sync_decl
val _sync_decl : Type0
val _sync_decl : Type0
let _sync_decl = unit
{ "file_name": "specs/lemmas/Spec.Hash.Incremental.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 21, "end_line": 17, "start_col": 0, "start_line": 17 }
module Spec.Hash.Incremental module S = FStar.Seq module Blake2 = Spec.Blake2 open Spec.Agile.Hash open Spec.Hash.Definitions friend Spec.Agile.Hash open FStar.Mul module Loops = Lib.LoopCombinators #set-options "--fuel 0 --ifuel 0 --z3rlimit 50"
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Incremental.fsti.checked", "Spec.MD.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Blake2.Incremental.fsti.checked", "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Hash.Incremental.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Blake2" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.UpdateMulti", "short_module": "UpdateMulti" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Blake2" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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
Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.unit" ]
[]
false
false
false
true
true
let _sync_decl =
unit
false
FStar.Integers.fst
FStar.Integers.g
val g : x: FStar.Integers.uint_32 -> y: FStar.Integers.uint_32 { FStar.Integers.ok FStar.Integers.op_Star y y /\ FStar.Integers.ok FStar.Integers.op_Plus x (y * y) } -> FStar.Integers.int_t (FStar.Integers.Unsigned FStar.Integers.W32)
let g (x:uint_32) (y:uint_32{ok ( * ) y y /\ ok (+) x (y * y)}) = x + y * y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 75, "end_line": 585, "start_col": 0, "start_line": 585 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z let f_uint_8 (x:uint_8) (y:uint_8{ok (+) x y}) = x + y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.Integers.uint_32 -> y: FStar.Integers.uint_32 { FStar.Integers.ok FStar.Integers.op_Star y y /\ FStar.Integers.ok FStar.Integers.op_Plus x (y * y) } -> FStar.Integers.int_t (FStar.Integers.Unsigned FStar.Integers.W32)
Prims.Tot
[ "total" ]
[]
[ "FStar.Integers.uint_32", "Prims.l_and", "FStar.Integers.ok", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.op_Star", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.op_Plus", "FStar.Integers.int_t" ]
[]
false
false
false
false
false
let g (x: uint_32) (y: uint_32{ok ( * ) y y /\ ok ( + ) x (y * y)}) =
x + y * y
false
FStar.Integers.fst
FStar.Integers.k
val k : x: Prims.int -> y: Prims.int -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
let k (x:Prims.int) (y:Prims.int) = x * y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 41, "end_line": 589, "start_col": 0, "start_line": 589 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z let f_uint_8 (x:uint_8) (y:uint_8{ok (+) x y}) = x + y let f_int_16 (x:int_16) (y:int_16{ok (+) x y}) = x + y let g (x:uint_32) (y:uint_32{ok ( * ) y y /\ ok (+) x (y * y)}) = x + y * y let h (x:Prims.nat) (y:Prims.nat): nat = u x + u y let i (x:Prims.nat) (y:Prims.nat) = x + y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> y: Prims.int -> FStar.Integers.int_t (FStar.Integers.Signed FStar.Integers.Winfinite)
Prims.Tot
[ "total" ]
[]
[ "Prims.int", "FStar.Integers.op_Star", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.int_t" ]
[]
false
false
false
true
false
let k (x y: Prims.int) =
x * y
false
Hacl.SHA2.Vec128.fst
Hacl.SHA2.Vec128.sha256_4
val sha256_4 (dst0 dst1 dst2 dst3: lbuffer uint8 32ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_256 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_256 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_256 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_256 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_256 (as_seq h0 input3))
val sha256_4 (dst0 dst1 dst2 dst3: lbuffer uint8 32ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_256 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_256 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_256 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_256 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_256 (as_seq h0 input3))
let sha256_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 = let ib = ntup4 (input0,(input1,(input2,input3))) in let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in let h0 = ST.get() in assert (live_multi h0 ib); assert (live_multi h0 rb); assert (internally_disjoint rb); loc_multi4 rb; hash #SHA2_256 #M128 sha256_init4 sha256_update_nblocks4 sha256_update_last4 sha256_finish4 rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M128 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0); assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1); assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2); assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3)
{ "file_name": "code/sha2-mb/Hacl.SHA2.Vec128.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 55, "end_line": 91, "start_col": 0, "start_line": 77 }
module Hacl.SHA2.Vec128 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.IntTypes open Lib.NTuple open Lib.Buffer open Lib.MultiBuffer open Spec.Hash.Definitions open Hacl.Spec.SHA2.Vec open Hacl.Impl.SHA2.Generic module ST = FStar.HyperStack.ST module Spec = Spec.Agile.Hash module SpecVec = Hacl.Spec.SHA2.Vec #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" [@CInline] private let sha224_init4 = init #SHA2_224 #M128 [@CInline] private let sha224_update4 = update #SHA2_224 #M128 [@CInline] private let sha224_update_nblocks4 = update_nblocks #SHA2_224 #M128 sha224_update4 [@CInline] private let sha224_update_last4 = update_last #SHA2_224 #M128 sha224_update4 [@CInline] private let sha224_finish4 = finish #SHA2_224 #M128 val sha224_4 (dst0 dst1 dst2 dst3: lbuffer uint8 28ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_224 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_224 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_224 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_224 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_224 (as_seq h0 input3)) let sha224_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 = let ib = ntup4 (input0,(input1,(input2,input3))) in let rb = ntup4 (dst0,(dst1,(dst2,dst3))) in let h0 = ST.get() in assert (live_multi h0 ib); assert (live_multi h0 rb); assert (internally_disjoint rb); loc_multi4 rb; hash #SHA2_224 #M128 sha224_init4 sha224_update_nblocks4 sha224_update_last4 sha224_finish4 rb input_len ib; let h1 = ST.get() in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_224 #M128 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(|0|) == as_seq h1 dst0); assert ((as_seq_multi h1 rb).(|1|) == as_seq h1 dst1); assert ((as_seq_multi h1 rb).(|2|) == as_seq h1 dst2); assert ((as_seq_multi h1 rb).(|3|) == as_seq h1 dst3) [@CInline] private let sha256_init4 = init #SHA2_256 #M128 [@CInline] private let sha256_update4 = update #SHA2_256 #M128 [@CInline] private let sha256_update_nblocks4 = update_nblocks #SHA2_256 #M128 sha256_update4 [@CInline] private let sha256_update_last4 = update_last #SHA2_256 #M128 sha256_update4 [@CInline] private let sha256_finish4 = finish #SHA2_256 #M128 val sha256_4 (dst0 dst1 dst2 dst3: lbuffer uint8 32ul) (input_len:size_t) (input0 input1 input2 input3: lbuffer uint8 input_len) : Stack unit (requires fun h0 -> v input_len `less_than_max_input_length` SHA2_256 /\ live4 h0 input0 input1 input2 input3 /\ live4 h0 dst0 dst1 dst2 dst3 /\ internally_disjoint4 dst0 dst1 dst2 dst3) (ensures fun h0 _ h1 -> modifies (loc dst0 |+| loc dst1 |+| loc dst2 |+| loc dst3) h0 h1 /\ as_seq h1 dst0 == Spec.hash SHA2_256 (as_seq h0 input0) /\ as_seq h1 dst1 == Spec.hash SHA2_256 (as_seq h0 input1) /\ as_seq h1 dst2 == Spec.hash SHA2_256 (as_seq h0 input2) /\ as_seq h1 dst3 == Spec.hash SHA2_256 (as_seq h0 input3))
{ "checked_file": "/", "dependencies": [ "Spec.Hash.Definitions.fst.checked", "Spec.Agile.Hash.fsti.checked", "prims.fst.checked", "Lib.NTuple.fsti.checked", "Lib.MultiBuffer.fst.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.SHA2.Vec.fst.checked", "Hacl.Spec.SHA2.Equiv.fst.checked", "Hacl.Impl.SHA2.Generic.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.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.SHA2.Vec128.fst" }
[ { "abbrev": true, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": "SpecVec" }, { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Spec" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.SHA2.Generic", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.SHA2.Vec", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Lib.MultiBuffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.NTuple", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "Hacl.SHA2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
dst0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> dst1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> dst2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> dst3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> input_len: Lib.IntTypes.size_t -> input0: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> input1: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> input2: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> input3: Lib.Buffer.lbuffer Lib.IntTypes.uint8 input_len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint8", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.size_t", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.seq", "Prims.l_or", "Prims.nat", "FStar.Seq.Base.length", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Hash.Definitions.hash_len", "Spec.Hash.Definitions.SHA2_256", "Lib.MultiBuffer.op_Lens_Access", "FStar.Seq.Properties.lseq", "Hacl.Spec.SHA2.Vec.lanes", "Hacl.Spec.SHA2.Vec.M128", "Lib.MultiBuffer.as_seq_multi", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "Hacl.Spec.SHA2.Equiv.hash_agile_lemma", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.SHA2.Generic.hash", "Hacl.SHA2.Vec128.sha256_init4", "Hacl.SHA2.Vec128.sha256_update_nblocks4", "Hacl.SHA2.Vec128.sha256_update_last4", "Hacl.SHA2.Vec128.sha256_finish4", "Lib.MultiBuffer.loc_multi4", "Lib.MultiBuffer.internally_disjoint", "Lib.MultiBuffer.live_multi", "Lib.NTuple.ntuple", "Lib.Buffer.lbuffer_t", "Lib.IntTypes.int_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Lib.NTuple.ntup4", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.tuple2" ]
[]
false
true
false
false
false
let sha256_4 dst0 dst1 dst2 dst3 input_len input0 input1 input2 input3 =
let ib = ntup4 (input0, (input1, (input2, input3))) in let rb = ntup4 (dst0, (dst1, (dst2, dst3))) in let h0 = ST.get () in assert (live_multi h0 ib); assert (live_multi h0 rb); assert (internally_disjoint rb); loc_multi4 rb; hash #SHA2_256 #M128 sha256_init4 sha256_update_nblocks4 sha256_update_last4 sha256_finish4 rb input_len ib; let h1 = ST.get () in Hacl.Spec.SHA2.Equiv.hash_agile_lemma #SHA2_256 #M128 (v input_len) (as_seq_multi h0 ib); assert ((as_seq_multi h1 rb).(| 0 |) == as_seq h1 dst0); assert ((as_seq_multi h1 rb).(| 1 |) == as_seq h1 dst1); assert ((as_seq_multi h1 rb).(| 2 |) == as_seq h1 dst2); assert ((as_seq_multi h1 rb).(| 3 |) == as_seq h1 dst3)
false
FStar.Integers.fst
FStar.Integers.h
val h (x y: Prims.nat) : nat
val h (x y: Prims.nat) : nat
let h (x:Prims.nat) (y:Prims.nat): nat = u x + u y
{ "file_name": "ulib/FStar.Integers.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 586, "start_col": 0, "start_line": 586 }
(* 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.Integers #set-options "--initial_ifuel 2 --max_ifuel 2 --initial_fuel 0 --max_fuel 0" irreducible let mark_for_norm = () unfold let norm (#a:Type) (x:a) = norm [iota; delta_attr [`%mark_for_norm]] x type width = | W8 | W16 | W32 | W64 | W128 | Winfinite [@@mark_for_norm] let nat_of_width = function | W8 -> Some 8 | W16 -> Some 16 | W32 -> Some 32 | W64 -> Some 64 | W128 -> Some 128 | Winfinite -> None let fixed_width = w:width{w <> Winfinite} [@@mark_for_norm] let nat_of_fixed_width (w:fixed_width) = match nat_of_width w with | Some v -> v type signed_width = | Signed of width | Unsigned of fixed_width //We don't support (Unsigned WInfinite); use nat instead [@@mark_for_norm] let width_of_sw = function | Signed w -> w | Unsigned w -> w [@@mark_for_norm] noextract inline_for_extraction let int_t sw : Tot Type0 = match sw with | Unsigned W8 -> FStar.UInt8.t | Unsigned W16 -> FStar.UInt16.t | Unsigned W32 -> FStar.UInt32.t | Unsigned W64 -> FStar.UInt64.t | Unsigned W128 -> FStar.UInt128.t | Signed Winfinite -> int | Signed W8 -> FStar.Int8.t | Signed W16 -> FStar.Int16.t | Signed W32 -> FStar.Int32.t | Signed W64 -> FStar.Int64.t | Signed W128 -> FStar.Int128.t [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let within_bounds' sw (x:int) = match sw, nat_of_width (width_of_sw sw) with | Signed _, None -> True | Signed _, Some n -> FStar.Int.size x n | Unsigned _, Some n -> FStar.UInt.size x n unfold let within_bounds sw x = norm (within_bounds' sw x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let v #sw (x:int_t sw) : Tot (y:int_t (Signed Winfinite){within_bounds sw y}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.v x | W16 -> FStar.UInt16.v x | W32 -> FStar.UInt32.v x | W64 -> FStar.UInt64.v x | W128 -> FStar.UInt128.v x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.v x | W16 -> FStar.Int16.v x | W32 -> FStar.Int32.v x | W64 -> FStar.Int64.v x | W128 -> FStar.Int128.v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let u #sw (x:int_t (Signed Winfinite){within_bounds sw x}) : Tot (y:int_t sw{norm (v x == v y)}) = match sw with | Unsigned w -> (match w with | W8 -> FStar.UInt8.uint_to_t x | W16 -> FStar.UInt16.uint_to_t x | W32 -> FStar.UInt32.uint_to_t x | W64 -> FStar.UInt64.uint_to_t x | W128 -> FStar.UInt128.uint_to_t x) | Signed w -> (match w with | Winfinite -> x | W8 -> FStar.Int8.int_to_t x | W16 -> FStar.Int16.int_to_t x | W32 -> FStar.Int32.int_to_t x | W64 -> FStar.Int64.int_to_t x | W128 -> FStar.Int128.int_to_t x) irreducible noextract let cast #sw #sw' (from:int_t sw{within_bounds sw' (v from)}) : Tot (to:int_t sw'{norm (v from == v to)}) = u (v from) [@@mark_for_norm] unfold noextract let cast_ok #from to (x:int_t from) = within_bounds to (v x) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( + ) #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x + v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x + y | Unsigned W8 -> FStar.UInt8.(x +^ y) | Unsigned W16 -> FStar.UInt16.(x +^ y) | Unsigned W32 -> FStar.UInt32.(x +^ y) | Unsigned W64 -> FStar.UInt64.(x +^ y) | Unsigned W128 -> FStar.UInt128.(x +^ y) | Signed W8 -> FStar.Int8.(x +^ y) | Signed W16 -> FStar.Int16.(x +^ y) | Signed W32 -> FStar.Int32.(x +^ y) | Signed W64 -> FStar.Int64.(x +^ y) | Signed W128 -> FStar.Int128.(x +^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +? ) (#w:fixed_width) (x:int_t (Unsigned w)) (y:int_t (Unsigned w)) : Tot (int_t (Unsigned w)) = match w with | W8 -> FStar.UInt8.(x +?^ y) | W16 -> FStar.UInt16.(x +?^ y) | W32 -> FStar.UInt32.(x +?^ y) | W64 -> FStar.UInt64.(x +?^ y) | W128 -> FStar.UInt128.(x +?^ y) [@@mark_for_norm; strict_on_arguments [0]] noextract let modulo sw (x:int) (y:pos{Signed? sw ==> y%2=0}) = match sw with | Unsigned _ -> x % y | _ -> FStar.Int.(x @% y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( +% ) (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x +%^ y) | W16 -> FStar.UInt16.(x +%^ y) | W32 -> FStar.UInt32.(x +%^ y) | W64 -> FStar.UInt64.(x +%^ y) | W128 -> FStar.UInt128.(x +%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction #sw (x:int_t sw) (y:int_t sw{within_bounds sw (v x - v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x - y | Unsigned W8 -> FStar.UInt8.(x -^ y) | Unsigned W16 -> FStar.UInt16.(x -^ y) | Unsigned W32 -> FStar.UInt32.(x -^ y) | Unsigned W64 -> FStar.UInt64.(x -^ y) | Unsigned W128 -> FStar.UInt128.(x -^ y) | Signed W8 -> FStar.Int8.(x -^ y) | Signed W16 -> FStar.Int16.(x -^ y) | Signed W32 -> FStar.Int32.(x -^ y) | Signed W64 -> FStar.Int64.(x -^ y) | Signed W128 -> FStar.Int128.(x -^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Question (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -?^ y) | W16 -> FStar.UInt16.(x -?^ y) | W32 -> FStar.UInt32.(x -?^ y) | W64 -> FStar.UInt64.(x -?^ y) | W128 -> FStar.UInt128.(x -?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Subtraction_Percent (#sw:_{Unsigned? sw}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x -%^ y) | W16 -> FStar.UInt16.(x -%^ y) | W32 -> FStar.UInt32.(x -%^ y) | W64 -> FStar.UInt64.(x -%^ y) | W128 -> FStar.UInt128.(x -%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let op_Minus (#sw:_{Signed? sw}) (x:int_t sw{within_bounds sw (0 - v x)}) : Tot (int_t sw) = let Signed w = sw in match w with | Winfinite -> 0 - x | W8 -> FStar.Int8.(0y -^ x) | W16 -> FStar.Int16.(0s -^ x) | W32 -> FStar.Int32.(0l -^ x) | W64 -> FStar.Int64.(0L -^ x) | W128 -> FStar.Int128.(int_to_t 0 -^ x) open FStar.Mul [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( * ) (#sw:signed_width{width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw{within_bounds sw (v x * v y)}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x * y | Unsigned W8 -> FStar.UInt8.(x *^ y) | Unsigned W16 -> FStar.UInt16.(x *^ y) | Unsigned W32 -> FStar.UInt32.(x *^ y) | Unsigned W64 -> FStar.UInt64.(x *^ y) | Signed W8 -> FStar.Int8.(x *^ y) | Signed W16 -> FStar.Int16.(x *^ y) | Signed W32 -> FStar.Int32.(x *^ y) | Signed W64 -> FStar.Int64.(x *^ y) | Signed W128 -> FStar.Int128.(x *^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *? ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *?^ y) | W16 -> FStar.UInt16.(x *?^ y) | W32 -> FStar.UInt32.(x *?^ y) | W64 -> FStar.UInt64.(x *?^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( *% ) (#sw:_{Unsigned? sw /\ width_of_sw sw <> W128}) (x:int_t sw) (y:int_t sw) : Tot (int_t sw) = let Unsigned w = sw in match w with | W8 -> FStar.UInt8.(x *%^ y) | W16 -> FStar.UInt16.(x *%^ y) | W32 -> FStar.UInt32.(x *%^ y) | W64 -> FStar.UInt64.(x *%^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( > ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x > y | Unsigned W8 -> FStar.UInt8.(x >^ y) | Unsigned W16 -> FStar.UInt16.(x >^ y) | Unsigned W32 -> FStar.UInt32.(x >^ y) | Unsigned W64 -> FStar.UInt64.(x >^ y) | Unsigned W128 -> FStar.UInt128.(x >^ y) | Signed W8 -> FStar.Int8.(x >^ y) | Signed W16 -> FStar.Int16.(x >^ y) | Signed W32 -> FStar.Int32.(x >^ y) | Signed W64 -> FStar.Int64.(x >^ y) | Signed W128 -> FStar.Int128.(x >^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x >= y | Unsigned W8 -> FStar.UInt8.(x >=^ y) | Unsigned W16 -> FStar.UInt16.(x >=^ y) | Unsigned W32 -> FStar.UInt32.(x >=^ y) | Unsigned W64 -> FStar.UInt64.(x >=^ y) | Unsigned W128 -> FStar.UInt128.(x >=^ y) | Signed W8 -> FStar.Int8.(x >=^ y) | Signed W16 -> FStar.Int16.(x >=^ y) | Signed W32 -> FStar.Int32.(x >=^ y) | Signed W64 -> FStar.Int64.(x >=^ y) | Signed W128 -> FStar.Int128.(x >=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( < ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x < y | Unsigned W8 -> FStar.UInt8.(x <^ y) | Unsigned W16 -> FStar.UInt16.(x <^ y) | Unsigned W32 -> FStar.UInt32.(x <^ y) | Unsigned W64 -> FStar.UInt64.(x <^ y) | Unsigned W128 -> FStar.UInt128.(x <^ y) | Signed W8 -> FStar.Int8.(x <^ y) | Signed W16 -> FStar.Int16.(x <^ y) | Signed W32 -> FStar.Int32.(x <^ y) | Signed W64 -> FStar.Int64.(x <^ y) | Signed W128 -> FStar.Int128.(x <^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <= ) #sw (x:int_t sw) (y:int_t sw) : bool = match sw with | Signed Winfinite -> x <= y | Unsigned W8 -> FStar.UInt8.(x <=^ y) | Unsigned W16 -> FStar.UInt16.(x <=^ y) | Unsigned W32 -> FStar.UInt32.(x <=^ y) | Unsigned W64 -> FStar.UInt64.(x <=^ y) | Unsigned W128 -> FStar.UInt128.(x <=^ y) | Signed W8 -> FStar.Int8.(x <=^ y) | Signed W16 -> FStar.Int16.(x <=^ y) | Signed W32 -> FStar.Int32.(x <=^ y) | Signed W64 -> FStar.Int64.(x <=^ y) | Signed W128 -> FStar.Int128.(x <=^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( / ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (v x / v y) | Signed _ -> within_bounds sw (v x `FStar.Int.op_Slash` v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x / y | Unsigned W8 -> FStar.UInt8.(x /^ y) | Unsigned W16 -> FStar.UInt16.(x /^ y) | Unsigned W32 -> FStar.UInt32.(x /^ y) | Unsigned W64 -> FStar.UInt64.(x /^ y) | Signed W8 -> FStar.Int8.(x /^ y) | Signed W16 -> FStar.Int16.(x /^ y) | Signed W32 -> FStar.Int32.(x /^ y) | Signed W64 -> FStar.Int64.(x /^ y) | Signed W128 -> FStar.Int128.(x /^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( % ) (#sw:signed_width{sw <> Unsigned W128}) (x:int_t sw) (y:int_t sw{0 <> (v y <: Prims.int) /\ (match sw with | Unsigned _ -> within_bounds sw (FStar.UInt.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y)) | Signed Winfinite -> True | Signed _ -> within_bounds sw (FStar.Int.mod #(nat_of_fixed_width (width_of_sw sw)) (v x) (v y))) /\ within_bounds sw (FStar.Int.op_Slash (v x) (v y))}) : Tot (int_t sw) = match sw with | Signed Winfinite -> x % y | Unsigned W8 -> FStar.UInt8.(x %^ y) | Unsigned W16 -> FStar.UInt16.(x %^ y) | Unsigned W32 -> FStar.UInt32.(x %^ y) | Unsigned W64 -> FStar.UInt64.(x %^ y) | Signed W8 -> FStar.Int8.(x %^ y) | Signed W16 -> FStar.Int16.(x %^ y) | Signed W32 -> FStar.Int32.(x %^ y) | Signed W64 -> FStar.Int64.(x %^ y) | Signed W128 -> FStar.Int128.(x %^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( ^^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x ^^ y) | Unsigned W16 -> FStar.UInt16.(x ^^ y) | Unsigned W32 -> FStar.UInt32.(x ^^ y) | Unsigned W64 -> FStar.UInt64.(x ^^ y) | Unsigned W128 -> FStar.UInt128.(x ^^ y) | Signed W8 -> FStar.Int8.(x ^^ y) | Signed W16 -> FStar.Int16.(x ^^ y) | Signed W32 -> FStar.Int32.(x ^^ y) | Signed W64 -> FStar.Int64.(x ^^ y) | Signed W128 -> FStar.Int128.(x ^^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( &^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x &^ y) | Unsigned W16 -> FStar.UInt16.(x &^ y) | Unsigned W32 -> FStar.UInt32.(x &^ y) | Unsigned W64 -> FStar.UInt64.(x &^ y) | Unsigned W128 -> FStar.UInt128.(x &^ y) | Signed W8 -> FStar.Int8.(x &^ y) | Signed W16 -> FStar.Int16.(x &^ y) | Signed W32 -> FStar.Int32.(x &^ y) | Signed W64 -> FStar.Int64.(x &^ y) | Signed W128 -> FStar.Int128.(x &^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( |^ ) #sw (x:int_t sw) (y:int_t sw{width_of_sw sw <> Winfinite}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x |^ y) | Unsigned W16 -> FStar.UInt16.(x |^ y) | Unsigned W32 -> FStar.UInt32.(x |^ y) | Unsigned W64 -> FStar.UInt64.(x |^ y) | Unsigned W128 -> FStar.UInt128.(x |^ y) | Signed W8 -> FStar.Int8.(x |^ y) | Signed W16 -> FStar.Int16.(x |^ y) | Signed W32 -> FStar.Int32.(x |^ y) | Signed W64 -> FStar.Int64.(x |^ y) | Signed W128 -> FStar.Int128.(x |^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( <<^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw) /\ (Signed? sw ==> within_bounds sw (v x * pow2 (v y)))}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x <<^ y) | Unsigned W16 -> FStar.UInt16.(x <<^ y) | Unsigned W32 -> FStar.UInt32.(x <<^ y) | Unsigned W64 -> FStar.UInt64.(x <<^ y) | Unsigned W128 -> FStar.UInt128.(x <<^ y) | Signed W8 -> FStar.Int8.(x <<^ y) | Signed W16 -> FStar.Int16.(x <<^ y) | Signed W32 -> FStar.Int32.(x <<^ y) | Signed W64 -> FStar.Int64.(x <<^ y) | Signed W128 -> FStar.Int128.(x <<^ y) [@@mark_for_norm; strict_on_arguments [0]] unfold noextract let ( >>^ ) #sw (x:int_t sw{0 <= v x}) (y:int_t (Unsigned W32){width_of_sw sw <> Winfinite /\ v y < nat_of_fixed_width (width_of_sw sw)}) : Tot (int_t sw) = match sw with | Unsigned W8 -> FStar.UInt8.(x >>^ y) | Unsigned W16 -> FStar.UInt16.(x >>^ y) | Unsigned W32 -> FStar.UInt32.(x >>^ y) | Unsigned W64 -> FStar.UInt64.(x >>^ y) | Unsigned W128 -> FStar.UInt128.(x >>^ y) | Signed W8 -> FStar.Int8.(x >>^ y) | Signed W16 -> FStar.Int16.(x >>^ y) | Signed W32 -> FStar.Int32.(x >>^ y) | Signed W64 -> FStar.Int64.(x >>^ y) | Signed W128 -> FStar.Int128.(x >>^ y) [@@mark_for_norm] unfold let uint_8 = int_t (Unsigned W8) [@@mark_for_norm] unfold let uint_16 = int_t (Unsigned W16) [@@mark_for_norm] unfold let uint_32 = int_t (Unsigned W32) [@@mark_for_norm] unfold let uint_64 = int_t (Unsigned W64) [@@mark_for_norm] unfold let int = int_t (Signed Winfinite) [@@mark_for_norm] unfold let int_8 = int_t (Signed W8) [@@mark_for_norm] unfold let int_16 = int_t (Signed W16) [@@mark_for_norm] unfold let int_32 = int_t (Signed W32) [@@mark_for_norm] unfold let int_64 = int_t (Signed W64) [@@mark_for_norm] unfold let int_128 = int_t (Signed W128) [@@mark_for_norm] unfold let ok #sw (op:(int_t (Signed Winfinite) -> int_t (Signed Winfinite) -> int_t (Signed Winfinite))) (x:int_t sw) (y:int_t sw) = within_bounds sw (op (v x) (v y)) [@@mark_for_norm] unfold let nat = i:int{ i >= 0 } [@@mark_for_norm] unfold let pos = i:nat{ 0 < i } //////////////////////////////////////////////////////////////////////////////// //Test //////////////////////////////////////////////////////////////////////////////// let f_int (x:int) (y:int) = x + y let f_nat (x:nat) (y:nat) = x + y let f_nat_int_pos (x:nat) (y:int) (z:pos) = x + y + z let f_uint_8 (x:uint_8) (y:uint_8{ok (+) x y}) = x + y let f_int_16 (x:int_16) (y:int_16{ok (+) x y}) = x + y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.UInt16.fsti.checked", "FStar.UInt128.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Int8.fsti.checked", "FStar.Int64.fsti.checked", "FStar.Int32.fsti.checked", "FStar.Int16.fsti.checked", "FStar.Int128.fsti.checked", "FStar.Int.fsti.checked" ], "interface_file": false, "source_file": "FStar.Integers.fst" }
[ { "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": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.nat -> y: Prims.nat -> FStar.Integers.nat
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.Integers.op_Plus", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.u", "FStar.Integers.nat" ]
[]
false
false
false
true
false
let h (x y: Prims.nat) : nat =
u x + u y
false
Spec.Hash.Incremental.fst
Spec.Hash.Incremental.hash_is_hash_incremental'
val hash_is_hash_incremental' (a: hash_alg) (input: bytes { S.length input `less_than_max_input_length` a }) (l: output_length a): Lemma (S.equal (hash' a input l) (hash_incremental a input l))
val hash_is_hash_incremental' (a: hash_alg) (input: bytes { S.length input `less_than_max_input_length` a }) (l: output_length a): Lemma (S.equal (hash' a input l) (hash_incremental a input l))
let hash_is_hash_incremental' (a: hash_alg) (input: bytes { S.length input `less_than_max_input_length` a }) l = if is_blake a then Spec.Blake2.Incremental.blake2_is_hash_incremental a input else if is_keccak a then Spec.SHA3.Incremental.sha3_is_incremental a input l else Spec.MD.Incremental.md_is_hash_incremental a input (init a)
{ "file_name": "specs/lemmas/Spec.Hash.Incremental.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 27, "start_col": 0, "start_line": 21 }
module Spec.Hash.Incremental module S = FStar.Seq module Blake2 = Spec.Blake2 open Spec.Agile.Hash open Spec.Hash.Definitions friend Spec.Agile.Hash open FStar.Mul module Loops = Lib.LoopCombinators #set-options "--fuel 0 --ifuel 0 --z3rlimit 50" /// A declaration whose sole purpose is to force synchronize the .fst and the .fsti let _sync_decl = unit
{ "checked_file": "/", "dependencies": [ "Spec.SHA3.Incremental.fsti.checked", "Spec.MD.Incremental.fsti.checked", "Spec.Hash.Definitions.fst.checked", "Spec.Blake2.Incremental.fsti.checked", "Spec.Blake2.fst.checked", "Spec.Agile.Hash.fst.checked", "Spec.Agile.Hash.fst.checked", "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": true, "source_file": "Spec.Hash.Incremental.fst" }
[ { "abbrev": false, "full_module": "Spec.Hash.Incremental.Definitions", "short_module": null }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Blake2" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": true, "full_module": "Lib.UpdateMulti", "short_module": "UpdateMulti" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile.Hash", "short_module": null }, { "abbrev": true, "full_module": "Spec.Blake2", "short_module": "Blake2" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": false, "full_module": "Spec.Hash", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 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: Spec.Hash.Definitions.hash_alg -> input: Spec.Hash.Definitions.bytes {Spec.Hash.Definitions.less_than_max_input_length (FStar.Seq.Base.length input) a} -> l: Spec.Hash.Definitions.output_length a -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (Spec.Agile.Hash.hash' a input l) (Spec.Hash.Incremental.Definitions.hash_incremental a input l))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.Hash.Definitions.hash_alg", "Spec.Hash.Definitions.bytes", "Prims.b2t", "Spec.Hash.Definitions.less_than_max_input_length", "FStar.Seq.Base.length", "Lib.IntTypes.uint8", "Spec.Hash.Definitions.output_length", "Spec.Hash.Definitions.is_blake", "Spec.Blake2.Incremental.blake2_is_hash_incremental", "Prims.bool", "Spec.Hash.Definitions.is_keccak", "Spec.SHA3.Incremental.sha3_is_incremental", "Spec.MD.Incremental.md_is_hash_incremental", "Spec.Agile.Hash.init", "Prims.unit" ]
[]
false
false
true
false
false
let hash_is_hash_incremental' (a: hash_alg) (input: bytes{(S.length input) `less_than_max_input_length` a}) l =
if is_blake a then Spec.Blake2.Incremental.blake2_is_hash_incremental a input else if is_keccak a then Spec.SHA3.Incremental.sha3_is_incremental a input l else Spec.MD.Incremental.md_is_hash_incremental a input (init a)
false
Hacl.Impl.Curve25519.Field51.fst
Hacl.Impl.Curve25519.Field51.fmul2
val fmul2: C.(fmul2_t M51 True)
val fmul2: C.(fmul2_t M51 True)
let fmul2 out f1 f2 _ = let f10 = f1.(0ul) in let f11 = f1.(1ul) in let f12 = f1.(2ul) in let f13 = f1.(3ul) in let f14 = f1.(4ul) in let f20 = f2.(0ul) in let f21 = f2.(1ul) in let f22 = f2.(2ul) in let f23 = f2.(3ul) in let f24 = f2.(4ul) in let f30 = f1.(5ul) in let f31 = f1.(6ul) in let f32 = f1.(7ul) in let f33 = f1.(8ul) in let f34 = f1.(9ul) in let f40 = f2.(5ul) in let f41 = f2.(6ul) in let f42 = f2.(7ul) in let f43 = f2.(8ul) in let f44 = f2.(9ul) in let ((o10,o11,o12,o13,o14), (o20,o21,o22,o23,o24)) = fmul25 (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) (f30,f31,f32,f33,f34) (f40,f41,f42,f43,f44) in out.(0ul) <- o10; out.(1ul) <- o11; out.(2ul) <- o12; out.(3ul) <- o13; out.(4ul) <- o14; out.(5ul) <- o20; out.(6ul) <- o21; out.(7ul) <- o22; out.(8ul) <- o23; out.(9ul) <- o24
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field51.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 244, "start_col": 0, "start_line": 205 }
module Hacl.Impl.Curve25519.Field51 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer include Hacl.Spec.Curve25519.Field51 include Hacl.Spec.Curve25519.Field51.Definition module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field51.Definition module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module Lemmas = Hacl.Spec.Curve25519.Field51.Lemmas module C = Hacl.Impl.Curve25519.Fields.Core #reset-options "--z3rlimit 20" let felem = lbuffer uint64 5ul let felem2 = lbuffer uint64 10ul let felem_wide = lbuffer uint128 5ul noextract let as_nat = C.f51_as_nat noextract val wide_as_nat: h:mem -> e:felem_wide -> GTot nat let wide_as_nat h e = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in let s4 = s.[4] in S.wide_as_nat5 (s0, s1, s2, s3, s4) noextract val fevalh: h:mem -> f:felem -> GTot P.elem let fevalh h f = (as_nat h f) % P.prime noextract val feval_wideh: h:mem -> f:felem_wide -> GTot P.elem let feval_wideh h f = (wide_as_nat h f) % P.prime noextract let felem_fits = C.f51_felem_fits noextract val felem_wide_fits: h:mem -> f:felem_wide -> m:S.scale128_5 -> Type0 let felem_wide_fits h f m = let s = as_seq h f in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in let s4 = s.[4] in S.felem_wide_fits5 (s0, s1, s2, s3, s4) m noextract let as_felem = C.f51_as_felem noextract let mul_inv_t = C.f51_mul_inv_t inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (LSeq.create 5 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 5ul (u64 0) inline_for_extraction noextract val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero f = f.(0ul) <- u64 0; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0; f.(4ul) <- u64 0 inline_for_extraction noextract val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1) let set_one f = f.(0ul) <- u64 1; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0; f.(4ul) <- u64 0 inline_for_extraction noextract val copy_felem: f1:felem -> f2:felem -> Stack unit (requires fun h -> live h f1 /\ live h f2 /\ disjoint f1 f2) (ensures fun h0 _ h1 -> modifies (loc f1) h0 h1 /\ as_seq h1 f1 == as_seq h0 f2) let copy_felem f1 f2 = f1.(0ul) <- f2.(0ul); f1.(1ul) <- f2.(1ul); f1.(2ul) <- f2.(2ul); f1.(3ul) <- f2.(3ul); f1.(4ul) <- f2.(4ul); let h1 = ST.get () in LSeq.eq_intro (as_seq h1 f1) (as_seq h1 f2) #set-options "--max_fuel 0 --max_ifuel 0" val fadd: C.(fadd_t M51 True) [@ CInline] let fadd out f1 f2 = let h0 = ST.get () in let f10 = f1.(0ul) in let f20 = f2.(0ul) in let f11 = f1.(1ul) in let f21 = f2.(1ul) in let f12 = f1.(2ul) in let f22 = f2.(2ul) in let f13 = f1.(3ul) in let f23 = f2.(3ul) in let f14 = f1.(4ul) in let f24 = f2.(4ul) in out.(0ul) <- f10 +! f20; out.(1ul) <- f11 +! f21; out.(2ul) <- f12 +! f22; out.(3ul) <- f13 +! f23; out.(4ul) <- f14 +! f24; let h1 = ST.get () in assert (as_nat h1 out == as_nat h0 f1 + as_nat h0 f2); FStar.Math.Lemmas.lemma_mod_plus_distr_l (as_nat h0 f1) (as_nat h0 f2) P.prime; FStar.Math.Lemmas.lemma_mod_plus_distr_r (as_nat h0 f1 % P.prime) (as_nat h0 f2) P.prime val fsub: C.(fsub_t M51 True) [@ CInline] let fsub out f1 f2 = let f10 = f1.(0ul) in let f20 = f2.(0ul) in let f11 = f1.(1ul) in let f21 = f2.(1ul) in let f12 = f1.(2ul) in let f22 = f2.(2ul) in let f13 = f1.(3ul) in let f23 = f2.(3ul) in let f14 = f1.(4ul) in let f24 = f2.(4ul) in out.(0ul) <- f10 +! u64 0x3fffffffffff68 -! f20; out.(1ul) <- f11 +! u64 0x3ffffffffffff8 -! f21; out.(2ul) <- f12 +! u64 0x3ffffffffffff8 -! f22; out.(3ul) <- f13 +! u64 0x3ffffffffffff8 -! f23; out.(4ul) <- f14 +! u64 0x3ffffffffffff8 -! f24; lemma_fsub (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) val fmul: C.(fmul_t M51 True) [@ CInline] let fmul out f1 f2 _ = let f10 = f1.(0ul) in let f11 = f1.(1ul) in let f12 = f1.(2ul) in let f13 = f1.(3ul) in let f14 = f1.(4ul) in let f20 = f2.(0ul) in let f21 = f2.(1ul) in let f22 = f2.(2ul) in let f23 = f2.(3ul) in let f24 = f2.(4ul) in let (o0,o1,o2,o3,o4) = fmul5 (f10,f11,f12,f13,f14) (f20,f21,f22,f23,f24) in out.(0ul) <- o0; out.(1ul) <- o1; out.(2ul) <- o2; out.(3ul) <- o3; out.(4ul) <- o4 val fmul2: C.(fmul2_t M51 True) #set-options "--z3rlimit 100"
{ "checked_file": "/", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field51.Lemmas.fst.checked", "Hacl.Spec.Curve25519.Field51.Definition.fst.checked", "Hacl.Spec.Curve25519.Field51.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.Math.Lemmas.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field51.fst" }
[ { "abbrev": true, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": "C" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Lemmas", "short_module": "Lemmas" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51.Definition", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Curve25519.Field51", "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": "Lib.Sequence", "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.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Curve25519.Fields.Core.fmul2_t Hacl.Impl.Curve25519.Fields.Core.M51 Prims.l_True
Prims.Tot
[ "total" ]
[]
[ "Hacl.Impl.Curve25519.Fields.Core.felem2", "Hacl.Impl.Curve25519.Fields.Core.M51", "Hacl.Impl.Curve25519.Fields.Core.felem_wide2", "Lib.IntTypes.uint64", "Lib.Buffer.op_Array_Assignment", "Hacl.Impl.Curve25519.Fields.Core.limb", "Lib.IntTypes.op_Plus_Dot", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Impl.Curve25519.Fields.Core.nlimb", "FStar.UInt32.__uint_to_t", "Prims.unit", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Curve25519.Field51.Definition.felem5", "Hacl.Spec.Curve25519.Field51.fmul25", "FStar.Pervasives.Native.Mktuple5", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT" ]
[]
false
false
false
true
false
let fmul2 out f1 f2 _ =
let f10 = f1.(0ul) in let f11 = f1.(1ul) in let f12 = f1.(2ul) in let f13 = f1.(3ul) in let f14 = f1.(4ul) in let f20 = f2.(0ul) in let f21 = f2.(1ul) in let f22 = f2.(2ul) in let f23 = f2.(3ul) in let f24 = f2.(4ul) in let f30 = f1.(5ul) in let f31 = f1.(6ul) in let f32 = f1.(7ul) in let f33 = f1.(8ul) in let f34 = f1.(9ul) in let f40 = f2.(5ul) in let f41 = f2.(6ul) in let f42 = f2.(7ul) in let f43 = f2.(8ul) in let f44 = f2.(9ul) in let (o10, o11, o12, o13, o14), (o20, o21, o22, o23, o24) = fmul25 (f10, f11, f12, f13, f14) (f20, f21, f22, f23, f24) (f30, f31, f32, f33, f34) (f40, f41, f42, f43, f44) in out.(0ul) <- o10; out.(1ul) <- o11; out.(2ul) <- o12; out.(3ul) <- o13; out.(4ul) <- o14; out.(5ul) <- o20; out.(6ul) <- o21; out.(7ul) <- o22; out.(8ul) <- o23; out.(9ul) <- o24
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'
val bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
val bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload)
let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 94, "start_col": 0, "start_line": 83 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> x: LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitSum' key key_size e payload) -> LowParse.Spec.BitSum.bitsum'_type_bitsum' cl bitsum'_size key key_size e payload
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.BitSum'", "LowParse.Spec.BitSum.bitsum'_type_bitsum'" ]
[]
false
false
false
false
false
let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_recip
val synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b))
val synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b))
let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 26, "end_line": 497, "start_col": 0, "start_line": 488 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b -> LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.synth_bitsum'_recip'", "Prims.unit", "LowParse.Spec.BitSum.synth_bitsum'_recip'_prop", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'" ]
[]
false
false
false
false
false
let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) =
synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_recip_inverse
val synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
val synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))
let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x )
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 552, "start_col": 0, "start_line": 541 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_inverse (LowParse.Spec.BitSum.synth_bitsum' b) (LowParse.Spec.BitSum.synth_bitsum'_recip b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Combinators.synth_inverse_intro'", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Spec.BitSum.synth_bitsum'_recip", "LowParse.Spec.BitSum.synth_bitsum'_recip_inverse'", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_inverse", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) =
synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_type_intro_BitSum'
val bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload))
val bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload))
let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 109, "start_col": 0, "start_line": 98 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> x: LowParse.Spec.BitSum.bitsum'_type_bitsum' cl bitsum'_size key key_size e payload -> LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitSum' key key_size e payload)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_type_bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.BitSum'" ]
[]
false
false
false
false
false
let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_type_intro_BitField
val bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest))
val bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest))
let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 135, "start_col": 0, "start_line": 126 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} -> rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) -> x: LowParse.Spec.BitSum.bitsum'_type_bitfield bitsum'_size sz rest -> LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitField sz rest)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_type_bitfield", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.BitField" ]
[]
false
false
false
false
false
let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_key_type
val bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size))
val bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size))
let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key))
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 54, "end_line": 150, "start_col": 0, "start_line": 138 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> Prims.Tot Prims.eqtype
Prims.Tot
[ "total", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.unit", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "Prims.dtuple2" ]
[ "recursion" ]
false
false
false
false
false
let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) =
match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key))
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_key_type_elim_BitSum'
val bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k'))
val bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k'))
let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 165, "start_col": 0, "start_line": 154 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> x: LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitSum' key key_size e payload) -> Prims.dtuple2 (LowParse.Spec.Enum.enum_key e) (fun k' -> LowParse.Spec.BitSum.bitsum'_key_type (payload k'))
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'", "Prims.dtuple2" ]
[]
false
false
false
false
false
let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.coerce
val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True))
val coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True))
let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2)
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 11, "end_line": 192, "start_col": 0, "start_line": 185 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
t2: Type -> x: t1 -> Prims.Pure t2
Prims.Pure
[]
[]
[ "Prims.eq2", "Prims.l_True" ]
[]
false
false
false
false
false
let coerce (t2 #t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) =
(x <: t2)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_key_type_intro_BitField
val bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest))
val bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest))
let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 48, "end_line": 205, "start_col": 0, "start_line": 196 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} -> rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) -> x: LowParse.Spec.BitSum.bitsum'_key_type rest -> LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitField sz rest)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.coerce", "LowParse.Spec.BitSum.BitField" ]
[]
false
false
false
false
false
let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) =
coerce (bitsum'_key_type (BitField sz rest)) x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'
val synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size))
val synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size))
let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 71, "end_line": 259, "start_col": 0, "start_line": 241 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) -> Prims.Tot (LowParse.Spec.BitSum.bitsum'_type b)
Prims.Tot
[ "total", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_type_intro_BitField", "FStar.Pervasives.Native.Mktuple2", "LowParse.BitFields.bitfield", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'_type_intro_BitSum'", "Prims.dtuple2", "Prims.Mkdtuple2", "LowParse.Spec.Enum.enum_key_of_repr" ]
[ "recursion" ]
false
false
false
false
false
let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) =
match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k:enum_key e = enum_key_of_repr e f in let z:bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p:(k': enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.filter_bitsum'
val filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size))
val filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size))
let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 11, "end_line": 239, "start_col": 0, "start_line": 220 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: t -> Prims.Tot Prims.bool
Prims.Tot
[ "total", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.snd", "LowParse.Spec.Enum.enum_key_of_repr", "Prims.bool", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield" ]
[ "recursion" ]
false
false
false
false
false
let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) =
match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum'
val bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload))
val bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload))
let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 180, "start_col": 0, "start_line": 169 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> key: Prims.eqtype -> key_size: Prims.nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot} -> e: LowParse.Spec.Enum.enum key (LowParse.BitFields.bitfield cl key_size) -> payload: (_: LowParse.Spec.Enum.enum_key e -> LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - key_size) ) -> x: Prims.dtuple2 (LowParse.Spec.Enum.enum_key e) (fun k' -> LowParse.Spec.BitSum.bitsum'_key_type (payload k')) -> LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitSum' key key_size e payload)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "Prims.dtuple2", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitSum'" ]
[]
false
false
false
false
false
let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat{key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot}) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_key_type_elim_BitField
val bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest)
val bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest)
let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 34, "end_line": 218, "start_col": 0, "start_line": 209 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} -> rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) -> x: LowParse.Spec.BitSum.bitsum'_key_type (LowParse.Spec.BitSum.BitField sz rest) -> LowParse.Spec.BitSum.bitsum'_key_type rest
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.BitField", "LowParse.Spec.BitSum.coerce" ]
[]
false
false
false
false
false
let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) =
coerce (bitsum'_key_type rest) x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_type_elim_BitField
val bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest)
val bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest)
let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 122, "start_col": 0, "start_line": 113 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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
cl: LowParse.BitFields.uint_t tot t -> bitsum'_size: Prims.nat -> sz: Prims.nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot} -> rest: LowParse.Spec.BitSum.bitsum' cl (bitsum'_size - sz) -> x: LowParse.Spec.BitSum.bitsum'_type (LowParse.Spec.BitSum.BitField sz rest) -> LowParse.Spec.BitSum.bitsum'_type_bitfield bitsum'_size sz rest
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "LowParse.Spec.BitSum.bitsum'", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.BitField", "LowParse.Spec.BitSum.bitsum'_type_bitfield" ]
[]
false
false
false
false
false
let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat{sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot}) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_recip'
val synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size))
val synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size))
let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 392, "start_col": 0, "start_line": 374 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b -> Prims.Tot t
Prims.Tot
[ "total", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "Prims.squash", "Prims.eq2", "Prims.int", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.BitFields.bitfield", "LowParse.BitFields.__proj__Mkuint_t__item__set_bitfield", "LowParse.Spec.BitSum.synth_bitsum'_recip'", "LowParse.Spec.BitSum.bitsum'_type_bitfield", "LowParse.Spec.BitSum.bitsum'_type_elim_BitField", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "FStar.UInt.uint_t", "LowParse.BitFields.__proj__Mkuint_t__item__v", "LowParse.BitFields.set_bitfield", "LowParse.Spec.Enum.enum_repr_of_key", "LowParse.Spec.BitSum.bitsum'_type_bitsum'", "LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'" ]
[ "recursion" ]
false
false
false
false
false
let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) =
match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.parse_bitsum'
val parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b))
val parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b))
let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 67, "end_line": 372, "start_col": 0, "start_line": 363 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl tot -> p: LowParse.Spec.Base.parser k t -> LowParse.Spec.Base.parser (LowParse.Spec.Combinators.parse_filter_kind k) (LowParse.Spec.BitSum.bitsum'_type b)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BitSum.synth_bitsum'", "Prims.unit", "LowParse.Spec.BitSum.synth_bitsum'_injective" ]
[]
false
false
false
false
false
let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) =
synth_bitsum'_injective b; (p `parse_filter` (filter_bitsum' b)) `parse_synth` (synth_bitsum' b)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.id
val id (#t: Type) (x: t) : Tot t
val id (#t: Type) (x: t) : Tot t
let id (#t: Type) (x: t) : Tot t = x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 621, "start_col": 0, "start_line": 617 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: t -> t
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let id (#t: Type) (x: t) : Tot t =
x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.get_bitfield_synth_bitsum'_recip'_other
val get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot}) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size))
val get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot}) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size))
let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 64, "end_line": 418, "start_col": 0, "start_line": 396 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b -> lo: Prims.nat -> hi: Prims.nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot} -> FStar.Pervasives.Lemma (ensures Mkuint_t?.v cl (Mkuint_t?.get_bitfield cl (LowParse.Spec.BitSum.synth_bitsum'_recip' b x) lo hi) == 0) (decreases bitsum'_size)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.squash", "Prims.eq2", "Prims.int", "LowParse.BitFields.get_bitfield_zero", "Prims.op_GreaterThan", "Prims.op_Subtraction", "LowParse.BitFields.bitfield", "LowParse.Spec.BitSum.get_bitfield_synth_bitsum'_recip'_other", "Prims.unit", "LowParse.BitFields.get_bitfield_set_bitfield_other", "LowParse.BitFields.__proj__Mkuint_t__item__v", "LowParse.Spec.BitSum.synth_bitsum'_recip'", "LowParse.Spec.BitSum.bitsum'_type_bitfield", "LowParse.Spec.BitSum.bitsum'_type_elim_BitField", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.enum_repr_of_key", "LowParse.Spec.BitSum.bitsum'_type_bitsum'", "LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'", "Prims.l_True", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat{bitsum'_size <= lo /\ lo <= hi /\ hi <= tot}) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) =
match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_ext
val synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size) ) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size))
val synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size) ) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size))
let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v)
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 19, "end_line": 359, "start_col": 0, "start_line": 319 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) -> y: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) -> FStar.Pervasives.Lemma (requires LowParse.BitFields.get_bitfield (Mkuint_t?.v cl x) 0 bitsum'_size == LowParse.BitFields.get_bitfield (Mkuint_t?.v cl y) 0 bitsum'_size) (ensures LowParse.Spec.BitSum.synth_bitsum' b x == LowParse.Spec.BitSum.synth_bitsum' b y) (decreases bitsum'_size)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Spec.BitSum.synth_bitsum'_ext", "Prims.unit", "LowParse.BitFields.get_bitfield_get_bitfield", "LowParse.BitFields.__proj__Mkuint_t__item__v", "Prims._assert", "LowParse.BitFields.bitfield", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.BitFields.ubitfield", "LowParse.BitFields.get_bitfield", "LowParse.Spec.BitSum.BitSum'", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Spec.BitSum.bitsum'_type_intro_BitSum'", "Prims.Mkdtuple2", "LowParse.Spec.Enum.enum_key_of_repr", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size) ) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) =
match b with | BitStop _ -> () | BitField sz rest -> let f:bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g:bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g:bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_injective
val synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b))
val synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b))
let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) )
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 313, "start_col": 0, "start_line": 300 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl tot -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Combinators.synth_injective (LowParse.Spec.BitSum.synth_bitsum' b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Combinators.synth_injective_intro'", "Prims.l_and", "Prims.eq2", "Prims.bool", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.synth_bitsum'", "Prims._assert", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "LowParse.BitFields.__proj__Mkuint_t__item__v", "Prims.unit", "LowParse.BitFields.get_bitfield_full", "LowParse.Spec.BitSum.synth_bitsum'_injective'", "Prims.l_True", "Prims.squash", "LowParse.Spec.Combinators.synth_injective", "LowParse.Spec.Combinators.parse_filter_refine", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) =
synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)))
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.filter_bitsum'_ext
val filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size) ) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size))
val filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size) ) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size))
let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else ()
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 15, "end_line": 457, "start_col": 0, "start_line": 424 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: t -> y: t -> FStar.Pervasives.Lemma (requires LowParse.BitFields.get_bitfield (Mkuint_t?.v cl x) 0 bitsum'_size == LowParse.BitFields.get_bitfield (Mkuint_t?.v cl y) 0 bitsum'_size) (ensures LowParse.Spec.BitSum.filter_bitsum' b x == LowParse.Spec.BitSum.filter_bitsum' b y) (decreases bitsum'_size)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Spec.BitSum.filter_bitsum'_ext", "Prims.unit", "LowParse.BitFields.get_bitfield_get_bitfield", "LowParse.BitFields.__proj__Mkuint_t__item__v", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.list_mem", "LowParse.Spec.Enum.list_map", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.snd", "LowParse.Spec.Enum.enum_key_of_repr", "Prims.bool", "Prims._assert", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "FStar.UInt.uint_t", "LowParse.BitFields.get_bitfield", "LowParse.BitFields.ubitfield", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size) ) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) =
match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g:bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.serialize_bitsum'_eq
val serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
val serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x))
let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 591, "start_col": 0, "start_line": 572 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl tot -> s: LowParse.Spec.Base.serializer p -> x: LowParse.Spec.BitSum.bitsum'_type b -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.serialize (LowParse.Spec.BitSum.serialize_bitsum' b s) x == LowParse.Spec.Base.serialize s (LowParse.Spec.BitSum.synth_bitsum'_recip b x))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.BitSum.synth_bitsum'_recip", "Prims.unit", "LowParse.Spec.BitSum.synth_bitsum'_recip_inverse", "LowParse.Spec.BitSum.synth_bitsum'_injective", "Prims.l_True", "Prims.squash", "Prims.eq2", "LowParse.Bytes.bytes", "LowParse.Spec.Base.serialize", "LowParse.Spec.BitSum.parse_bitsum'", "LowParse.Spec.BitSum.serialize_bitsum'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) =
synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` (filter_bitsum' b)) (synth_bitsum' b) (s `serialize_filter` (filter_bitsum' b)) (synth_bitsum'_recip b) () x
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.serialize_bitsum'
val serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p))
val serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p))
let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) ()
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 570, "start_col": 0, "start_line": 554 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl tot -> s: LowParse.Spec.Base.serializer p -> LowParse.Spec.Base.serializer (LowParse.Spec.BitSum.parse_bitsum' b p)
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.Spec.Combinators.serialize_synth", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Spec.Combinators.serialize_filter", "LowParse.Spec.BitSum.synth_bitsum'_recip", "Prims.unit", "LowParse.Spec.BitSum.synth_bitsum'_recip_inverse", "LowParse.Spec.BitSum.synth_bitsum'_injective", "LowParse.Spec.BitSum.parse_bitsum'" ]
[]
false
false
false
false
false
let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) =
synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` (filter_bitsum' b)) (synth_bitsum' b) (s `serialize_filter` (filter_bitsum' b)) (synth_bitsum'_recip b) ()
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.destr_bitsum'_bitstop
val destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
val destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ()))
let destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ())) = fun u u_if f x -> f ()
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 6, "end_line": 1302, "start_col": 0, "start_line": 1296 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction noextract let id (#t: Type) (x: t) : Tot t = x inline_for_extraction noextract noeq type synth_case_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) : Type = | SynthCase: (f: ( (k' : bitsum'_type b) -> type_of_tag (bitsum'_key_of_t b k') -> Tot (refine_with_tag (tag_of_data) k') )) -> (f_inj: ( (k' : bitsum'_type b) -> (pl1: type_of_tag (bitsum'_key_of_t b k')) -> (pl2: type_of_tag (bitsum'_key_of_t b k')) -> Lemma (requires (f k' pl1 == f k' pl2)) (ensures (pl1 == pl2)) )) -> (g: ( (k' : bitsum'_type b) -> refine_with_tag (tag_of_data) k' -> Tot (type_of_tag (bitsum'_key_of_t b k')) )) -> (f_g_eq: ( (k: bitsum'_type b) -> (x: refine_with_tag (tag_of_data) k) -> Lemma (f k (g k x) == x) )) -> synth_case_t b data tag_of_data type_of_tag let synth_case_g_f_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#b: bitsum' cl tot) (#data: Type) (#tag_of_data: (data -> Tot (bitsum'_type b))) (#type_of_tag: (bitsum'_key_type b -> Tot Type)) (s: synth_case_t b data tag_of_data type_of_tag) (k: bitsum'_type b) (x: type_of_tag (bitsum'_key_of_t b k)) : Lemma (s.g k (s.f k x) == x) = s.f_g_eq k (s.f k x); s.f_inj k (s.g k (s.f k x)) x #push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3" let rec weaken_parse_bitsum_cases_kind' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (f: (x: bitsum'_key_type b) -> Tot parser_kind) : Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) (decreases (bitsum'_size)) = match b with | BitStop _ -> (| f (), (fun y -> ()) |) | BitField sz rest -> let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in (| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |) | BitSum' key key_size e payload -> let keys : list key = List.Tot.map fst e in let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma (requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x)) (ensures (k `is_weaker_than` f y)))) = if List.Tot.mem x keys then let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in assert (y1 == x); g y2 ) |) else (| default_parser_kind, (fun y -> ()) |) in let k = glb_list_of #key (fun x -> dfst (phi x)) keys in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in dsnd (phi y1) y ) |) let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) }) = let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k let synth_bitsum_case_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] = synth_injective_intro' (synth_case.f x) (fun y z -> synth_case.f_inj x y z ) let parse_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bitsum'_type b) : Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) = let tg : bitsum'_key_type b = bitsum'_key_of_t b x in let (| k_, p |) = f tg in weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x) inline_for_extraction let parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f) let parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) = parse_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f) module Seq = FStar.Seq #push-options "--z3rlimit 16" let parse_bitsum_eq (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bytes) : Lemma (parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with | None -> None | Some (tg, consumed1) -> let k = bitsum'_key_of_t b tg in begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with | None -> None | Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2) end )) = parse_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f) x; match parse (parse_bitsum' b p) x with | None -> () | Some (tg, consumed1) -> let k = bitsum'_key_of_t b tg in synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg; parse_synth_eq (dsnd (f k)) (synth_case.f tg) (Seq.slice x consumed1 (Seq.length x)) #pop-options let parse_bitsum_eq' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bytes) : Lemma (parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with | None -> None | Some (tg', consumed1) -> if filter_bitsum' b tg' then let tg = synth_bitsum' b tg' in let k = bitsum'_key_of_t b tg in begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with | None -> None | Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2) end else None )) = parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x; synth_bitsum'_injective b; parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x; parse_filter_eq p (filter_bitsum' b) x let synth_bitsum_case_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_inverse (synth_case.f x) (synth_case.g x)) [SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY? = synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y -> synth_case.f_g_eq x y ) let serialize_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: bitsum'_type b) : Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x)) = let tg = bitsum'_key_of_t b x in let (| _, p |) = f tg in synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger? synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger? serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (serialize_synth p (synth_case.f x) (g tg) (synth_case.g x) ()) let serialize_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) : Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = serialize_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p) (serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) #(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) (serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) let serialize_bitsum_alt (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : GTot bytes = let tg = tag_of_data x in let k = bitsum'_key_of_t b tg in let payload = synth_case.g tg x in serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload let serialize_bitsum_eq (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : Lemma (serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) = serialize_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p) (serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) #(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) (serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) x; let tg = tag_of_data x in let k = bitsum'_key_of_t b tg in serialize_bitsum'_eq b s tg; let (| _, p |) = f k in serialize_synth_eq #_ #(type_of_tag k) p (synth_case.f tg) (g k) (synth_case.g tg) () x let serialize_bitsum_eq' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : Lemma (serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x) = serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x let serialize_bitsum_alt_2 (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (tg: bitsum'_type b) (payload: type_of_tag (bitsum'_key_of_t b tg)) : GTot bytes = let k = bitsum'_key_of_t b tg in serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload let serialize_bitsum_eq_2 (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (tg: bitsum'_type b) (payload: type_of_tag (bitsum'_key_of_t b tg)) : Lemma (serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload) = serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload); synth_case_g_f_eq synth_case tg payload (* Implementation of filter_bitsum' *) inline_for_extraction noextract let filter_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = (x: t) -> Tot (y: bool { y == filter_bitsum' b x }) inline_for_extraction let filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) = fun _ -> true inline_for_extraction let filter_bitsum'_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: filter_bitsum'_t rest) : Tot (filter_bitsum'_t (BitField sz rest)) = fun x -> phi x inline_for_extraction let filter_bitsum'_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) }))) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k))) : Tot (filter_bitsum'_t (BitSum' key key_size e payload)) = fun x -> let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if not (is_valid_repr r) then false else destr_payload (key_of r) x inline_for_extraction noextract let filter_bitsum'_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot Type = (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x }) inline_for_extraction let filter_bitsum'_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e) : Tot (filter_bitsum'_t (BitSum' key key_size e payload)) = fun x -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi x xr inline_for_extraction let filter_bitsum'_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e []) = (fun x xr -> false) inline_for_extraction let filter_bitsum'_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: filter_bitsum'_t (payload k)) (destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun x xr -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload x else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail (x <: t) xr let bitsum_wellfoundedness (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b:bitsum' cl bitsum'_size { BitSum'? b }) : Lemma (let BitSum' key key_size e payload = b in (forall (k:enum_key e). payload k << b)) = () [@filter_bitsum'_t_attr] noextract let rec mk_filter_bitsum'_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (filter_bitsum'_t b) (decreases %[b; 1; ()]) = match b with | BitStop _ -> filter_bitsum'_bitstop cl | BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest) | BitSum' key key_size e payload -> filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e) and mk_filter_bitsum'_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; 0; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_filter_bitsum'_t' (payload k)) (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q) (* Universal destructor *) inline_for_extraction let if_combinator_weak (t: Type) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t) inline_for_extraction noextract let destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(a + 1)) = (u: (bitsum'_type b -> Tot (Type u#a))) -> (u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) -> (f: ((k: bitsum'_type b) -> Tot (u k))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (u (synth_bitsum' b x))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 3, "max_fuel": 8, "max_ifuel": 3, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cl: LowParse.BitFields.uint_t tot t -> LowParse.Spec.BitSum.destr_bitsum'_t (LowParse.Spec.BitSum.BitStop ())
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.BitStop", "FStar.Ghost.erased", "LowParse.Spec.BitSum.if_combinator_weak", "FStar.Ghost.reveal", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.synth_bitsum'", "LowParse.Spec.BitSum.destr_bitsum'_t" ]
[]
false
false
false
false
false
let destr_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (destr_bitsum'_t #tot #t #cl #0 (BitStop ())) =
fun u u_if f x -> f ()
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_recip_inverse'
val synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size)
val synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size)
let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 47, "end_line": 537, "start_col": 0, "start_line": 501 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b -> FStar.Pervasives.Lemma (ensures LowParse.Spec.BitSum.synth_bitsum' b (LowParse.Spec.BitSum.synth_bitsum'_recip b x) == x) (decreases bitsum'_size)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.BitFields.bitfield", "LowParse.Spec.BitSum.synth_bitsum'_recip_inverse'", "Prims.unit", "LowParse.Spec.BitSum.synth_bitsum'_ext", "LowParse.Spec.BitSum.filter_bitsum'_ext", "LowParse.BitFields.get_bitfield_set_bitfield_other", "LowParse.BitFields.__proj__Mkuint_t__item__v", "Prims._assert", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.BitFields.get_bitfield_set_bitfield_same", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.synth_bitsum'_recip", "LowParse.Spec.BitSum.bitsum'_type_bitfield", "LowParse.Spec.BitSum.bitsum'_type_elim_BitField", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.enum_repr_of_key", "LowParse.Spec.Enum.enum_key_of_repr_of_key", "LowParse.Spec.BitSum.bitsum'_type_bitsum'", "LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'", "Prims.l_True", "LowParse.Spec.BitSum.synth_bitsum'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) =
match b with | BitStop _ -> () | BitField sz rest -> let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1; synth_bitsum'_recip_inverse' (payload k) tl
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_recip'_prop
val synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size))
val synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size))
let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 44, "end_line": 485, "start_col": 0, "start_line": 461 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b -> FStar.Pervasives.Lemma (ensures LowParse.Spec.BitSum.filter_bitsum' b (LowParse.Spec.BitSum.synth_bitsum'_recip' b x) == true) (decreases bitsum'_size)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.BitFields.bitfield", "LowParse.Spec.BitSum.synth_bitsum'_recip'_prop", "Prims.unit", "LowParse.Spec.BitSum.filter_bitsum'_ext", "LowParse.Spec.BitSum.synth_bitsum'_recip'", "LowParse.BitFields.get_bitfield_set_bitfield_other", "LowParse.BitFields.__proj__Mkuint_t__item__v", "LowParse.Spec.BitSum.bitsum'_type_bitfield", "LowParse.Spec.BitSum.bitsum'_type_elim_BitField", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.enum_key_of_repr_of_key", "Prims._assert", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "LowParse.Spec.Enum.enum_repr_of_key", "LowParse.BitFields.get_bitfield_set_bitfield_same", "LowParse.Spec.BitSum.bitsum'_type_bitsum'", "LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'", "Prims.l_True", "Prims.bool", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) =
match b with | BitStop _ -> () | BitField sz rest -> let hd, tl = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k , tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.synth_bitsum'_injective'
val synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size))
val synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size))
let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 125, "end_line": 296, "start_col": 0, "start_line": 265 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) -> y: LowParse.Spec.Combinators.parse_filter_refine (LowParse.Spec.BitSum.filter_bitsum' b) -> FStar.Pervasives.Lemma (requires LowParse.Spec.BitSum.synth_bitsum' b x == LowParse.Spec.BitSum.synth_bitsum' b y) (ensures Mkuint_t?.get_bitfield cl x 0 bitsum'_size == Mkuint_t?.get_bitfield cl y 0 bitsum'_size) (decreases bitsum'_size)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "Prims.squash", "Prims.eq2", "Prims.int", "Prims._assert", "LowParse.BitFields.__proj__Mkuint_t__item__uint_to_t", "LowParse.BitFields.__proj__Mkuint_t__item__v", "LowParse.BitFields.__proj__Mkuint_t__item__get_bitfield", "Prims.unit", "LowParse.BitFields.get_bitfield_empty", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.BitFields.get_bitfield_partition", "Prims.Cons", "Prims.Nil", "FStar.UInt.uint_t", "LowParse.Spec.BitSum.synth_bitsum'_injective'", "LowParse.Spec.Enum.enum", "LowParse.BitFields.bitfield", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.enum_repr_of_key_of_repr", "LowParse.Spec.Enum.enum_key_of_repr", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.synth_bitsum'", "Prims.l_or", "LowParse.BitFields.get_bitfield", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) =
match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f:bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g:bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size)))
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.destr_bitsum'_t
val destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(a + 1))
val destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(a + 1))
let destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(a + 1)) = (u: (bitsum'_type b -> Tot (Type u#a))) -> (u_if: ((k: Ghost.erased (bitsum'_type b)) -> Tot (if_combinator_weak (u (Ghost.reveal k))))) -> (f: ((k: bitsum'_type b) -> Tot (u k))) -> (x: parse_filter_refine (filter_bitsum' b)) -> Tot (u (synth_bitsum' b x))
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 1293, "start_col": 0, "start_line": 1282 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction noextract let id (#t: Type) (x: t) : Tot t = x inline_for_extraction noextract noeq type synth_case_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) : Type = | SynthCase: (f: ( (k' : bitsum'_type b) -> type_of_tag (bitsum'_key_of_t b k') -> Tot (refine_with_tag (tag_of_data) k') )) -> (f_inj: ( (k' : bitsum'_type b) -> (pl1: type_of_tag (bitsum'_key_of_t b k')) -> (pl2: type_of_tag (bitsum'_key_of_t b k')) -> Lemma (requires (f k' pl1 == f k' pl2)) (ensures (pl1 == pl2)) )) -> (g: ( (k' : bitsum'_type b) -> refine_with_tag (tag_of_data) k' -> Tot (type_of_tag (bitsum'_key_of_t b k')) )) -> (f_g_eq: ( (k: bitsum'_type b) -> (x: refine_with_tag (tag_of_data) k) -> Lemma (f k (g k x) == x) )) -> synth_case_t b data tag_of_data type_of_tag let synth_case_g_f_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#b: bitsum' cl tot) (#data: Type) (#tag_of_data: (data -> Tot (bitsum'_type b))) (#type_of_tag: (bitsum'_key_type b -> Tot Type)) (s: synth_case_t b data tag_of_data type_of_tag) (k: bitsum'_type b) (x: type_of_tag (bitsum'_key_of_t b k)) : Lemma (s.g k (s.f k x) == x) = s.f_g_eq k (s.f k x); s.f_inj k (s.g k (s.f k x)) x #push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3" let rec weaken_parse_bitsum_cases_kind' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (f: (x: bitsum'_key_type b) -> Tot parser_kind) : Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) (decreases (bitsum'_size)) = match b with | BitStop _ -> (| f (), (fun y -> ()) |) | BitField sz rest -> let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in (| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |) | BitSum' key key_size e payload -> let keys : list key = List.Tot.map fst e in let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma (requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x)) (ensures (k `is_weaker_than` f y)))) = if List.Tot.mem x keys then let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in assert (y1 == x); g y2 ) |) else (| default_parser_kind, (fun y -> ()) |) in let k = glb_list_of #key (fun x -> dfst (phi x)) keys in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in dsnd (phi y1) y ) |) let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) }) = let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k let synth_bitsum_case_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] = synth_injective_intro' (synth_case.f x) (fun y z -> synth_case.f_inj x y z ) let parse_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bitsum'_type b) : Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) = let tg : bitsum'_key_type b = bitsum'_key_of_t b x in let (| k_, p |) = f tg in weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x) inline_for_extraction let parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f) let parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) = parse_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f) module Seq = FStar.Seq #push-options "--z3rlimit 16" let parse_bitsum_eq (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bytes) : Lemma (parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with | None -> None | Some (tg, consumed1) -> let k = bitsum'_key_of_t b tg in begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with | None -> None | Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2) end )) = parse_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f) x; match parse (parse_bitsum' b p) x with | None -> () | Some (tg, consumed1) -> let k = bitsum'_key_of_t b tg in synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg; parse_synth_eq (dsnd (f k)) (synth_case.f tg) (Seq.slice x consumed1 (Seq.length x)) #pop-options let parse_bitsum_eq' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bytes) : Lemma (parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with | None -> None | Some (tg', consumed1) -> if filter_bitsum' b tg' then let tg = synth_bitsum' b tg' in let k = bitsum'_key_of_t b tg in begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with | None -> None | Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2) end else None )) = parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x; synth_bitsum'_injective b; parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x; parse_filter_eq p (filter_bitsum' b) x let synth_bitsum_case_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_inverse (synth_case.f x) (synth_case.g x)) [SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY? = synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y -> synth_case.f_g_eq x y ) let serialize_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: bitsum'_type b) : Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x)) = let tg = bitsum'_key_of_t b x in let (| _, p |) = f tg in synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger? synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger? serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (serialize_synth p (synth_case.f x) (g tg) (synth_case.g x) ()) let serialize_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) : Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = serialize_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p) (serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) #(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) (serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) let serialize_bitsum_alt (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : GTot bytes = let tg = tag_of_data x in let k = bitsum'_key_of_t b tg in let payload = synth_case.g tg x in serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload let serialize_bitsum_eq (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : Lemma (serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) = serialize_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p) (serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) #(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) (serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) x; let tg = tag_of_data x in let k = bitsum'_key_of_t b tg in serialize_bitsum'_eq b s tg; let (| _, p |) = f k in serialize_synth_eq #_ #(type_of_tag k) p (synth_case.f tg) (g k) (synth_case.g tg) () x let serialize_bitsum_eq' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : Lemma (serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x) = serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x let serialize_bitsum_alt_2 (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (tg: bitsum'_type b) (payload: type_of_tag (bitsum'_key_of_t b tg)) : GTot bytes = let k = bitsum'_key_of_t b tg in serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload let serialize_bitsum_eq_2 (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (tg: bitsum'_type b) (payload: type_of_tag (bitsum'_key_of_t b tg)) : Lemma (serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload) = serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload); synth_case_g_f_eq synth_case tg payload (* Implementation of filter_bitsum' *) inline_for_extraction noextract let filter_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = (x: t) -> Tot (y: bool { y == filter_bitsum' b x }) inline_for_extraction let filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) = fun _ -> true inline_for_extraction let filter_bitsum'_bitfield (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (phi: filter_bitsum'_t rest) : Tot (filter_bitsum'_t (BitField sz rest)) = fun x -> phi x inline_for_extraction let filter_bitsum'_bitsum_gen (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (is_valid_repr: ((x: bitfield cl key_size) -> Tot (y: bool { y == list_mem x (list_map snd e) }))) (key_of: ((x: enum_repr e) -> Tot (y: enum_key e { y == enum_key_of_repr e x }))) (destr_payload: ((k: enum_key e) -> filter_bitsum'_t (payload k))) : Tot (filter_bitsum'_t (BitSum' key key_size e payload)) = fun x -> let r : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if not (is_valid_repr r) then false else destr_payload (key_of r) x inline_for_extraction noextract let filter_bitsum'_bitsum'_t (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot Type = (x: t { ~ (list_mem (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) (list_map snd l1)) }) -> (xr: t { xr == cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size }) -> Tot (y: bool { y == filter_bitsum' (BitSum' key key_size e payload) x }) inline_for_extraction let filter_bitsum'_bitsum'_intro (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (phi: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload [] e) : Tot (filter_bitsum'_t (BitSum' key key_size e payload)) = fun x -> let xr = cl.bitfield_eq_lhs x (bitsum'_size - key_size) bitsum'_size in phi x xr inline_for_extraction let filter_bitsum'_bitsum'_nil (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (h: squash (e == e `L.append` [])) : Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload e []) = (fun x xr -> false) inline_for_extraction let filter_bitsum'_bitsum'_cons (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (k: key) (r: bitfield cl key_size) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` ((k, r) :: l2) /\ list_mem k (list_map fst e) /\ enum_repr_of_key e k == r /\ e == (l1 `L.append` [(k, r)]) `L.append` l2 }) (destr_payload: filter_bitsum'_t (payload k)) (destr_tail: filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) l2) : Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 ((k, r) :: l2)) = fun x xr -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) l2 in [@inline_let] let yr = cl.bitfield_eq_rhs x (bitsum'_size - key_size) bitsum'_size r in [@inline_let] let cond = (xr <: t) = yr in [@inline_let] let _ = assert (cond == true <==> (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) == r) in if cond then destr_payload x else [@inline_let] let _ = L.append_assoc l1 [(k, r)] l2; L.map_append snd l1 [(k, r)]; L.append_mem (L.map snd l1) (L.map snd [(k, r)]) (cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size <: bitfield cl key_size) in destr_tail (x <: t) xr let bitsum_wellfoundedness (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b:bitsum' cl bitsum'_size { BitSum'? b }) : Lemma (let BitSum' key key_size e payload = b in (forall (k:enum_key e). payload k << b)) = () [@filter_bitsum'_t_attr] noextract let rec mk_filter_bitsum'_t' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot (filter_bitsum'_t b) (decreases %[b; 1; ()]) = match b with | BitStop _ -> filter_bitsum'_bitstop cl | BitField sz rest -> filter_bitsum'_bitfield cl bitsum'_size sz rest (mk_filter_bitsum'_t' rest) | BitSum' key key_size e payload -> filter_bitsum'_bitsum'_intro cl bitsum'_size key key_size e payload (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload [] e) and mk_filter_bitsum'_bitsum'_t' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (l1: list (key & bitfield cl key_size)) (l2: list (key & bitfield cl key_size) { e == l1 `L.append` l2 } ) : Tot (filter_bitsum'_bitsum'_t cl bitsum'_size key key_size e payload l1 l2) (decreases %[BitSum' key key_size e payload; 0; l2]) = bitsum_wellfoundedness (BitSum' key key_size e payload); match l2 with | [] -> [@inline_let] let _ = L.append_l_nil l1 in filter_bitsum'_bitsum'_nil cl bitsum'_size key key_size e payload () | (k, r) :: q -> [@inline_let] let _ = enum_repr_of_key_append_cons e l1 (k, r) q; L.append_assoc l1 [(k, r)] q in filter_bitsum'_bitsum'_cons cl bitsum'_size key key_size e payload l1 k r q (mk_filter_bitsum'_t' (payload k)) (mk_filter_bitsum'_bitsum'_t' cl bitsum'_size key key_size e payload (l1 `L.append` [(k, r)]) q) (* Universal destructor *) inline_for_extraction let if_combinator_weak (t: Type) : Tot Type = (cond: bool) -> (sv_true: (cond_true cond -> Tot t)) -> (sv_false: (cond_false cond -> Tot t)) -> Tot (y: t) inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 3, "max_fuel": 8, "max_ifuel": 3, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl from -> Type
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "FStar.Ghost.erased", "LowParse.Spec.BitSum.if_combinator_weak", "FStar.Ghost.reveal", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.synth_bitsum'" ]
[]
false
false
false
false
true
let destr_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#from: nat) (b: bitsum' cl from) : Tot (Type u#(a + 1)) =
u: (bitsum'_type b -> Tot (Type u#a)) -> u_if: (k: Ghost.erased (bitsum'_type b) -> Tot (if_combinator_weak (u (Ghost.reveal k)))) -> f: (k: bitsum'_type b -> Tot (u k)) -> x: parse_filter_refine (filter_bitsum' b) -> Tot (u (synth_bitsum' b x))
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.bitsum'_key_of_t
val bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size))
val bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size))
let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 613, "start_col": 0, "start_line": 593 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "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: LowParse.Spec.BitSum.bitsum' cl bitsum'_size -> x: LowParse.Spec.BitSum.bitsum'_type b -> Prims.Tot (LowParse.Spec.BitSum.bitsum'_key_type b)
Prims.Tot
[ "total", "" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.nat", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_Subtraction", "LowParse.Spec.BitSum.bitsum'_type_elim_BitField", "LowParse.BitFields.bitfield", "LowParse.Spec.BitSum.bitsum'_key_type_intro_BitField", "LowParse.Spec.BitSum.bitsum'_key_of_t", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.Enum.enum", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.BitSum.bitsum'_type_elim_BitSum'", "LowParse.Spec.BitSum.bitsum'_key_type_intro_BitSum'", "Prims.Mkdtuple2" ]
[ "recursion" ]
false
false
false
false
false
let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) =
match b with | BitStop _ -> () | BitField sz rest -> (match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | _, tl -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl)) | BitSum' key key_size e payload -> match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k , pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.parse_bitsum_kind
val parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot parser_kind
val parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot parser_kind
let parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 87, "end_line": 770, "start_col": 0, "start_line": 761 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction noextract let id (#t: Type) (x: t) : Tot t = x inline_for_extraction noextract noeq type synth_case_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) : Type = | SynthCase: (f: ( (k' : bitsum'_type b) -> type_of_tag (bitsum'_key_of_t b k') -> Tot (refine_with_tag (tag_of_data) k') )) -> (f_inj: ( (k' : bitsum'_type b) -> (pl1: type_of_tag (bitsum'_key_of_t b k')) -> (pl2: type_of_tag (bitsum'_key_of_t b k')) -> Lemma (requires (f k' pl1 == f k' pl2)) (ensures (pl1 == pl2)) )) -> (g: ( (k' : bitsum'_type b) -> refine_with_tag (tag_of_data) k' -> Tot (type_of_tag (bitsum'_key_of_t b k')) )) -> (f_g_eq: ( (k: bitsum'_type b) -> (x: refine_with_tag (tag_of_data) k) -> Lemma (f k (g k x) == x) )) -> synth_case_t b data tag_of_data type_of_tag let synth_case_g_f_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#b: bitsum' cl tot) (#data: Type) (#tag_of_data: (data -> Tot (bitsum'_type b))) (#type_of_tag: (bitsum'_key_type b -> Tot Type)) (s: synth_case_t b data tag_of_data type_of_tag) (k: bitsum'_type b) (x: type_of_tag (bitsum'_key_of_t b k)) : Lemma (s.g k (s.f k x) == x) = s.f_g_eq k (s.f k x); s.f_inj k (s.g k (s.f k x)) x #push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3" let rec weaken_parse_bitsum_cases_kind' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (f: (x: bitsum'_key_type b) -> Tot parser_kind) : Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) (decreases (bitsum'_size)) = match b with | BitStop _ -> (| f (), (fun y -> ()) |) | BitField sz rest -> let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in (| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |) | BitSum' key key_size e payload -> let keys : list key = List.Tot.map fst e in let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma (requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x)) (ensures (k `is_weaker_than` f y)))) = if List.Tot.mem x keys then let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in assert (y1 == x); g y2 ) |) else (| default_parser_kind, (fun y -> ()) |) in let k = glb_list_of #key (fun x -> dfst (phi x)) keys in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in dsnd (phi y1) y ) |) let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) }) = let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k let synth_bitsum_case_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] = synth_injective_intro' (synth_case.f x) (fun y z -> synth_case.f_inj x y z ) let parse_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bitsum'_type b) : Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) = let tg : bitsum'_key_type b = bitsum'_key_of_t b x in let (| k_, p |) = f tg in weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 3, "max_fuel": 8, "max_ifuel": 3, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
kt: LowParse.Spec.Base.parser_kind -> b: LowParse.Spec.BitSum.bitsum' cl tot -> type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) -> f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) -> LowParse.Spec.Base.parser_kind
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_key_type", "Prims.dtuple2", "LowParse.Spec.Base.parser", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind" ]
[]
false
false
false
false
false
let parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot parser_kind =
and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind
val weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))})
val weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))})
let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) }) = let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 725, "start_col": 0, "start_line": 715 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction noextract let id (#t: Type) (x: t) : Tot t = x inline_for_extraction noextract noeq type synth_case_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) : Type = | SynthCase: (f: ( (k' : bitsum'_type b) -> type_of_tag (bitsum'_key_of_t b k') -> Tot (refine_with_tag (tag_of_data) k') )) -> (f_inj: ( (k' : bitsum'_type b) -> (pl1: type_of_tag (bitsum'_key_of_t b k')) -> (pl2: type_of_tag (bitsum'_key_of_t b k')) -> Lemma (requires (f k' pl1 == f k' pl2)) (ensures (pl1 == pl2)) )) -> (g: ( (k' : bitsum'_type b) -> refine_with_tag (tag_of_data) k' -> Tot (type_of_tag (bitsum'_key_of_t b k')) )) -> (f_g_eq: ( (k: bitsum'_type b) -> (x: refine_with_tag (tag_of_data) k) -> Lemma (f k (g k x) == x) )) -> synth_case_t b data tag_of_data type_of_tag let synth_case_g_f_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#b: bitsum' cl tot) (#data: Type) (#tag_of_data: (data -> Tot (bitsum'_type b))) (#type_of_tag: (bitsum'_key_type b -> Tot Type)) (s: synth_case_t b data tag_of_data type_of_tag) (k: bitsum'_type b) (x: type_of_tag (bitsum'_key_of_t b k)) : Lemma (s.g k (s.f k x) == x) = s.f_g_eq k (s.f k x); s.f_inj k (s.g k (s.f k x)) x #push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3" let rec weaken_parse_bitsum_cases_kind' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (f: (x: bitsum'_key_type b) -> Tot parser_kind) : Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) (decreases (bitsum'_size)) = match b with | BitStop _ -> (| f (), (fun y -> ()) |) | BitField sz rest -> let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in (| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |) | BitSum' key key_size e payload -> let keys : list key = List.Tot.map fst e in let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma (requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x)) (ensures (k `is_weaker_than` f y)))) = if List.Tot.mem x keys then let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in assert (y1 == x); g y2 ) |) else (| default_parser_kind, (fun y -> ()) |) in let k = glb_list_of #key (fun x -> dfst (phi x)) keys in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in dsnd (phi y1) y ) |)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 3, "max_fuel": 8, "max_ifuel": 3, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl tot -> type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) -> f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) -> k: LowParse.Spec.Base.parser_kind { forall (x: LowParse.Spec.BitSum.bitsum'_key_type b). LowParse.Spec.Base.is_weaker_than k (FStar.Pervasives.dfst (f x)) }
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_key_type", "Prims.dtuple2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "Prims.unit", "Prims.l_True", "Prims.squash", "LowParse.Spec.Base.is_weaker_than", "FStar.Pervasives.dfst", "Prims.Nil", "FStar.Pervasives.pattern", "FStar.Classical.forall_intro", "Prims.l_Forall", "LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind'" ]
[]
false
false
false
false
false
let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot (k: parser_kind{forall (x: bitsum'_key_type b). k `is_weaker_than` (dfst (f x))}) =
let (| k , phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.parse_bitsum
val parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
val parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data)
let parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) = parse_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 63, "end_line": 792, "start_col": 0, "start_line": 772 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction noextract let id (#t: Type) (x: t) : Tot t = x inline_for_extraction noextract noeq type synth_case_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) : Type = | SynthCase: (f: ( (k' : bitsum'_type b) -> type_of_tag (bitsum'_key_of_t b k') -> Tot (refine_with_tag (tag_of_data) k') )) -> (f_inj: ( (k' : bitsum'_type b) -> (pl1: type_of_tag (bitsum'_key_of_t b k')) -> (pl2: type_of_tag (bitsum'_key_of_t b k')) -> Lemma (requires (f k' pl1 == f k' pl2)) (ensures (pl1 == pl2)) )) -> (g: ( (k' : bitsum'_type b) -> refine_with_tag (tag_of_data) k' -> Tot (type_of_tag (bitsum'_key_of_t b k')) )) -> (f_g_eq: ( (k: bitsum'_type b) -> (x: refine_with_tag (tag_of_data) k) -> Lemma (f k (g k x) == x) )) -> synth_case_t b data tag_of_data type_of_tag let synth_case_g_f_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#b: bitsum' cl tot) (#data: Type) (#tag_of_data: (data -> Tot (bitsum'_type b))) (#type_of_tag: (bitsum'_key_type b -> Tot Type)) (s: synth_case_t b data tag_of_data type_of_tag) (k: bitsum'_type b) (x: type_of_tag (bitsum'_key_of_t b k)) : Lemma (s.g k (s.f k x) == x) = s.f_g_eq k (s.f k x); s.f_inj k (s.g k (s.f k x)) x #push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3" let rec weaken_parse_bitsum_cases_kind' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (f: (x: bitsum'_key_type b) -> Tot parser_kind) : Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) (decreases (bitsum'_size)) = match b with | BitStop _ -> (| f (), (fun y -> ()) |) | BitField sz rest -> let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in (| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |) | BitSum' key key_size e payload -> let keys : list key = List.Tot.map fst e in let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma (requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x)) (ensures (k `is_weaker_than` f y)))) = if List.Tot.mem x keys then let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in assert (y1 == x); g y2 ) |) else (| default_parser_kind, (fun y -> ()) |) in let k = glb_list_of #key (fun x -> dfst (phi x)) keys in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in dsnd (phi y1) y ) |) let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) }) = let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k let synth_bitsum_case_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] = synth_injective_intro' (synth_case.f x) (fun y z -> synth_case.f_inj x y z ) let parse_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bitsum'_type b) : Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) = let tg : bitsum'_key_type b = bitsum'_key_of_t b x in let (| k_, p |) = f tg in weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x) inline_for_extraction let parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 3, "max_fuel": 8, "max_ifuel": 3, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Spec.BitSum.bitsum' cl tot -> tag_of_data: (_: data -> LowParse.Spec.BitSum.bitsum'_type b) -> type_of_tag: (_: LowParse.Spec.BitSum.bitsum'_key_type b -> Type) -> synth_case: LowParse.Spec.BitSum.synth_case_t b data tag_of_data type_of_tag -> p: LowParse.Spec.Base.parser kt t -> f: (x: LowParse.Spec.BitSum.bitsum'_key_type b -> Prims.dtuple2 LowParse.Spec.Base.parser_kind (fun k -> LowParse.Spec.Base.parser k (type_of_tag x))) -> LowParse.Spec.Base.parser (LowParse.Spec.BitSum.parse_bitsum_kind kt b type_of_tag f) data
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "LowParse.Spec.BitSum.bitsum'", "LowParse.Spec.BitSum.bitsum'_type", "LowParse.Spec.BitSum.bitsum'_key_type", "LowParse.Spec.BitSum.synth_case_t", "LowParse.Spec.Base.parser", "Prims.dtuple2", "LowParse.Spec.Combinators.parse_tagged_union", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BitSum.parse_bitsum'", "LowParse.Spec.BitSum.weaken_parse_bitsum_cases_kind", "LowParse.Spec.BitSum.parse_bitsum_cases", "LowParse.Spec.BitSum.parse_bitsum_kind" ]
[]
false
false
false
false
false
let parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b -> Tot (k: parser_kind & parser k (type_of_tag x)))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) =
parse_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f)
false
LowParse.Spec.BitSum.fst
LowParse.Spec.BitSum.filter_bitsum'_bitstop
val filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
val filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ()))
let filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) = fun _ -> true
{ "file_name": "src/lowparse/LowParse.Spec.BitSum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 15, "end_line": 1089, "start_col": 0, "start_line": 1084 }
module LowParse.Spec.BitSum include LowParse.Spec.Enum include LowParse.BitFields module L = FStar.List.Tot // IMPORTANT: these bitfield operators are defined in a MOST // significant bit (MSB) first fashion. noeq type bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) = | BitStop of (squash (bitsum'_size == 0)) | BitField : (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) -> (rest: bitsum' cl (bitsum'_size - sz)) -> bitsum' cl bitsum'_size | BitSum' : (key: eqtype) -> (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) -> // key_size made positive because F* cannot prove that (payload _) is a smaller term wrt. << without FStar.WellFounded.axiom1_dep //NS: TODO: please check this comment (e: enum key (bitfield cl key_size)) -> (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) -> bitsum' cl bitsum'_size noextract let rec bitsum'_type' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> (bitfield cl sz & bitsum'_type' rest) | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_type' (payload key)) noextract let bitsum'_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = bitsum'_type' b inline_for_extraction let bitsum'_type_bitfield (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) : Tot Type = bitfield cl sz & bitsum'_type rest let bitsum'_type_bitsum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) : Tot Type = (k': enum_key e & bitsum'_type (payload k')) noextract noeq type filter_bitsum'_t_attr = [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type (BitSum' key key_size e payload)) : Tot (bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_type_bitsum' cl bitsum'_size key key_size e payload) : Tot (bitsum'_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type (BitField sz rest)) : Tot (bitsum'_type_bitfield bitsum'_size sz rest) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_type_bitfield bitsum'_size sz rest) : Tot (bitsum'_type (BitField sz rest)) = x noextract let rec bitsum'_key_type (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot eqtype (decreases (bitsum'_size)) = match b with | BitStop _ -> unit | BitField sz rest -> bitsum'_key_type rest | BitSum' key key_size e payload -> (key: enum_key e & bitsum'_key_type (payload key)) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: bitsum'_key_type (BitSum' key key_size e payload)) : Tot (k': enum_key e & bitsum'_key_type (payload k')) = x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitSum' (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (key: eqtype) (key_size: nat { key_size > 0 /\ key_size <= bitsum'_size /\ bitsum'_size <= tot }) (e: enum key (bitfield cl key_size)) (payload: (enum_key e -> Tot (bitsum' cl (bitsum'_size - key_size)))) (x: (k': enum_key e & bitsum'_key_type (payload k'))) : Tot (bitsum'_key_type (BitSum' key key_size e payload)) = x [@filter_bitsum'_t_attr] unfold inline_for_extraction let coerce (t2: Type) (#t1: Type) (x: t1) : Pure t2 (requires (t1 == t2)) (ensures (fun _ -> True)) = (x <: t2) [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_intro_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type rest) : Tot (bitsum'_key_type (BitField sz rest)) = coerce (bitsum'_key_type (BitField sz rest)) x [@filter_bitsum'_t_attr] inline_for_extraction let bitsum'_key_type_elim_BitField (#tot: pos) (#t: eqtype) (cl: uint_t tot t) (bitsum'_size: nat) (sz: nat { sz > 0 /\ sz <= bitsum'_size /\ bitsum'_size <= tot }) (rest: bitsum' cl (bitsum'_size - sz)) (x: bitsum'_key_type (BitField sz rest)) : Tot (bitsum'_key_type rest) = coerce (bitsum'_key_type rest) x let rec filter_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: t) : Tot bool (decreases (bitsum'_size)) = match b with | BitStop _ -> true | BitField _ rest -> filter_bitsum' rest x | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in if list_mem f (list_map snd e) then let k = enum_key_of_repr e f in filter_bitsum' (payload k) x else false let rec synth_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: parse_filter_refine (filter_bitsum' b)) : Tot (bitsum'_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> bitsum'_type_intro_BitField cl bitsum'_size sz rest (cl.get_bitfield x (bitsum'_size - sz) bitsum'_size, synth_bitsum' rest x) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) bitsum'_size in let k : enum_key e = enum_key_of_repr e f in let z : bitsum'_type (payload k) = synth_bitsum' (payload k) x in let p : (k' : enum_key e & bitsum'_type (payload k')) = (| k, z |) in bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload p module BF = LowParse.BitFields #push-options "--z3rlimit 16" let rec synth_bitsum'_injective' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (synth_bitsum' b x == synth_bitsum' b y)) (ensures (cl.get_bitfield x 0 bitsum'_size == cl.get_bitfield y 0 bitsum'_size)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_empty (cl.v x) 0; BF.get_bitfield_empty (cl.v y) 0; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitField sz rest -> assert (cl.v (cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size)) == cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))); synth_bitsum'_injective' rest x y; assert (cl.v (cl.get_bitfield x 0 (bitsum'_size - sz)) == cl.v (cl.get_bitfield y 0 (bitsum'_size - sz))); BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - sz]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in let k = enum_key_of_repr e f in enum_repr_of_key_of_repr e f; enum_repr_of_key_of_repr e g; assert (cl.v f == cl.v g); synth_bitsum'_injective' (payload k) x y; BF.get_bitfield_partition (cl.v x) (cl.v y) 0 bitsum'_size [bitsum'_size - key_size]; assert (cl.uint_to_t (cl.v (cl.get_bitfield x 0 bitsum'_size)) == cl.uint_to_t (cl.v (cl.get_bitfield y 0 bitsum'_size))) #pop-options let synth_bitsum'_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) : Lemma (synth_injective (synth_bitsum' b)) // [SMTPat (synth_injective (synth_bitsum' b))] = synth_injective_intro' (synth_bitsum' b) (fun x y -> synth_bitsum'_injective' b x y; BF.get_bitfield_full (cl.v x); BF.get_bitfield_full (cl.v y); assert (cl.uint_to_t (cl.v x) == cl.uint_to_t (cl.v y)) ) // #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #push-options "--z3rlimit 64" let rec synth_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: parse_filter_refine (filter_bitsum' b)) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (synth_bitsum' b x == synth_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let f : bitfield cl sz = cl.get_bitfield x (bitsum'_size - sz) (bitsum'_size) in let g : bitfield cl sz = cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - sz) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); synth_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); let k = enum_key_of_repr e f in let u = synth_bitsum' (payload k) x in let v = synth_bitsum' (payload k) y in assert (synth_bitsum' (BitSum' key key_size e payload) x == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, u |)); assert (synth_bitsum' (BitSum' key key_size e payload) y == bitsum'_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, v |)); BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v x) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v x) 0 bitsum'_size) (0) (bitsum'_size - key_size)); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); assert (BF.get_bitfield (cl.v y) 0 (bitsum'_size - key_size) == BF.get_bitfield (BF.get_bitfield (cl.v y) 0 bitsum'_size) (0) (bitsum'_size - key_size)); synth_bitsum'_ext (payload k) x y; assert (u == v) #pop-options let parse_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (p: parser k t) : Tot (parser (parse_filter_kind k) (bitsum'_type b)) = synth_bitsum'_injective b; (p `parse_filter` filter_bitsum' b) `parse_synth` synth_bitsum' b let rec synth_bitsum'_recip' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot t (decreases (bitsum'_size)) = match b with | BitStop _ -> cl.uint_to_t 0 | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in cl.set_bitfield (synth_bitsum'_recip' rest tl) (bitsum'_size - sz) (bitsum'_size) hd | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y1 = synth_bitsum'_recip' (payload k) tl in let y2 = cl.set_bitfield y1 (bitsum'_size - key_size) bitsum'_size (enum_repr_of_key e k) in y2 #push-options "--z3rlimit 16" let rec get_bitfield_synth_bitsum'_recip'_other (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) (lo: nat) (hi: nat { bitsum'_size <= lo /\ lo <= hi /\ hi <= tot }) : Lemma (ensures (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) lo hi) == 0)) (decreases (bitsum'_size)) = match b with | BitStop h -> BF.get_bitfield_zero tot lo hi | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) bitsum'_size (cl.v hd) lo hi; get_bitfield_synth_bitsum'_recip'_other rest tl lo hi | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) lo hi; get_bitfield_synth_bitsum'_recip'_other (payload k) tl lo hi #pop-options #push-options "--z3rlimit 64" let rec filter_bitsum'_ext (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x y: t) : Lemma (requires (BF.get_bitfield (cl.v x) 0 bitsum'_size == BF.get_bitfield (cl.v y) 0 bitsum'_size)) (ensures (filter_bitsum' b x == filter_bitsum' b y)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - sz); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - sz); filter_bitsum'_ext rest x y | BitSum' key key_size e payload -> let f : bitfield cl key_size = cl.get_bitfield x (bitsum'_size - key_size) (bitsum'_size) in let g : bitfield cl key_size = cl.get_bitfield y (bitsum'_size - key_size) (bitsum'_size) in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size (bitsum'_size - key_size) bitsum'_size; assert (BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size) == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v f == BF.get_bitfield (cl.v x) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.v g == BF.get_bitfield (cl.v y) (bitsum'_size - key_size) (bitsum'_size)); assert (cl.uint_to_t (cl.v f) == cl.uint_to_t (cl.v g)); assert (f == g); if list_mem f (list_map snd e) then begin let k = enum_key_of_repr e f in BF.get_bitfield_get_bitfield (cl.v x) 0 bitsum'_size 0 (bitsum'_size - key_size); BF.get_bitfield_get_bitfield (cl.v y) 0 bitsum'_size 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) x y end else () #pop-options let rec synth_bitsum'_recip'_prop (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (filter_bitsum' b (synth_bitsum'_recip' b x) == true)) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' rest tl)) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest (synth_bitsum'_recip' b x) (synth_bitsum'_recip' rest tl); synth_bitsum'_recip'_prop rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in BF.get_bitfield_set_bitfield_same (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); BF.get_bitfield_set_bitfield_other (cl.v (synth_bitsum'_recip' (payload k) tl)) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); assert (cl.uint_to_t (cl.v (cl.get_bitfield (synth_bitsum'_recip' b x) (bitsum'_size - key_size) (bitsum'_size))) == cl.uint_to_t (cl.v (enum_repr_of_key e k <: t))); enum_key_of_repr_of_key e k; filter_bitsum'_ext (payload k) (synth_bitsum'_recip' b x) (synth_bitsum'_recip' (payload k) tl); synth_bitsum'_recip'_prop (payload k) tl inline_for_extraction let synth_bitsum'_recip (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (parse_filter_refine (filter_bitsum' b)) = synth_bitsum'_recip'_prop b x; synth_bitsum'_recip' b x #push-options "--z3rlimit 16" let rec synth_bitsum'_recip_inverse' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Lemma (ensures (synth_bitsum' b (synth_bitsum'_recip b x) == x)) (decreases bitsum'_size) = match b with | BitStop _ -> () | BitField sz rest -> let (hd, tl) = bitsum'_type_elim_BitField cl bitsum'_size sz rest x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip rest tl in (* Part 1/2: synth_bitfield cl 0 header_size header y == hd *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - sz) (bitsum'_size))) == cl.uint_to_t (cl.v hd)); (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - sz) (bitsum'_size) (cl.v hd) 0 (bitsum'_size - sz); filter_bitsum'_ext rest y y1; synth_bitsum'_ext rest y y1 ; synth_bitsum'_recip_inverse' rest tl | BitSum' key key_size e payload -> let (| k, tl |) = bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x in let y = synth_bitsum'_recip b x in let y1 = synth_bitsum'_recip (payload k) tl in (* Part 1/2: k == enum_key_of_repr e f *) BF.get_bitfield_set_bitfield_same (cl.v y1) (bitsum'_size - key_size) (bitsum'_size) (cl.v (enum_repr_of_key e k)); assert (cl.uint_to_t (cl.v (cl.get_bitfield y (bitsum'_size - key_size) bitsum'_size)) == cl.uint_to_t (cl.v (enum_repr_of_key e k))); enum_key_of_repr_of_key e k; (* Part 2/2: synth_bitfield cl (header_size + key_size) tot (payload k) y == tl *) BF.get_bitfield_set_bitfield_other (cl.v y1) (bitsum'_size - key_size) bitsum'_size (cl.v (enum_repr_of_key e k)) 0 (bitsum'_size - key_size); filter_bitsum'_ext (payload k) y y1; synth_bitsum'_ext (payload k) y y1 ; synth_bitsum'_recip_inverse' (payload k) tl #pop-options let synth_bitsum'_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Lemma (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b)) // [SMTPat (synth_inverse (synth_bitsum' b) (synth_bitsum'_recip b))] = synth_inverse_intro' (synth_bitsum' b) (synth_bitsum'_recip b) (fun x -> synth_bitsum'_recip_inverse' b x ) let serialize_bitsum' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) : Tot (serializer (parse_bitsum' b p)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () let serialize_bitsum'_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#k: parser_kind) (#p: parser k t) (s: serializer p) (x: bitsum'_type b) : Lemma (serialize (serialize_bitsum' b s) x == serialize s (synth_bitsum'_recip b x)) = synth_bitsum'_injective b; synth_bitsum'_recip_inverse b; serialize_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) (s `serialize_filter` filter_bitsum' b) (synth_bitsum'_recip b) () x let rec bitsum'_key_of_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (x: bitsum'_type b) : Tot (bitsum'_key_type b) (decreases (bitsum'_size)) = match b with | BitStop _ -> () | BitField sz rest -> begin match bitsum'_type_elim_BitField cl bitsum'_size sz rest x with | (_, tl) -> bitsum'_key_type_intro_BitField cl bitsum'_size sz rest (bitsum'_key_of_t rest tl) end | BitSum' key key_size e payload -> begin match bitsum'_type_elim_BitSum' cl bitsum'_size key key_size e payload x with | (| k, pl |) -> bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| k, bitsum'_key_of_t (payload k) pl |) end inline_for_extraction noextract let id (#t: Type) (x: t) : Tot t = x inline_for_extraction noextract noeq type synth_case_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) : Type = | SynthCase: (f: ( (k' : bitsum'_type b) -> type_of_tag (bitsum'_key_of_t b k') -> Tot (refine_with_tag (tag_of_data) k') )) -> (f_inj: ( (k' : bitsum'_type b) -> (pl1: type_of_tag (bitsum'_key_of_t b k')) -> (pl2: type_of_tag (bitsum'_key_of_t b k')) -> Lemma (requires (f k' pl1 == f k' pl2)) (ensures (pl1 == pl2)) )) -> (g: ( (k' : bitsum'_type b) -> refine_with_tag (tag_of_data) k' -> Tot (type_of_tag (bitsum'_key_of_t b k')) )) -> (f_g_eq: ( (k: bitsum'_type b) -> (x: refine_with_tag (tag_of_data) k) -> Lemma (f k (g k x) == x) )) -> synth_case_t b data tag_of_data type_of_tag let synth_case_g_f_eq (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#b: bitsum' cl tot) (#data: Type) (#tag_of_data: (data -> Tot (bitsum'_type b))) (#type_of_tag: (bitsum'_key_type b -> Tot Type)) (s: synth_case_t b data tag_of_data type_of_tag) (k: bitsum'_type b) (x: type_of_tag (bitsum'_key_of_t b k)) : Lemma (s.g k (s.f k x) == x) = s.f_g_eq k (s.f k x); s.f_inj k (s.g k (s.f k x)) x #push-options "--z3rlimit 16 --max_ifuel 3 --initial_ifuel 3" let rec weaken_parse_bitsum_cases_kind' (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) (f: (x: bitsum'_key_type b) -> Tot parser_kind) : Tot (k' : parser_kind & ((x: bitsum'_key_type b) -> Lemma (k' `is_weaker_than` f x))) (decreases (bitsum'_size)) = match b with | BitStop _ -> (| f (), (fun y -> ()) |) | BitField sz rest -> let (| g, phi |) = weaken_parse_bitsum_cases_kind' rest (fun x -> f (bitsum'_key_type_intro_BitField cl bitsum'_size sz rest x)) in (| g, (fun x -> phi (bitsum'_key_type_elim_BitField cl bitsum'_size sz rest x)) |) | BitSum' key key_size e payload -> let keys : list key = List.Tot.map fst e in let phi (x: key) : Tot (k: parser_kind & ((y: bitsum'_key_type b) -> Lemma (requires (dfst (bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y) == x)) (ensures (k `is_weaker_than` f y)))) = if List.Tot.mem x keys then let (| k, g |) = weaken_parse_bitsum_cases_kind' (payload x) (fun z -> f (bitsum'_key_type_intro_BitSum' cl bitsum'_size key key_size e payload (| x, z |))) in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in assert (y1 == x); g y2 ) |) else (| default_parser_kind, (fun y -> ()) |) in let k = glb_list_of #key (fun x -> dfst (phi x)) keys in (| k, (fun y -> let (| y1, y2 |) = bitsum'_key_type_elim_BitSum' cl bitsum'_size key key_size e payload y in dsnd (phi y1) y ) |) let weaken_parse_bitsum_cases_kind (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (k: parser_kind { forall (x: bitsum'_key_type b) . k `is_weaker_than` dfst (f x) }) = let (| k, phi |) = weaken_parse_bitsum_cases_kind' b (fun k -> dfst (f k)) in Classical.forall_intro phi; k let synth_bitsum_case_injective (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_injective (synth_case.f x)) [SMTPat (synth_injective (synth_case.f x))] = synth_injective_intro' (synth_case.f x) (fun y z -> synth_case.f_inj x y z ) let parse_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bitsum'_type b) : Tot (parser (weaken_parse_bitsum_cases_kind b type_of_tag f) (refine_with_tag (tag_of_data) x)) = let tg : bitsum'_key_type b = bitsum'_key_of_t b x in let (| k_, p |) = f tg in weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (p `parse_synth` synth_case.f x) inline_for_extraction let parse_bitsum_kind (kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot parser_kind = and_then_kind (parse_filter_kind kt) (weaken_parse_bitsum_cases_kind b type_of_tag f) let parse_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) : Tot (parser (parse_bitsum_kind kt b type_of_tag f) data) = parse_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f) module Seq = FStar.Seq #push-options "--z3rlimit 16" let parse_bitsum_eq (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bytes) : Lemma (parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse (parse_bitsum' b p) x with | None -> None | Some (tg, consumed1) -> let k = bitsum'_key_of_t b tg in begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with | None -> None | Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2) end )) = parse_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) (parse_bitsum' b p) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) (parse_bitsum_cases b tag_of_data type_of_tag synth_case f) x; match parse (parse_bitsum' b p) x with | None -> () | Some (tg, consumed1) -> let k = bitsum'_key_of_t b tg in synth_bitsum_case_injective b tag_of_data type_of_tag synth_case tg; parse_synth_eq (dsnd (f k)) (synth_case.f tg) (Seq.slice x consumed1 (Seq.length x)) #pop-options let parse_bitsum_eq' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (p: parser kt t) (f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (x: bytes) : Lemma (parse (parse_bitsum b tag_of_data type_of_tag synth_case p f) x == (match parse p x with | None -> None | Some (tg', consumed1) -> if filter_bitsum' b tg' then let tg = synth_bitsum' b tg' in let k = bitsum'_key_of_t b tg in begin match parse (dsnd (f k)) (Seq.slice x consumed1 (Seq.length x)) with | None -> None | Some (y, consumed2) -> Some ((synth_case.f tg y <: data), consumed1 + consumed2) end else None )) = parse_bitsum_eq b tag_of_data type_of_tag synth_case p f x; synth_bitsum'_injective b; parse_synth_eq (p `parse_filter` filter_bitsum' b) (synth_bitsum' b) x; parse_filter_eq p (filter_bitsum' b) x let synth_bitsum_case_recip_inverse (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (x: bitsum'_type b) : Lemma (synth_inverse (synth_case.f x) (synth_case.g x)) [SMTPat (synth_inverse (synth_case.f x) (synth_case.g x))] // FIXME: does not trigger. WHY WHY WHY? = synth_inverse_intro' (synth_case.f x) (synth_case.g x) (fun y -> synth_case.f_g_eq x y ) let serialize_bitsum_cases (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: bitsum'_type b) : Tot (serializer (parse_bitsum_cases b tag_of_data type_of_tag synth_case f x)) = let tg = bitsum'_key_of_t b x in let (| _, p |) = f tg in synth_bitsum_case_injective b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger? synth_bitsum_case_recip_inverse b tag_of_data type_of_tag synth_case x; // FIXME: WHY WHY WHY does the pattern not trigger? serialize_weaken (weaken_parse_bitsum_cases_kind b type_of_tag f) (serialize_synth p (synth_case.f x) (g tg) (synth_case.g x) ()) let serialize_bitsum (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) : Tot (serializer (parse_bitsum b tag_of_data type_of_tag synth_case p f)) = serialize_tagged_union #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p) (serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) #(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) (serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) let serialize_bitsum_alt (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : GTot bytes = let tg = tag_of_data x in let k = bitsum'_key_of_t b tg in let payload = synth_case.g tg x in serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload let serialize_bitsum_eq (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : Lemma (serialize (serialize_bitsum b tag_of_data type_of_tag synth_case s g) x == serialize_bitsum_alt b tag_of_data type_of_tag synth_case s g x) = serialize_tagged_union_eq #(parse_filter_kind kt) #(bitsum'_type b) #(parse_bitsum' b p) (serialize_bitsum' b s) #(data) (tag_of_data) #(weaken_parse_bitsum_cases_kind b type_of_tag f) #(parse_bitsum_cases b tag_of_data type_of_tag synth_case f) (serialize_bitsum_cases b tag_of_data type_of_tag synth_case #f g) x; let tg = tag_of_data x in let k = bitsum'_key_of_t b tg in serialize_bitsum'_eq b s tg; let (| _, p |) = f k in serialize_synth_eq #_ #(type_of_tag k) p (synth_case.f tg) (g k) (synth_case.g tg) () x let serialize_bitsum_eq' (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (x: data) : Lemma (serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x == serialize_bitsum_alt #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g x) = serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g x let serialize_bitsum_alt_2 (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (tg: bitsum'_type b) (payload: type_of_tag (bitsum'_key_of_t b tg)) : GTot bytes = let k = bitsum'_key_of_t b tg in serialize s (synth_bitsum'_recip b tg) `Seq.append` serialize (g k) payload let serialize_bitsum_eq_2 (#kt: parser_kind) (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (b: bitsum' cl tot) (#data: Type) (tag_of_data: (data -> Tot (bitsum'_type b))) (type_of_tag: (bitsum'_key_type b -> Tot Type)) (synth_case: synth_case_t b data tag_of_data type_of_tag) (#p: parser kt t) (s: serializer p { kt.parser_kind_subkind == Some ParserStrong } ) (#f: (x: bitsum'_key_type b) -> Tot (k: parser_kind & parser k (type_of_tag x))) (g: (x: bitsum'_key_type b) -> Tot (serializer (dsnd (f x)))) (tg: bitsum'_type b) (payload: type_of_tag (bitsum'_key_of_t b tg)) : Lemma (serialize_bitsum #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g (synth_case.f tg payload) == serialize_bitsum_alt_2 #kt #tot #t #cl b #data tag_of_data type_of_tag synth_case #p s #f g tg payload) = serialize_bitsum_eq b tag_of_data type_of_tag synth_case s g (synth_case.f tg payload); synth_case_g_f_eq synth_case tg payload (* Implementation of filter_bitsum' *) inline_for_extraction noextract let filter_bitsum'_t (#tot: pos) (#t: eqtype) (#cl: uint_t tot t) (#bitsum'_size: nat) (b: bitsum' cl bitsum'_size) : Tot Type = (x: t) -> Tot (y: bool { y == filter_bitsum' b x })
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.BitFields.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "LowParse.Spec.BitSum.fst" }
[ { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "LowParse.BitFields", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.BitFields", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 3, "max_fuel": 8, "max_ifuel": 3, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cl: LowParse.BitFields.uint_t tot t -> LowParse.Spec.BitSum.filter_bitsum'_t (LowParse.Spec.BitSum.BitStop ())
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.eqtype", "LowParse.BitFields.uint_t", "Prims.bool", "Prims.eq2", "LowParse.Spec.BitSum.filter_bitsum'", "LowParse.Spec.BitSum.BitStop", "LowParse.Spec.BitSum.filter_bitsum'_t" ]
[]
false
false
false
false
false
let filter_bitsum'_bitstop (#tot: pos) (#t: eqtype) (cl: uint_t tot t) : Tot (filter_bitsum'_t #tot #t #cl #0 (BitStop ())) =
fun _ -> true
false
FStar.Monotonic.HyperHeap.fsti
FStar.Monotonic.HyperHeap.modifies_just
val modifies_just : s: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> m0: FStar.Monotonic.HyperHeap.hmap -> m1: FStar.Monotonic.HyperHeap.hmap -> Prims.logical
let modifies_just (s:Set.set rid) (m0:hmap) (m1:hmap) = Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\ Set.subset (Map.domain m0) (Map.domain m1)
{ "file_name": "ulib/FStar.Monotonic.HyperHeap.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 116, "start_col": 0, "start_line": 114 }
(* Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Monotonic.HyperHeap module Set = FStar.Set module Map = FStar.Map open FStar.Monotonic.Heap open FStar.Ghost (* * This module provides the map view of the memory and associated functions and lemmas * The intention of this module is for it to be included in HyperStack * Clients should not open/know about HyperHeap, they should work only with HyperStack *) (* * AR: mark it must_erase_for_extraction temporarily until CMI comes in *) [@@must_erase_for_extraction] val rid :eqtype val reveal (r:rid) :GTot (list (int * int)) let rid_last_component (r:rid) :GTot int = let open FStar.List.Tot in let r = reveal r in if length r = 0 then 0 else snd (hd r) val color (x:rid) :GTot int val rid_freeable (x:rid) : GTot bool type hmap = Map.t rid heap val root : r:rid{color r == 0 /\ not (rid_freeable r)} val root_last_component (_:unit) : Lemma (rid_last_component root == 0) let root_has_color_zero (u:unit) :Lemma (color root == 0) = () val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root)) private val rid_length (r:rid) :GTot nat private val rid_tail (r:rid{rid_length r > 0}) :rid val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2)) let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i) val lemma_disjoint_includes (i:rid) (j:rid) (k:rid) :Lemma (requires (disjoint i j /\ includes j k)) (ensures (disjoint i k)) (decreases (List.Tot.length (reveal k))) [SMTPat (disjoint i j); SMTPat (includes j k)] val extends (i:rid) (j:rid) :GTot bool val parent (r:rid{r =!= root}) :rid val lemma_includes_refl (i:rid) :Lemma (includes i i) [SMTPat (includes i i)] val lemma_extends_includes (i:rid) (j:rid) :Lemma (requires (extends j i)) (ensures (includes i j /\ not(includes j i))) [SMTPat (extends j i)] val lemma_includes_anti_symmetric (i:rid) (j:rid) :Lemma (requires (includes i j /\ i =!= j)) (ensures (not (includes j i))) [SMTPat (includes i j)] val lemma_extends_disjoint (i:rid) (j:rid) (k:rid) :Lemma (requires (extends j i /\ extends k i /\ j =!= k)) (ensures (disjoint j k)) val lemma_extends_parent (i:rid{i =!= root}) :Lemma (extends i (parent i)) [SMTPat (parent i)] val lemma_extends_not_root (i:rid) (j:rid{extends j i}) :Lemma (j =!= root) [SMTPat (extends j i)] val lemma_extends_only_parent (i:rid) (j:rid{extends j i}) :Lemma (i == parent j) [SMTPat (extends j i)] val mod_set (s:Set.set rid) :(Set.set rid) assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)} Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x) let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) = Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\ Set.subset (Map.domain m0) (Map.domain m1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Heap.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.HyperHeap.fsti" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Heap", "short_module": null }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "Map" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "Set" }, { "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
s: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> m0: FStar.Monotonic.HyperHeap.hmap -> m1: FStar.Monotonic.HyperHeap.hmap -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Set.set", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperHeap.hmap", "Prims.l_and", "FStar.Map.equal", "FStar.Monotonic.Heap.heap", "FStar.Map.concat", "FStar.Map.restrict", "FStar.Set.complement", "FStar.Set.subset", "FStar.Map.domain", "Prims.logical" ]
[]
false
false
false
true
true
let modifies_just (s: Set.set rid) (m0 m1: hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement s) m0)) /\ Set.subset (Map.domain m0) (Map.domain m1)
false
FStar.Monotonic.HyperHeap.fsti
FStar.Monotonic.HyperHeap.modifies
val modifies : s: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> m0: FStar.Monotonic.HyperHeap.hmap -> m1: FStar.Monotonic.HyperHeap.hmap -> Prims.logical
let modifies (s:Set.set rid) (m0:hmap) (m1:hmap) = Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\ Set.subset (Map.domain m0) (Map.domain m1)
{ "file_name": "ulib/FStar.Monotonic.HyperHeap.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 44, "end_line": 112, "start_col": 0, "start_line": 110 }
(* Copyright 2008-2014 Nikhil Swamy, Aseem Rastogi, and Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Monotonic.HyperHeap module Set = FStar.Set module Map = FStar.Map open FStar.Monotonic.Heap open FStar.Ghost (* * This module provides the map view of the memory and associated functions and lemmas * The intention of this module is for it to be included in HyperStack * Clients should not open/know about HyperHeap, they should work only with HyperStack *) (* * AR: mark it must_erase_for_extraction temporarily until CMI comes in *) [@@must_erase_for_extraction] val rid :eqtype val reveal (r:rid) :GTot (list (int * int)) let rid_last_component (r:rid) :GTot int = let open FStar.List.Tot in let r = reveal r in if length r = 0 then 0 else snd (hd r) val color (x:rid) :GTot int val rid_freeable (x:rid) : GTot bool type hmap = Map.t rid heap val root : r:rid{color r == 0 /\ not (rid_freeable r)} val root_last_component (_:unit) : Lemma (rid_last_component root == 0) let root_has_color_zero (u:unit) :Lemma (color root == 0) = () val root_is_not_freeable (_:unit) : Lemma (not (rid_freeable root)) private val rid_length (r:rid) :GTot nat private val rid_tail (r:rid{rid_length r > 0}) :rid val includes (r1:rid) (r2:rid) :GTot bool (decreases (reveal r2)) let disjoint (i:rid) (j:rid) :GTot bool = not (includes i j) && not (includes j i) val lemma_disjoint_includes (i:rid) (j:rid) (k:rid) :Lemma (requires (disjoint i j /\ includes j k)) (ensures (disjoint i k)) (decreases (List.Tot.length (reveal k))) [SMTPat (disjoint i j); SMTPat (includes j k)] val extends (i:rid) (j:rid) :GTot bool val parent (r:rid{r =!= root}) :rid val lemma_includes_refl (i:rid) :Lemma (includes i i) [SMTPat (includes i i)] val lemma_extends_includes (i:rid) (j:rid) :Lemma (requires (extends j i)) (ensures (includes i j /\ not(includes j i))) [SMTPat (extends j i)] val lemma_includes_anti_symmetric (i:rid) (j:rid) :Lemma (requires (includes i j /\ i =!= j)) (ensures (not (includes j i))) [SMTPat (includes i j)] val lemma_extends_disjoint (i:rid) (j:rid) (k:rid) :Lemma (requires (extends j i /\ extends k i /\ j =!= k)) (ensures (disjoint j k)) val lemma_extends_parent (i:rid{i =!= root}) :Lemma (extends i (parent i)) [SMTPat (parent i)] val lemma_extends_not_root (i:rid) (j:rid{extends j i}) :Lemma (j =!= root) [SMTPat (extends j i)] val lemma_extends_only_parent (i:rid) (j:rid{extends j i}) :Lemma (i == parent j) [SMTPat (extends j i)] val mod_set (s:Set.set rid) :(Set.set rid) assume Mod_set_def: forall (x:rid) (s:Set.set rid). {:pattern Set.mem x (mod_set s)} Set.mem x (mod_set s) <==> (exists (y:rid). Set.mem y s /\ includes y x)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Set.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Monotonic.Heap.fsti.checked", "FStar.Map.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "FStar.Monotonic.HyperHeap.fsti" }
[ { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Monotonic.Heap", "short_module": null }, { "abbrev": true, "full_module": "FStar.Map", "short_module": "Map" }, { "abbrev": true, "full_module": "FStar.Set", "short_module": "Set" }, { "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
s: FStar.Set.set FStar.Monotonic.HyperHeap.rid -> m0: FStar.Monotonic.HyperHeap.hmap -> m1: FStar.Monotonic.HyperHeap.hmap -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "FStar.Set.set", "FStar.Monotonic.HyperHeap.rid", "FStar.Monotonic.HyperHeap.hmap", "Prims.l_and", "FStar.Map.equal", "FStar.Monotonic.Heap.heap", "FStar.Map.concat", "FStar.Map.restrict", "FStar.Set.complement", "FStar.Monotonic.HyperHeap.mod_set", "FStar.Set.subset", "FStar.Map.domain", "Prims.logical" ]
[]
false
false
false
true
true
let modifies (s: Set.set rid) (m0 m1: hmap) =
Map.equal m1 (Map.concat m1 (Map.restrict (Set.complement (mod_set s)) m0)) /\ Set.subset (Map.domain m0) (Map.domain m1)
false