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
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if5
val test_if5 (b: bool) : SteelT ref emp (fun r -> ptr r)
val test_if5 (b: bool) : SteelT ref emp (fun r -> ptr r)
let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r) = if b then alloc 0 else alloc 1
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 125, "start_col": 0, "start_line": 124 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop () let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ())
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> Steel.Effect.SteelT SteelFramingTestSuite.ref
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.alloc", "SteelFramingTestSuite.ref", "Steel.Effect.Common.emp", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if5 (b: bool) : SteelT ref emp (fun r -> ptr r) =
if b then alloc 0 else alloc 1
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_top_index_u64
val bn_get_top_index_u64 (len: _) : bn_get_top_index_st U64 len
val bn_get_top_index_u64 (len: _) : bn_get_top_index_st U64 len
let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 88, "end_line": 137, "start_col": 0, "start_line": 137 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Hacl.Bignum.Lib.bn_get_top_index_st Lib.IntTypes.U64 len
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Lib.mk_bn_get_top_index", "Lib.IntTypes.U64", "Hacl.Bignum.Lib.bn_get_top_index_st" ]
[]
false
false
false
false
false
let bn_get_top_index_u64 len : bn_get_top_index_st U64 len =
mk_bn_get_top_index #U64 len
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if1
val test_if1 (b: bool) : SteelT unit emp (fun _ -> emp)
val test_if1 (b: bool) : SteelT unit emp (fun _ -> emp)
let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop ()
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 113, "start_col": 0, "start_line": 112 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "Steel.Effect.Atomic.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if1 (b: bool) : SteelT unit emp (fun _ -> emp) =
if b then noop () else noop ()
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_bits_u32
val bn_get_bits_u32:bn_get_bits_st U32
val bn_get_bits_u32:bn_get_bits_st U32
let bn_get_bits_u32: bn_get_bits_st U32 = mk_bn_get_bits
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 193, "start_col": 0, "start_line": 193 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64 inline_for_extraction noextract val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) let bn_get_bits_limb #t len n ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1 inline_for_extraction noextract let bn_get_bits_st (t:limb_t) = len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l)) inline_for_extraction noextract val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t let mk_bn_get_bits #t len b i l = [@inline_let] let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in bn_get_bits_limb len b i &. mask_l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Bignum.Lib.bn_get_bits_st Lib.IntTypes.U32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Lib.mk_bn_get_bits", "Lib.IntTypes.U32" ]
[]
false
false
false
true
false
let bn_get_bits_u32:bn_get_bits_st U32 =
mk_bn_get_bits
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.size32_maybe_enum_key_gen'
val size32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: size32 (serialize_enum_key p s e)) : Tot (size32 (serialize_maybe_enum_key p s e))
val size32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: size32 (serialize_enum_key p s e)) : Tot (size32 (serialize_maybe_enum_key p s e))
let size32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: size32 (serialize_enum_key p s e)) : Tot (size32 (serialize_maybe_enum_key p s e)) = fun (input: maybe_enum_key e) -> (( [@inline_let] let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@inline_let] let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r ) <: (r: U32.t { size32_postcond (serialize_maybe_enum_key p s e) input r } ))
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 81, "end_line": 223, "start_col": 0, "start_line": 205 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32 inline_for_extraction let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) inline_for_extraction let parse32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_enum_key p e)) = parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) inline_for_extraction let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } )) inline_for_extraction let serialize32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_enum_key p s e)) = serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (size32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } )) inline_for_extraction let size32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (size32 (serialize_enum_key p s e)) = size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e)) = fun (input: maybe_enum_key e) -> (( [@inline_let] let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@inline_let] let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r ) <: (r: bytes32 { serializer32_correct (serialize_maybe_enum_key p s e) input r } )) inline_for_extraction let serialize32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k == k' } ) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (u3: unit { s' == serialize_maybe_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = serialize32_maybe_enum_key_gen' s32 e (serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f) inline_for_extraction let serialize32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_maybe_enum_key p s e)) = serialize32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s32: LowParse.SLow.Base.size32 s -> e: LowParse.Spec.Enum.enum key repr -> f: LowParse.SLow.Base.size32 (LowParse.Spec.Enum.serialize_enum_key p s e) -> LowParse.SLow.Base.size32 (LowParse.Spec.Enum.serialize_maybe_enum_key p s e)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "LowParse.Spec.Enum.enum", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key", "LowParse.Spec.Enum.maybe_enum_key", "Prims.unit", "LowParse.Spec.Enum.serialize_enum_key_eq", "LowParse.Spec.Enum.unknown_enum_repr", "FStar.UInt32.t", "LowParse.SLow.Base.size32_postcond", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key_eq" ]
[]
false
false
false
false
false
let size32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: size32 (serialize_enum_key p s e)) : Tot (size32 (serialize_maybe_enum_key p s e)) =
fun (input: maybe_enum_key e) -> (([@@ inline_let ]let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@@ inline_let ]let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r) <: (r: U32.t{size32_postcond (serialize_maybe_enum_key p s e) input r}))
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_bits_u64
val bn_get_bits_u64:bn_get_bits_st U64
val bn_get_bits_u64:bn_get_bits_st U64
let bn_get_bits_u64: bn_get_bits_st U64 = mk_bn_get_bits
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 56, "end_line": 195, "start_col": 0, "start_line": 195 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64 inline_for_extraction noextract val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) let bn_get_bits_limb #t len n ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1 inline_for_extraction noextract let bn_get_bits_st (t:limb_t) = len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l)) inline_for_extraction noextract val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t let mk_bn_get_bits #t len b i l = [@inline_let] let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in bn_get_bits_limb len b i &. mask_l [@CInline] let bn_get_bits_u32: bn_get_bits_st U32 = mk_bn_get_bits
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Bignum.Lib.bn_get_bits_st Lib.IntTypes.U64
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Lib.mk_bn_get_bits", "Lib.IntTypes.U64" ]
[]
false
false
false
true
false
let bn_get_bits_u64:bn_get_bits_st U64 =
mk_bn_get_bits
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if2
val test_if2 (b: bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r)
val test_if2 (b: bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r)
let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 116, "start_col": 0, "start_line": 115 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop ()
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> r: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.ref", "SteelFramingTestSuite.write", "Prims.unit", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if2 (b: bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) =
if b then write r 0 else write r 1
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test3
val test3 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3))
val test3 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3))
let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 66, "start_col": 0, "start_line": 61 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.int
Steel.Effect.SteelT
[]
[]
[ "SteelFramingTestSuite.ref", "Prims.int", "SteelFramingTestSuite.read", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test3 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3)) =
let x = read b3 in x
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.serialize32_maybe_enum_key_gen'
val serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e))
val serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e))
let serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e)) = fun (input: maybe_enum_key e) -> (( [@inline_let] let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@inline_let] let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r ) <: (r: bytes32 { serializer32_correct (serialize_maybe_enum_key p s e) input r } ))
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 88, "end_line": 169, "start_col": 0, "start_line": 151 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32 inline_for_extraction let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) inline_for_extraction let parse32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_enum_key p e)) = parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) inline_for_extraction let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } )) inline_for_extraction let serialize32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_enum_key p s e)) = serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (size32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } )) inline_for_extraction let size32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (size32 (serialize_enum_key p s e)) = size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s32: LowParse.SLow.Base.serializer32 s -> e: LowParse.Spec.Enum.enum key repr -> f: LowParse.SLow.Base.serializer32 (LowParse.Spec.Enum.serialize_enum_key p s e) -> LowParse.SLow.Base.serializer32 (LowParse.Spec.Enum.serialize_maybe_enum_key p s e)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.serializer32", "LowParse.Spec.Enum.enum", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key", "LowParse.Spec.Enum.maybe_enum_key", "Prims.unit", "LowParse.Spec.Enum.serialize_enum_key_eq", "LowParse.Spec.Enum.unknown_enum_repr", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key_eq" ]
[]
false
false
false
false
false
let serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e)) =
fun (input: maybe_enum_key e) -> (([@@ inline_let ]let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@@ inline_let ]let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r) <: (r: bytes32{serializer32_correct (serialize_maybe_enum_key p s e) input r}))
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.is_permutation
val is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) : prop
val is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) : prop
let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i))
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 39, "end_line": 31, "start_col": 0, "start_line": 26 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> f: FStar.Sequence.Permutation.index_fun s0 -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "FStar.Sequence.Base.seq", "FStar.Sequence.Permutation.index_fun", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Sequence.Base.length", "Prims.l_Forall", "FStar.Sequence.Permutation.nat_at_most", "Prims.l_imp", "Prims.b2t", "Prims.op_disEquality", "Prims.op_LessThan", "FStar.Sequence.Base.index", "Prims.prop" ]
[]
false
false
false
false
true
let is_permutation (#a: Type) (s0 s1: seq a) (f: index_fun s0) =
S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test4
val test4 (b1 b2 b3: ref) : SteelT unit (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3))
val test4 (b1 b2 b3: ref) : SteelT unit (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3))
let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 12, "end_line": 73, "start_col": 0, "start_line": 68 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "SteelFramingTestSuite.ref", "SteelFramingTestSuite.write", "Prims.unit", "Prims.int", "SteelFramingTestSuite.read", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test4 (b1 b2 b3: ref) : SteelT unit (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3)) =
let x = read b3 in write b2 x
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.serialize32_enum_key_gen
val serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (u3: unit{s' == serialize_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (serializer32 s')
val serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (u3: unit{s' == serialize_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (serializer32 s')
let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } ))
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 97, "end_line": 101, "start_col": 0, "start_line": 81 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32 inline_for_extraction let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) inline_for_extraction let parse32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_enum_key p e)) = parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s32: LowParse.SLow.Base.serializer32 s -> e: LowParse.Spec.Enum.enum key repr -> k': LowParse.Spec.Base.parser_kind -> t': Type0 -> p': LowParse.Spec.Base.parser k' t' -> s': LowParse.Spec.Base.serializer p' -> u1: Prims.unit{k' == LowParse.Spec.Combinators.parse_filter_kind k} -> u15: Prims.unit{t' == LowParse.Spec.Enum.enum_key e} -> u2: Prims.unit{p' == LowParse.Spec.Enum.parse_enum_key p e} -> u3: Prims.unit{s' == LowParse.Spec.Enum.serialize_enum_key p s e} -> f: LowParse.Spec.Enum.enum_repr_of_key'_t e -> LowParse.SLow.Base.serializer32 s'
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.serializer32", "LowParse.Spec.Enum.enum", "Prims.unit", "Prims.eq2", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key", "LowParse.Spec.Enum.enum_repr_of_key'_t", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.Enum.serialize_enum_key_eq" ]
[]
false
false
false
false
false
let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (u3: unit{s' == serialize_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') =
fun (input: enum_key e) -> ([@@ inline_let ]let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32{serializer32_correct (serialize_enum_key p s e) input r}))
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.reveal_is_permutation
val reveal_is_permutation (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> (* lengths of the sequences are the same *) S.length s0 == S.length s1 /\ (* f is injective *) (forall x y. {:pattern f x; f y} x <> y ==> f x <> f y) /\ (* and f relates equal items in s0 and s1 *) (forall (i:nat{i < S.length s0}).{:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)))
val reveal_is_permutation (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> (* lengths of the sequences are the same *) S.length s0 == S.length s1 /\ (* f is injective *) (forall x y. {:pattern f x; f y} x <> y ==> f x <> f y) /\ (* and f relates equal items in s0 and s1 *) (forall (i:nat{i < S.length s0}).{:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)))
let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 61, "end_line": 34, "start_col": 0, "start_line": 33 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> f: FStar.Sequence.Permutation.index_fun s0 -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Permutation.is_permutation s0 s1 f <==> FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\ (forall (x: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0)) (y: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0)). {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i: Prims.nat{i < FStar.Sequence.Base.length s0}). {:pattern FStar.Sequence.Base.index s1 (f i)} FStar.Sequence.Base.index s0 i == FStar.Sequence.Base.index s1 (f i)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Sequence.Base.seq", "FStar.Sequence.Permutation.index_fun", "FStar.Pervasives.reveal_opaque", "Prims.prop", "FStar.Sequence.Permutation.is_permutation", "Prims.unit" ]
[]
true
false
true
false
false
let reveal_is_permutation #a (s0: seq a) (s1: seq a) (f: index_fun s0) =
reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.reveal_is_permutation_nopats
val reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i)))
val reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i)))
let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 45, "start_col": 0, "start_line": 36 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> f: FStar.Sequence.Permutation.index_fun s0 -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Permutation.is_permutation s0 s1 f <==> FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\ (forall (x: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0)) (y: FStar.Sequence.Permutation.nat_at_most (FStar.Sequence.Base.length s0)). x <> y ==> f x <> f y) /\ (forall (i: Prims.nat{i < FStar.Sequence.Base.length s0}). FStar.Sequence.Base.index s0 i == FStar.Sequence.Base.index s1 (f i)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Sequence.Base.seq", "FStar.Sequence.Permutation.index_fun", "FStar.Sequence.Permutation.reveal_is_permutation", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_iff", "FStar.Sequence.Permutation.is_permutation", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Sequence.Base.length", "Prims.l_Forall", "FStar.Sequence.Permutation.nat_at_most", "Prims.l_imp", "Prims.b2t", "Prims.op_disEquality", "Prims.op_LessThan", "FStar.Sequence.Base.index", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let reveal_is_permutation_nopats (#a: Type) (s0 s1: seq a) (f: index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i: nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) =
reveal_is_permutation s0 s1 f
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.size32_enum_key_gen
val size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (u3: unit{s' == serialize_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (size32 s')
val size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (u3: unit{s' == serialize_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (size32 s')
let size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (size32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } ))
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 93, "end_line": 136, "start_col": 0, "start_line": 116 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32 inline_for_extraction let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) inline_for_extraction let parse32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_enum_key p e)) = parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) inline_for_extraction let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } )) inline_for_extraction let serialize32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_enum_key p s e)) = serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s32: LowParse.SLow.Base.size32 s -> e: LowParse.Spec.Enum.enum key repr -> k': LowParse.Spec.Base.parser_kind -> t': Type0 -> p': LowParse.Spec.Base.parser k' t' -> s': LowParse.Spec.Base.serializer p' -> u1: Prims.unit{k' == LowParse.Spec.Combinators.parse_filter_kind k} -> u15: Prims.unit{t' == LowParse.Spec.Enum.enum_key e} -> u2: Prims.unit{p' == LowParse.Spec.Enum.parse_enum_key p e} -> u3: Prims.unit{s' == LowParse.Spec.Enum.serialize_enum_key p s e} -> f: LowParse.Spec.Enum.enum_repr_of_key'_t e -> LowParse.SLow.Base.size32 s'
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "LowParse.Spec.Enum.enum", "Prims.unit", "Prims.eq2", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key", "LowParse.Spec.Enum.enum_repr_of_key'_t", "FStar.UInt32.t", "LowParse.SLow.Base.size32_postcond", "LowParse.Spec.Enum.serialize_enum_key_eq" ]
[]
false
false
false
false
false
let size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (u3: unit{s' == serialize_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (size32 s') =
fun (input: enum_key e) -> ([@@ inline_let ]let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: UInt32.t{size32_postcond (serialize_enum_key p s e) input r}))
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.parse32_enum_key_gen
val parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p')
val parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p')
let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } )))
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 96, "end_line": 67, "start_col": 0, "start_line": 41 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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: LowParse.Spec.Base.parser k repr -> e: LowParse.Spec.Enum.enum key repr -> k': LowParse.Spec.Base.parser_kind -> t': Type0 -> p': LowParse.Spec.Base.parser k' t' -> u1: Prims.unit{k' == LowParse.Spec.Combinators.parse_filter_kind k} -> u15: Prims.unit{t' == LowParse.Spec.Enum.enum_key e} -> u2: Prims.unit{p' == LowParse.Spec.Enum.parse_enum_key p e} -> pe: LowParse.SLow.Base.parser32 (LowParse.Spec.Enum.parse_maybe_enum_key p e) -> LowParse.SLow.Base.parser32 p'
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Enum.enum", "Prims.unit", "Prims.eq2", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.SLow.Base.parser32", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.SLow.Base.bytes32", "FStar.UInt32.t", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.option", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.Enum.parse_maybe_enum_key_eq", "FStar.Bytes.reveal", "LowParse.Spec.Enum.parse_enum_key_eq" ]
[]
false
false
false
false
false
let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (u1: unit{k' == parse_filter_kind k}) (u15: unit{t' == enum_key e}) (u2: unit{p' == parse_enum_key p e}) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') =
(fun (input: bytes32) -> (([@@ inline_let ]let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> (match k with | Known k' -> Some (k', consumed) | _ -> None) | _ -> None) <: (res: option (enum_key e * U32.t) {parser32_correct (parse_enum_key p e) input res})))
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_bits_st
val bn_get_bits_st : t: Hacl.Bignum.Definitions.limb_t -> Type0
let bn_get_bits_st (t:limb_t) = len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l))
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 182, "start_col": 0, "start_line": 174 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64 inline_for_extraction noextract val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) let bn_get_bits_limb #t len n ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Prims.op_Division", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Lib.Buffer.live", "Lib.Buffer.MUT", "Prims.eq2", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Lib.bn_get_bits", "Lib.Buffer.as_seq" ]
[]
false
false
false
true
true
let bn_get_bits_st (t: limb_t) =
len: size_t -> b: lbignum t len -> i: size_t -> l: size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l))
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test2
val test2 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b3) `star` (ptr b2)) `star` (ptr b1))
val test2 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b3) `star` (ptr b2)) `star` (ptr b1))
let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 59, "start_col": 0, "start_line": 54 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.int
Steel.Effect.SteelT
[]
[]
[ "SteelFramingTestSuite.ref", "Prims.int", "SteelFramingTestSuite.read", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test2 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b3) `star` (ptr b2)) `star` (ptr b1)) =
let x = read b1 in x
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.size32_maybe_enum_key_gen
val size32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k == k'}) (u15: unit{t' == maybe_enum_key e}) (u2: unit{p' == parse_maybe_enum_key p e}) (u3: unit{s' == serialize_maybe_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (size32 s')
val size32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k == k'}) (u15: unit{t' == maybe_enum_key e}) (u2: unit{p' == parse_maybe_enum_key p e}) (u3: unit{s' == serialize_maybe_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (size32 s')
let size32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k == k' } ) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (u3: unit { s' == serialize_maybe_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (size32 s') = size32_maybe_enum_key_gen' s32 e (size32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f)
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 78, "end_line": 244, "start_col": 0, "start_line": 226 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32 inline_for_extraction let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) inline_for_extraction let parse32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_enum_key p e)) = parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) inline_for_extraction let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } )) inline_for_extraction let serialize32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_enum_key p s e)) = serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (size32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } )) inline_for_extraction let size32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (size32 (serialize_enum_key p s e)) = size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e)) = fun (input: maybe_enum_key e) -> (( [@inline_let] let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@inline_let] let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r ) <: (r: bytes32 { serializer32_correct (serialize_maybe_enum_key p s e) input r } )) inline_for_extraction let serialize32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k == k' } ) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (u3: unit { s' == serialize_maybe_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = serialize32_maybe_enum_key_gen' s32 e (serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f) inline_for_extraction let serialize32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_maybe_enum_key p s e)) = serialize32_maybe_enum_key_gen s32 e _ _ _ (serialize_maybe_enum_key p s e) () () () () f inline_for_extraction let size32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: size32 (serialize_enum_key p s e)) : Tot (size32 (serialize_maybe_enum_key p s e)) = fun (input: maybe_enum_key e) -> (( [@inline_let] let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@inline_let] let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r ) <: (r: U32.t { size32_postcond (serialize_maybe_enum_key p s e) input r } ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s32: LowParse.SLow.Base.size32 s -> e: LowParse.Spec.Enum.enum key repr -> k': LowParse.Spec.Base.parser_kind -> t': Type0 -> p': LowParse.Spec.Base.parser k' t' -> s': LowParse.Spec.Base.serializer p' -> u1: Prims.unit{k == k'} -> u15: Prims.unit{t' == LowParse.Spec.Enum.maybe_enum_key e} -> u2: Prims.unit{p' == LowParse.Spec.Enum.parse_maybe_enum_key p e} -> u3: Prims.unit{s' == LowParse.Spec.Enum.serialize_maybe_enum_key p s e} -> f: LowParse.Spec.Enum.enum_repr_of_key'_t e -> LowParse.SLow.Base.size32 s'
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "LowParse.Spec.Enum.enum", "Prims.unit", "Prims.eq2", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key", "LowParse.Spec.Enum.enum_repr_of_key'_t", "LowParse.SLow.Enum.size32_maybe_enum_key_gen'", "LowParse.SLow.Enum.size32_enum_key_gen", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key" ]
[]
false
false
false
false
false
let size32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k == k'}) (u15: unit{t' == maybe_enum_key e}) (u2: unit{p' == parse_maybe_enum_key p e}) (u3: unit{s' == serialize_maybe_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (size32 s') =
size32_maybe_enum_key_gen' s32 e (size32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f)
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test0
val test0 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b1) `star` (ptr b2)) `star` (ptr b3))
val test0 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b1) `star` (ptr b2)) `star` (ptr b3))
let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 45, "start_col": 0, "start_line": 40 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.int
Steel.Effect.SteelT
[]
[]
[ "SteelFramingTestSuite.ref", "Prims.int", "SteelFramingTestSuite.read", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test0 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b1) `star` (ptr b2)) `star` (ptr b3)) =
let x = read b1 in x
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.split3_index
val split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures (let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1)))
val split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures (let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1)))
let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else ()
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 61, "start_col": 0, "start_line": 49 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> x: a -> s1: FStar.Sequence.Base.seq a -> j: Prims.nat -> FStar.Pervasives.Lemma (requires j < FStar.Sequence.Base.length (FStar.Sequence.Base.append s0 s1)) (ensures (let s = FStar.Sequence.Base.append s0 (FStar.Sequence.Util.cons x s1) in let s' = FStar.Sequence.Base.append s0 s1 in let n = FStar.Sequence.Base.length s0 in (match j < n with | true -> FStar.Sequence.Base.index s' j == FStar.Sequence.Base.index s j | _ -> FStar.Sequence.Base.index s' j == FStar.Sequence.Base.index s (j + 1)) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.Sequence.Base.seq", "Prims.nat", "Prims.op_LessThan", "Prims.bool", "Prims.unit", "FStar.Sequence.Base.length", "FStar.Sequence.Base.append", "Prims.b2t", "Prims.squash", "Prims.eq2", "FStar.Sequence.Base.index", "Prims.op_Addition", "FStar.Sequence.Util.cons", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let split3_index (#a: eqtype) (s0: seq a) (x: a) (s1: seq a) (j: nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures (let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1))) =
let n = S.length (S.append s0 s1) in if j < n then ()
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_top_index_st
val bn_get_top_index_st : t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Type0
let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b))
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 102, "start_col": 0, "start_line": 97 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: Hacl.Bignum.Definitions.limb_t -> len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "Lib.Buffer.live", "Lib.Buffer.MUT", "Prims.l_and", "Lib.Buffer.modifies0", "Prims.eq2", "Prims.int", "Prims.l_or", "Lib.IntTypes.range", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThanOrEqual", "Lib.IntTypes.max_size_t", "Lib.IntTypes.SEC", "Hacl.Spec.Bignum.Lib.bn_get_top_index", "Lib.Buffer.as_seq" ]
[]
false
false
false
false
true
let bn_get_top_index_st (t: limb_t) (len: size_t{0 < v len}) =
b: lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b))
false
Hacl.Streaming.Poly1305_32.fst
Hacl.Streaming.Poly1305_32.mac
val mac: poly1305_mac_st M32
val mac: poly1305_mac_st M32
let mac = poly1305_poly1305_mac_higher #M32 True poly1305_finish poly1305_update poly1305_init
{ "file_name": "code/streaming/Hacl.Streaming.Poly1305_32.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 94, "end_line": 9, "start_col": 0, "start_line": 9 }
module Hacl.Streaming.Poly1305_32 open Hacl.Meta.Poly1305 open Hacl.Poly1305_32 friend Hacl.Meta.Poly1305
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Hacl.Poly1305_32.fsti.checked", "Hacl.Meta.Poly1305.fst.checked", "Hacl.Meta.Poly1305.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Streaming.Poly1305_32.fst" }
[ { "abbrev": false, "full_module": "Hacl.Poly1305_32", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Meta.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming.Poly1305", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Poly1305.Fields", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Streaming.Interface", "short_module": "I" }, { "abbrev": true, "full_module": "Hacl.Streaming.Functor", "short_module": "F" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Streaming", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Impl.Poly1305.poly1305_mac_st Hacl.Impl.Poly1305.Fields.M32
Prims.Tot
[ "total" ]
[]
[ "Hacl.Meta.Poly1305.poly1305_poly1305_mac_higher", "Hacl.Impl.Poly1305.Fields.M32", "Prims.l_True", "Hacl.Poly1305_32.poly1305_finish", "Hacl.Poly1305_32.poly1305_update", "Hacl.Poly1305_32.poly1305_init" ]
[]
false
false
false
true
false
let mac =
poly1305_poly1305_mac_higher #M32 True poly1305_finish poly1305_update poly1305_init
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.count_singleton_one
val count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1)
val count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1)
let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a)
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 84, "start_col": 0, "start_line": 82 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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 -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Util.count x (FStar.Sequence.Base.singleton x) == 1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.Pervasives.reveal_opaque", "FStar.Sequence.Base.seq", "Prims.nat", "FStar.Sequence.Util.count", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.int", "FStar.Sequence.Base.singleton", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let count_singleton_one (#a: eqtype) (x: a) : Lemma (count x (singleton x) == 1) =
reveal_opaque (`%count) (count #a)
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.count_singleton_zero
val count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0)
val count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0)
let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a)
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 87, "start_col": 0, "start_line": 85 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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 -> y: a -> FStar.Pervasives.Lemma (ensures ~(x == y) ==> FStar.Sequence.Util.count x (FStar.Sequence.Base.singleton y) == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.Pervasives.reveal_opaque", "FStar.Sequence.Base.seq", "Prims.nat", "FStar.Sequence.Util.count", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.l_imp", "Prims.l_not", "Prims.eq2", "Prims.int", "FStar.Sequence.Base.singleton", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let count_singleton_zero (#a: eqtype) (x y: a) : Lemma (x =!= y ==> count x (singleton y) == 0) =
reveal_opaque (`%count) (count #a)
false
Hacl.HPKE.Curve64_CP256_SHA256.fsti
Hacl.HPKE.Curve64_CP256_SHA256.vale_p
val vale_p : Prims.logical
let vale_p = Vale.X64.CPU_Features_s.(adx_enabled /\ bmi2_enabled)
{ "file_name": "code/hpke/Hacl.HPKE.Curve64_CP256_SHA256.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 13, "start_col": 0, "start_line": 13 }
module Hacl.HPKE.Curve64_CP256_SHA256 open Hacl.Impl.HPKE module S = Spec.Agile.HPKE module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash noextract unfold let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Hacl.Impl.HPKE.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Curve64_CP256_SHA256.fsti" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Prims.l_and", "Prims.b2t", "Vale.X64.CPU_Features_s.adx_enabled", "Vale.X64.CPU_Features_s.bmi2_enabled" ]
[]
false
false
false
true
true
let vale_p =
let open Vale.X64.CPU_Features_s in adx_enabled /\ bmi2_enabled
false
LowParse.SLow.Enum.fst
LowParse.SLow.Enum.serialize32_maybe_enum_key_gen
val serialize32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k == k'}) (u15: unit{t' == maybe_enum_key e}) (u2: unit{p' == parse_maybe_enum_key p e}) (u3: unit{s' == serialize_maybe_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (serializer32 s')
val serialize32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k == k'}) (u15: unit{t' == maybe_enum_key e}) (u2: unit{p' == parse_maybe_enum_key p e}) (u3: unit{s' == serialize_maybe_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (serializer32 s')
let serialize32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k == k' } ) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (u3: unit { s' == serialize_maybe_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = serialize32_maybe_enum_key_gen' s32 e (serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f)
{ "file_name": "src/lowparse/LowParse.SLow.Enum.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 83, "end_line": 190, "start_col": 0, "start_line": 172 }
module LowParse.SLow.Enum include LowParse.Spec.Enum include LowParse.SLow.Combinators module L = FStar.List.Tot module U32 = FStar.UInt32 (* Parser for enums *) inline_for_extraction let parse32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == k }) (u15: unit { t' == maybe_enum_key e } ) (u2: unit { p' == parse_maybe_enum_key p e } ) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 p') = parse32_synth p (maybe_enum_key_of_repr e) f p32 () inline_for_extraction let parse32_maybe_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_maybe_enum_key p e)) = parse32_maybe_enum_key_gen p32 e _ _ (parse_maybe_enum_key p e) () () () f module B32 = LowParse.Bytes32 inline_for_extraction let parse32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (p: parser k repr) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (pe: parser32 (parse_maybe_enum_key p e)) : Tot (parser32 p') = (fun (input: bytes32) -> (( [@inline_let] let _ = parse_enum_key_eq p e (B32.reveal input); parse_maybe_enum_key_eq p e (B32.reveal input) in match pe input with | Some (k, consumed) -> begin match k with | Known k' -> Some (k', consumed) | _ -> None end | _ -> None ) <: (res: option (enum_key e * U32.t) { parser32_correct (parse_enum_key p e) input res } ))) inline_for_extraction let parse32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (p32: parser32 p) (e: enum key repr) (f: maybe_enum_key_of_repr'_t e) : Tot (parser32 (parse_enum_key p e)) = parse32_enum_key_gen p e _ _ (parse_enum_key p e) () () () (parse32_maybe_enum_key p32 e f) inline_for_extraction let serialize32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: bytes32 { serializer32_correct (serialize_enum_key p s e) input r } )) inline_for_extraction let serialize32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (serializer32 (serialize_enum_key p s e)) = serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let size32_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (k' : parser_kind) (t' : Type) (p' : parser k' t') (s' : serializer p') (u1: unit { k' == parse_filter_kind k } ) (u15: unit { t' == enum_key e } ) (u2: unit { p' == parse_enum_key p e } ) (u3: unit { s' == serialize_enum_key p s e } ) (f: enum_repr_of_key'_t e) : Tot (size32 s') = fun (input: enum_key e) -> ( [@inline_let] let _ = serialize_enum_key_eq s e input in (s32 (f input)) <: (r: UInt32.t { size32_postcond (serialize_enum_key p s e) input r } )) inline_for_extraction let size32_enum_key (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: size32 s) (e: enum key repr) (f: enum_repr_of_key'_t e) : Tot (size32 (serialize_enum_key p s e)) = size32_enum_key_gen s32 e _ _ _ (serialize_enum_key p s e) () () () () f inline_for_extraction let serialize32_maybe_enum_key_gen' (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (f: serializer32 (serialize_enum_key p s e)) : Tot (serializer32 (serialize_maybe_enum_key p s e)) = fun (input: maybe_enum_key e) -> (( [@inline_let] let _ = serialize_maybe_enum_key_eq s e input in match input with | Known k -> [@inline_let] let _ = serialize_enum_key_eq s e k in f k | Unknown r -> s32 r ) <: (r: bytes32 { serializer32_correct (serialize_maybe_enum_key p s e) input r } ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Enum.fst.checked", "LowParse.SLow.Combinators.fst.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "LowParse.SLow.Enum.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.SLow.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Enum", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s32: LowParse.SLow.Base.serializer32 s -> e: LowParse.Spec.Enum.enum key repr -> k': LowParse.Spec.Base.parser_kind -> t': Type0 -> p': LowParse.Spec.Base.parser k' t' -> s': LowParse.Spec.Base.serializer p' -> u1: Prims.unit{k == k'} -> u15: Prims.unit{t' == LowParse.Spec.Enum.maybe_enum_key e} -> u2: Prims.unit{p' == LowParse.Spec.Enum.parse_maybe_enum_key p e} -> u3: Prims.unit{s' == LowParse.Spec.Enum.serialize_maybe_enum_key p s e} -> f: LowParse.Spec.Enum.enum_repr_of_key'_t e -> LowParse.SLow.Base.serializer32 s'
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.eqtype", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.serializer32", "LowParse.Spec.Enum.enum", "Prims.unit", "Prims.eq2", "LowParse.Spec.Enum.maybe_enum_key", "LowParse.Spec.Enum.parse_maybe_enum_key", "LowParse.Spec.Enum.serialize_maybe_enum_key", "LowParse.Spec.Enum.enum_repr_of_key'_t", "LowParse.SLow.Enum.serialize32_maybe_enum_key_gen'", "LowParse.SLow.Enum.serialize32_enum_key_gen", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Enum.enum_key", "LowParse.Spec.Enum.parse_enum_key", "LowParse.Spec.Enum.serialize_enum_key" ]
[]
false
false
false
false
false
let serialize32_maybe_enum_key_gen (#k: parser_kind) (#key #repr: eqtype) (#p: parser k repr) (#s: serializer p) (s32: serializer32 s) (e: enum key repr) (k': parser_kind) (t': Type) (p': parser k' t') (s': serializer p') (u1: unit{k == k'}) (u15: unit{t' == maybe_enum_key e}) (u2: unit{p' == parse_maybe_enum_key p e}) (u3: unit{s' == serialize_maybe_enum_key p s e}) (f: enum_repr_of_key'_t e) : Tot (serializer32 s') =
serialize32_maybe_enum_key_gen' s32 e (serialize32_enum_key_gen s32 e _ _ _ (serialize_enum_key _ s e) () () () () f)
false
Hacl.Spec.Bignum.fst
Hacl.Spec.Bignum.bn_sub_mask_lemma
val bn_sub_mask_lemma: #t:limb_t -> #len:size_nat -> n:lbignum t len -> a:lbignum t len -> Lemma (requires bn_v a <= bn_v n) (ensures bn_v (bn_sub_mask n a) == (if bn_v a = bn_v n then 0 else bn_v a))
val bn_sub_mask_lemma: #t:limb_t -> #len:size_nat -> n:lbignum t len -> a:lbignum t len -> Lemma (requires bn_v a <= bn_v n) (ensures bn_v (bn_sub_mask n a) == (if bn_v a = bn_v n then 0 else bn_v a))
let bn_sub_mask_lemma #t #len n a = let mask = Lib.ByteSequence.seq_eq_mask n a len in assert (n == a ==> v mask == v (ones t SEC)); assert (n =!= a ==> v mask == v (zeros t SEC)); let mod_mask = map (logand mask) n in bn_mask_lemma n mask; assert (n == a ==> bn_v mod_mask == bn_v n); assert (n =!= a ==> bn_v mod_mask == 0); let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask; assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask); bn_eval_bound res len; assert (bn_v res == bn_v a - bn_v mod_mask); Classical.move_requires_2 (bn_eval_inj len) n a
{ "file_name": "code/bignum/Hacl.Spec.Bignum.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 49, "end_line": 180, "start_col": 0, "start_line": 165 }
module Hacl.Spec.Bignum module Loops = Lib.LoopCombinators #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let bn_add1 #t #aLen a b1 = Hacl.Spec.Bignum.Addition.bn_add1 a b1 let bn_add1_lemma #t #aLen a b1 = Hacl.Spec.Bignum.Addition.bn_add1_lemma a b1 let bn_sub1 #t #aLen a b1 = Hacl.Spec.Bignum.Addition.bn_sub1 a b1 let bn_sub1_lemma #t #aLen a b1 = Hacl.Spec.Bignum.Addition.bn_sub1_lemma a b1 let bn_add #t #aLen #bLen a b = Hacl.Spec.Bignum.Addition.bn_add a b let bn_add_lemma #t #aLen #bLen a b = Hacl.Spec.Bignum.Addition.bn_add_lemma a b let bn_sub #t #aLen #bLen a b = Hacl.Spec.Bignum.Addition.bn_sub a b let bn_sub_lemma #t #aLen #bLen a b = Hacl.Spec.Bignum.Addition.bn_sub_lemma a b let bn_reduce_once #t #len n c0 a = let c1, res = bn_sub a n in let c = c0 -. c1 in map2 (mask_select c) a res let bn_reduce_once_lemma #t #len n c0 res0 = let pbits = bits t in let tmp = bn_v res0 + v c0 * pow2 (pbits * len) in let c1, res1 = bn_sub res0 n in bn_sub_lemma res0 n; assert (bn_v res1 - v c1 * pow2 (pbits * len) == bn_v res0 - bn_v n); let c = c0 -. c1 in assert (bn_v res1 + (v c0 - v c1) * pow2 (pbits * len) == tmp - bn_v n); let res = map2 (mask_select c) res0 res1 in if tmp < bn_v n then begin assert (v c0 == 0); assert (v c1 == 1); assert (v c == pow2 pbits - 1); lseq_mask_select_lemma res0 res1 c; assert (bn_v res == bn_v res0); Math.Lemmas.small_mod tmp (bn_v n); assert (bn_v res == tmp % bn_v n) end else begin assert (tmp - bn_v n < bn_v n); bn_eval_bound res1 len; bn_eval_bound n len; assert (v c == 0); lseq_mask_select_lemma res0 res1 c; assert (bn_v res == bn_v res1); Math.Lemmas.modulo_addition_lemma tmp (bn_v n) (- 1); assert (bn_v res % bn_v n == tmp % bn_v n); Math.Lemmas.small_mod (bn_v res) (bn_v n) end let bn_add_mod_n #t #len n a b = let c0, res0 = bn_add a b in bn_reduce_once n c0 res0 let bn_add_mod_n_lemma #t #len n a b = let c0, res0 = bn_add a b in bn_add_lemma a b; bn_reduce_once_lemma n c0 res0 let bn_sub_mod_n #t #len n a b = let c0, res0 = bn_sub a b in let c1, res1 = bn_add res0 n in let c = uint #t 0 -. c0 in map2 (mask_select c) res1 res0 let bn_sub_mod_n_lemma #t #len n a b = let c0, res0 = bn_sub a b in bn_sub_lemma a b; assert (bn_v res0 - v c0 * pow2 (bits t * len) == bn_v a - bn_v b); let c1, res1 = bn_add res0 n in let c = uint #t 0 -. c0 in assert (v c == 0 \/ v c == v (ones t SEC)); let res = map2 (mask_select c) res1 res0 in lseq_mask_select_lemma res1 res0 c; if v c0 = 0 then begin assert (bn_v res0 == bn_v a - bn_v b); Math.Lemmas.small_mod (bn_v res0) (bn_v n); assert (bn_v res == (bn_v a - bn_v b) % bn_v n); () end else begin bn_add_lemma res0 n; assert (bn_v res1 + v c1 * pow2 (bits t * len) == bn_v res0 + bn_v n); bn_eval_bound res0 len; bn_eval_bound res1 len; bn_eval_bound n len; assert (v c0 - v c1 = 0); assert (bn_v res1 == bn_v a - bn_v b + bn_v n); assert (bn_v res1 < bn_v n); Math.Lemmas.modulo_addition_lemma (bn_v a - bn_v b) (bn_v n) 1; Math.Lemmas.small_mod (bn_v res1) (bn_v n); assert (bn_v res == (bn_v a - bn_v b) % bn_v n); () end let bn_mul1 #t #aLen a b1 = Hacl.Spec.Bignum.Multiplication.bn_mul1 a b1 let bn_mul1_lemma #t #aLen a b1 = Hacl.Spec.Bignum.Multiplication.bn_mul1_lemma a b1 let bn_mul #t #aLen #bLen a b = Hacl.Spec.Bignum.Multiplication.bn_mul a b let bn_mul_lemma #t #aLen #bLen a b = Hacl.Spec.Bignum.Multiplication.bn_mul_lemma a b let bn_karatsuba_mul #t #aLen a b = Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul a b let bn_karatsuba_mul_lemma #t #aLen a b = Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_lemma a b let bn_sqr #t #aLen a = Hacl.Spec.Bignum.Squaring.bn_sqr a let bn_sqr_lemma #t #aLen a = Hacl.Spec.Bignum.Squaring.bn_sqr_lemma a let bn_karatsuba_sqr #t #aLen a = Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr a let bn_karatsuba_sqr_lemma #t #aLen a = Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_lemma a let bn_mul1_lshift_add #t #aLen #resLen a b j acc = Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add a b j acc let bn_mul1_lshift_add_lemma #t #aLen #resLen a b j acc = Hacl.Spec.Bignum.Multiplication.bn_mul1_lshift_add_lemma a b j acc let bn_rshift #t #len b i = Hacl.Spec.Bignum.Lib.bn_div_pow2 b i let bn_rshift_lemma #t #len c i = Hacl.Spec.Bignum.Lib.bn_div_pow2_lemma c i let bn_sub_mask #t #len n a = let mask = BSeq.seq_eq_mask n a len in let mod_mask = map (logand mask) n in let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in res
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.LoopCombinators.fsti.checked", "Lib.ByteSequence.fsti.checked", "Hacl.Spec.Bignum.Squaring.fst.checked", "Hacl.Spec.Bignum.Multiplication.fst.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Spec.Bignum.Karatsuba.fst.checked", "Hacl.Spec.Bignum.Convert.fst.checked", "Hacl.Spec.Bignum.Comparison.fst.checked", "Hacl.Spec.Bignum.Addition.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "Hacl.Spec.Bignum.fst" }
[ { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec.Bignum.Base", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Spec", "short_module": null }, { "abbrev": false, "full_module": "Hacl.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": 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
n: Hacl.Spec.Bignum.Definitions.lbignum t len -> a: Hacl.Spec.Bignum.Definitions.lbignum t len -> FStar.Pervasives.Lemma (requires Hacl.Spec.Bignum.Definitions.bn_v a <= Hacl.Spec.Bignum.Definitions.bn_v n) (ensures Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Bignum.bn_sub_mask n a) == (match Hacl.Spec.Bignum.Definitions.bn_v a = Hacl.Spec.Bignum.Definitions.bn_v n with | true -> 0 | _ -> Hacl.Spec.Bignum.Definitions.bn_v a))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Hacl.Spec.Bignum.Definitions.limb_t", "Lib.IntTypes.size_nat", "Hacl.Spec.Bignum.Definitions.lbignum", "Hacl.Spec.Bignum.Base.carry", "FStar.Classical.move_requires_2", "Prims.eq2", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Lib.Sequence.equal", "Hacl.Spec.Bignum.Definitions.limb", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Prims.unit", "Prims._assert", "Prims.int", "Prims.op_Subtraction", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "FStar.Mul.op_Star", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "Prims.pow2", "Lib.IntTypes.bits", "Hacl.Spec.Bignum.Addition.bn_sub_lemma", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Addition.bn_sub", "Prims.l_imp", "Prims.l_not", "Hacl.Spec.Bignum.Definitions.bn_mask_lemma", "Lib.Sequence.lseq", "Prims.l_Forall", "Prims.b2t", "Prims.op_LessThan", "Lib.Sequence.index", "Lib.IntTypes.logand", "Lib.Sequence.map", "Lib.IntTypes.range_t", "Lib.IntTypes.zeros", "Lib.IntTypes.ones", "Lib.IntTypes.int_t", "Prims.l_and", "Prims.l_or", "FStar.Seq.Base.seq", "Lib.Sequence.to_seq", "FStar.Seq.Base.slice", "Prims.op_Addition", "FStar.Seq.Base.index", "Lib.Sequence.sub", "Lib.IntTypes.range", "Lib.ByteSequence.seq_eq_mask" ]
[]
false
false
true
false
false
let bn_sub_mask_lemma #t #len n a =
let mask = Lib.ByteSequence.seq_eq_mask n a len in assert (n == a ==> v mask == v (ones t SEC)); assert (n =!= a ==> v mask == v (zeros t SEC)); let mod_mask = map (logand mask) n in bn_mask_lemma n mask; assert (n == a ==> bn_v mod_mask == bn_v n); assert (n =!= a ==> bn_v mod_mask == 0); let c, res = Hacl.Spec.Bignum.Addition.bn_sub a mod_mask in Hacl.Spec.Bignum.Addition.bn_sub_lemma a mod_mask; assert (bn_v res - v c * pow2 (bits t * len) == bn_v a - bn_v mod_mask); bn_eval_bound res len; assert (bn_v res == bn_v a - bn_v mod_mask); Classical.move_requires_2 (bn_eval_inj len) n a
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.elim_lift_binrel
val elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x)
val elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x)
let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in ()
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 36, "start_col": 0, "start_line": 22 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.WellFounded.binrel a -> y: FStar.WellFounded.Util.top -> x: a -> FStar.Pervasives.Lemma (requires FStar.WellFounded.Util.lift_binrel r y (| a, x |)) (ensures FStar.Pervasives.dfst y == a /\ r (FStar.Pervasives.dsnd y) x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.Util.top", "Prims.squash", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.dfst", "FStar.Pervasives.dsnd", "FStar.Squash.bind_squash", "FStar.WellFounded.Util.lift_binrel", "Prims.Mkdtuple2", "FStar.Classical.Sugar.and_intro", "Prims.unit", "FStar.Classical.Sugar.and_elim", "FStar.Squash.return_squash", "FStar.Squash.get_proof", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let elim_lift_binrel (#a: Type) (r: binrel a) (y: top) (x: a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) =
let s:squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s:squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf: lift_binrel r y (| a, x |)) -> let p1:(dfst y == a /\ a == a) = dfst pf in let p2:r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r . l and FStar.Squash.return_squash p2) in ()
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.equal_counts_empty
val equal_counts_empty (#a: eqtype) (s0 s1: seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0)
val equal_counts_empty (#a: eqtype) (s0 s1: seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0)
let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0)
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 94, "start_col": 0, "start_line": 88 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> FStar.Pervasives.Lemma (requires FStar.Sequence.Base.length s0 == 0 /\ (forall (x: a). FStar.Sequence.Util.count x s0 == FStar.Sequence.Util.count x s1)) (ensures FStar.Sequence.Base.length s1 == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.Sequence.Base.seq", "Prims.op_GreaterThan", "FStar.Sequence.Base.length", "Prims._assert", "Prims.b2t", "FStar.Sequence.Util.count", "FStar.Sequence.Util.head", "Prims.bool", "Prims.unit", "FStar.Pervasives.reveal_opaque", "Prims.nat", "Prims.l_and", "Prims.eq2", "Prims.int", "Prims.l_Forall", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let equal_counts_empty (#a: eqtype) (s0 s1: seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) =
reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0)
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.find
val find (#a: eqtype) (x: a) (s: seq a {count x s > 0}) : Tot (frags: (seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s))
val find (#a: eqtype) (x: a) (s: seq a {count x s > 0}) : Tot (frags: (seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s))
let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx )
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 80, "start_col": 0, "start_line": 64 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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 -> s: FStar.Sequence.Base.seq a {FStar.Sequence.Util.count x s > 0} -> Prims.Tot (frags: (FStar.Sequence.Base.seq a * FStar.Sequence.Base.seq a) { let s' = FStar.Sequence.Base.append (FStar.Pervasives.Native.fst frags) (FStar.Pervasives.Native.snd frags) in let n = FStar.Sequence.Base.length (FStar.Pervasives.Native.fst frags) in FStar.Sequence.Base.equal s (FStar.Sequence.Base.append (FStar.Pervasives.Native.fst frags) (FStar.Sequence.Util.cons x (FStar.Pervasives.Native.snd frags))) })
Prims.Tot
[ "total", "" ]
[]
[ "Prims.eqtype", "FStar.Sequence.Base.seq", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Sequence.Util.count", "Prims.op_Equality", "FStar.Sequence.Util.head", "FStar.Pervasives.Native.Mktuple2", "FStar.Sequence.Base.empty", "FStar.Sequence.Util.tail", "Prims.bool", "FStar.Sequence.Util.cons", "Prims.unit", "Prims._assert", "FStar.Sequence.Base.equal", "FStar.Sequence.Base.append", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd", "Prims.nat", "FStar.Sequence.Base.length", "FStar.Sequence.Permutation.find", "FStar.Pervasives.reveal_opaque" ]
[ "recursion" ]
false
false
false
false
false
let rec find (#a: eqtype) (x: a) (s: seq a {count x s > 0}) : Tot (frags: (seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` (S.append (fst frags) (cons x (snd frags))) }) (decreases (S.length s)) =
reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else (let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx)
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.cswap2_st
val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy )
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 93, "start_col": 0, "start_line": 80 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> bit: Hacl.Bignum.Definitions.limb t -> b1: Hacl.Bignum.Definitions.lbignum t len -> b2: Hacl.Bignum.Definitions.lbignum t len -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.limb", "Hacl.Bignum.Definitions.lbignum", "Lib.Buffer.loop2", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.Buffer.op_Array_Assignment", "Prims.unit", "Lib.IntTypes.op_Hat_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Lib.IntTypes.op_Amp_Dot", "Lib.LoopCombinators.unfold_repeati", "FStar.Pervasives.Native.tuple2", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Pervasives.Native.Mktuple2", "Lib.Buffer.as_seq", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.nat", "Hacl.Spec.Bignum.Lib.cswap2_f", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.uint" ]
[]
false
true
false
false
false
let cswap2_st #t len bit b1 b2 =
[@@ inline_let ]let mask = uint #t 0 -. bit in [@@ inline_let ]let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy)
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.count_head
val count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0)
val count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0)
let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a)
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 97, "start_col": 0, "start_line": 95 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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.Sequence.Base.seq a {FStar.Sequence.Base.length x > 0} -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Util.count (FStar.Sequence.Util.head x) x > 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.eqtype", "FStar.Sequence.Base.seq", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Sequence.Base.length", "FStar.Pervasives.reveal_opaque", "Prims.nat", "FStar.Sequence.Util.count", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Sequence.Util.head", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let count_head (#a: eqtype) (x: seq a {S.length x > 0}) : Lemma (count (head x) x > 0) =
reveal_opaque (`%count) (count #a)
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_top_index
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len
let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 31, "end_line": 145, "start_col": 0, "start_line": 142 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Hacl.Bignum.Lib.bn_get_top_index_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.Lib.bn_get_top_index_u32", "Hacl.Bignum.Lib.bn_get_top_index_u64", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Lib.bn_get_top_index_st" ]
[]
false
false
false
false
false
let bn_get_top_index #t =
match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.lift_binrel_well_founded
val lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r)
val lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r)
let lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r) = let rec aux (y:top{dfst y == a}) (pf:acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 65, "start_col": 0, "start_line": 46 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in () let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in () let lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y) = dsnd p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wf_r: FStar.WellFounded.well_founded r -> FStar.WellFounded.well_founded (FStar.WellFounded.Util.lift_binrel r)
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.Util.top", "FStar.Pervasives.dsnd", "Prims.bool", "FStar.WellFounded.acc", "FStar.WellFounded.Util.lift_binrel", "Prims.l_iff", "Prims.b2t", "Prims.op_Equality", "Prims.eq2", "FStar.Pervasives.dfst", "FStar.StrongExcludedMiddle.strong_excluded_middle", "Prims.l_not", "FStar.WellFounded.AccIntro", "FStar.Pervasives.false_elim", "FStar.WellFounded.__proj__AccIntro__item__access_smaller", "FStar.WellFounded.Util.lower_binrel" ]
[]
false
false
false
false
false
let lift_binrel_well_founded (#a: Type u#a) (#r: binrel u#a u#r a) (wf_r: well_founded r) : well_founded (lift_binrel r) =
let rec aux (y: top{dfst y == a}) (pf: acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf) = AccIntro (fun (z: top) (p: lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p))) in let aux' (y: top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in fun (x: top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.unsquash_well_founded
val unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded u#a u#r r
val unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded u#a u#r r
let unsquash_well_founded (#a:Type u#a) (r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded u#a u#r r = let rec f (x:a) : Tot (acc r x) (decreases {:well-founded (lift_binrel_squashed_as_well_founded_relation wf_r) (| a, x |)}) = AccIntro (let g_smaller (y: a) (u: r y x) : acc r y = lift_binrel_squashed_intro wf_r y x (FStar.Squash.return_squash u); f y in g_smaller) in f
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 121, "start_col": 0, "start_line": 111 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in () let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in () let lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y) = dsnd p let lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r) = let rec aux (y:top{dfst y == a}) (pf:acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x let lower_binrel_squashed (#a:Type u#a) (#r:binrel u#a u#r a) (x y:top u#a) (p:lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y)) = assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y))) by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p))) let lift_binrel_squashed_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded (lift_binrel_squashed r) = let rec aux (y:top{dfst y == a}) (pf:acc (squash_binrel r) (dsnd y)) : Tot (acc (lift_binrel_squashed r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel_squashed r z y) -> let p = lower_binrel_squashed z y p in aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel_squashed r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x let lift_binrel_squashed_intro (#a:Type) (#r:binrel a) (wf_r:well_founded (squash_binrel r)) (x y:a) (sqr:squash (r x y)) : Lemma (ensures lift_binrel_squashed r (|a, x|) (|a, y|)) = assert (lift_binrel_squashed r (| a, x |) (| a , y |)) by FStar.Tactics.( norm [delta_only [`%lift_binrel_squashed]]; split(); split(); trefl(); trefl(); mapply (`FStar.Squash.join_squash) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.WellFounded.binrel a -> wf_r: FStar.WellFounded.well_founded (FStar.WellFounded.Util.squash_binrel r) -> FStar.WellFounded.well_founded r
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.Util.squash_binrel", "FStar.WellFounded.acc", "FStar.WellFounded.Util.lift_binrel_squashed_as_well_founded_relation", "Prims.Mkdtuple2", "FStar.WellFounded.AccIntro", "Prims.unit", "FStar.WellFounded.Util.lift_binrel_squashed_intro", "FStar.Squash.return_squash" ]
[]
false
false
false
false
false
let unsquash_well_founded (#a: Type u#a) (r: binrel u#a u#r a) (wf_r: well_founded (squash_binrel r)) : well_founded u#a u#r r =
let rec f (x: a) : Tot (acc r x) (decreases {:well-founded (lift_binrel_squashed_as_well_founded_relation wf_r) (| a, x |) }) = AccIntro (let g_smaller (y: a) (u: r y x) : acc r y = lift_binrel_squashed_intro wf_r y x (FStar.Squash.return_squash u); f y in g_smaller) in f
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.elim_monoid_laws
val elim_monoid_laws (#a: _) (m: CM.cm a) : Lemma ((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z. {:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x))
val elim_monoid_laws (#a: _) (m: CM.cm a) : Lemma ((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z. {:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x))
let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x )
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 215, "start_col": 0, "start_line": 202 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Algebra.CommMonoid.cm a -> FStar.Pervasives.Lemma (ensures (forall (x: a) (y: a). {:pattern CM?.mult m x y} CM?.mult m x y == CM?.mult m y x) /\ (forall (x: a) (y: a) (z: a). {:pattern CM?.mult m x (CM?.mult m y z)} CM?.mult m x (CM?.mult m y z) == CM?.mult m (CM?.mult m x y) z) /\ (forall (x: a). {:pattern CM?.mult m x (CM?.unit m)} CM?.mult m x (CM?.unit m) == x))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Algebra.CommMonoid.cm", "FStar.Classical.Sugar.forall_intro", "Prims.eq2", "FStar.Algebra.CommMonoid.__proj__CM__item__mult", "FStar.Algebra.CommMonoid.__proj__CM__item__unit", "FStar.Algebra.CommMonoid.__proj__CM__item__identity", "Prims.squash", "Prims.unit", "Prims.l_Forall", "FStar.Algebra.CommMonoid.__proj__CM__item__associativity", "FStar.Algebra.CommMonoid.__proj__CM__item__commutativity", "Prims.l_True", "Prims.l_and", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let elim_monoid_laws #a (m: CM.cm a) : Lemma ((forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z. {:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x. {:pattern (m.mult x m.unit)} m.mult x m.unit == x)) =
introduce forall x y . m.mult x y == m.mult y x with (m.commutativity x y); introduce forall x y z . m.mult x (m.mult y z) == m.mult (m.mult x y) z with (m.associativity x y z); introduce forall x . m.mult x m.unit == x with (m.identity x)
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.foldm_back_sym
val foldm_back_sym (#a:Type) (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
val foldm_back_sym (#a:Type) (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1))
let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 253, "start_col": 0, "start_line": 248 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Algebra.CommMonoid.cm a -> s1: FStar.Sequence.Base.seq a -> s2: FStar.Sequence.Base.seq a -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s1 s2) == FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s2 s1))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Algebra.CommMonoid.cm", "FStar.Sequence.Base.seq", "FStar.Sequence.Permutation.foldm_back_append", "Prims.unit", "FStar.Sequence.Permutation.elim_monoid_laws", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Sequence.Permutation.foldm_back", "FStar.Sequence.Base.append", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let foldm_back_sym #a (m: CM.cm a) (s1: seq a) (s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) =
elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.intro_lift_binrel
val intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |))
val intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |))
let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in ()
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 20, "start_col": 0, "start_line": 6 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: FStar.WellFounded.binrel a -> y: a -> x: a -> FStar.Pervasives.Lemma (requires r y x) (ensures FStar.WellFounded.Util.lift_binrel r (| a, y |) (| a, x |))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.WellFounded.binrel", "Prims.squash", "FStar.WellFounded.Util.lift_binrel", "FStar.Squash.bind_squash", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.dfst", "FStar.Pervasives.dsnd", "FStar.Squash.return_squash", "Prims.Mkdtuple2", "FStar.WellFounded.Util.top", "Prims.unit", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let intro_lift_binrel (#a: Type) (r: binrel a) (y x: a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) =
let t0:top = (| a, y |) in let t1:top = (| a, x |) in let pf1:squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2:squash (r (dsnd t0) (dsnd t1)) = () in let pf:squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p:lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in ()
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.remove_i
val remove_i (#a: _) (s: seq a) (i: nat{i < S.length s}) : a & seq a
val remove_i (#a: _) (s: seq a) (i: nat{i < S.length s}) : a & seq a
let remove_i #a (s:seq a) (i:nat{i < S.length s}) : a & seq a = let s0, s1 = split s i in head s1, append s0 (tail s1)
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 285, "start_col": 0, "start_line": 282 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1 #push-options "--fuel 2" let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m #pop-options #push-options "--fuel 0" let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = calc (==) { foldm_back m (S.append s1 (cons x s2)); (==) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); (==) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); (==) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); (==) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); (==) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); } #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: FStar.Sequence.Base.seq a -> i: Prims.nat{i < FStar.Sequence.Base.length s} -> a * FStar.Sequence.Base.seq a
Prims.Tot
[ "total" ]
[]
[ "FStar.Sequence.Base.seq", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.Sequence.Base.length", "FStar.Pervasives.Native.Mktuple2", "FStar.Sequence.Util.head", "FStar.Sequence.Base.append", "FStar.Sequence.Util.tail", "FStar.Pervasives.Native.tuple2", "FStar.Sequence.Util.split" ]
[]
false
false
false
false
false
let remove_i #a (s: seq a) (i: nat{i < S.length s}) : a & seq a =
let s0, s1 = split s i in head s1, append s0 (tail s1)
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_ith_bit
val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i))
val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i))
let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 44, "start_col": 0, "start_line": 36 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> b: Hacl.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.IntTypes.uint", "Hacl.Bignum.Definitions.limb", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Percent_Dot", "Lib.IntTypes.op_Slash_Dot", "Lib.IntTypes.size" ]
[]
false
true
false
false
false
let bn_get_ith_bit #t len input ind =
[@@ inline_let ]let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.lower_binrel
val lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y)
val lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y)
let lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y) = dsnd p
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 10, "end_line": 43, "start_col": 0, "start_line": 38 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in () let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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.WellFounded.Util.top -> y: FStar.WellFounded.Util.top -> p: FStar.WellFounded.Util.lift_binrel r x y -> r (FStar.Pervasives.dsnd x) (FStar.Pervasives.dsnd y)
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.Util.top", "FStar.WellFounded.Util.lift_binrel", "FStar.Pervasives.dsnd", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.dfst" ]
[]
false
false
false
false
false
let lower_binrel (#a: Type) (#r: binrel a) (x y: top) (p: lift_binrel r x y) : r (dsnd x) (dsnd y) =
dsnd p
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.seqperm_len
val seqperm_len (#a: _) (s0 s1: seq a) (p: seqperm s0 s1) : Lemma (ensures S.length s0 == S.length s1)
val seqperm_len (#a: _) (s0 s1: seq a) (p: seqperm s0 s1) : Lemma (ensures S.length s0 == S.length s1)
let seqperm_len #a (s0 s1:seq a) (p:seqperm s0 s1) : Lemma (ensures S.length s0 == S.length s1) = reveal_is_permutation s0 s1 p
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 321, "start_col": 0, "start_line": 317 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1 #push-options "--fuel 2" let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m #pop-options #push-options "--fuel 0" let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = calc (==) { foldm_back m (S.append s1 (cons x s2)); (==) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); (==) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); (==) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); (==) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); (==) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); } #pop-options let remove_i #a (s:seq a) (i:nat{i < S.length s}) : a & seq a = let s0, s1 = split s i in head s1, append s0 (tail s1) let shift_perm' #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) = reveal_is_permutation s0 s1 p; let s0', last = un_build s0 in let n = S.length s0' in let p' (i:nat{ i < n }) : j:nat{ j < n } = if p i < p n then p i else p i - 1 in let _, s1' = remove_i s1 (p n) in reveal_is_permutation_nopats s0' s1' p'; p' let shift_perm #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) (requires True) (ensures fun _ -> let n = S.length s0 - 1 in S.index s1 (p n) == S.index s0 n) = reveal_is_permutation s0 s1 p; shift_perm' s0 s1 () p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> p: FStar.Sequence.Permutation.seqperm s0 s1 -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Sequence.Base.seq", "FStar.Sequence.Permutation.seqperm", "FStar.Sequence.Permutation.reveal_is_permutation", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.nat", "FStar.Sequence.Base.length", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let seqperm_len #a (s0: seq a) (s1: seq a) (p: seqperm s0 s1) : Lemma (ensures S.length s0 == S.length s1) =
reveal_is_permutation s0 s1 p
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.lower_binrel_squashed
val lower_binrel_squashed (#a:Type u#a) (#r:binrel u#a u#r a) (x y:top u#a) (p:lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y))
val lower_binrel_squashed (#a:Type u#a) (#r:binrel u#a u#r a) (x y:top u#a) (p:lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y))
let lower_binrel_squashed (#a:Type u#a) (#r:binrel u#a u#r a) (x y:top u#a) (p:lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y)) = assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y))) by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p)))
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 71, "end_line": 73, "start_col": 0, "start_line": 67 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in () let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in () let lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y) = dsnd p let lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r) = let rec aux (y:top{dfst y == a}) (pf:acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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.WellFounded.Util.top -> y: FStar.WellFounded.Util.top -> p: FStar.WellFounded.Util.lift_binrel_squashed r x y -> Prims.squash (r (FStar.Pervasives.dsnd x) (FStar.Pervasives.dsnd y))
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.Util.top", "FStar.WellFounded.Util.lift_binrel_squashed", "FStar.Tactics.Effect.assert_by_tactic", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.dfst", "Prims.squash", "FStar.Pervasives.dsnd", "Prims.unit", "FStar.Tactics.V1.Derived.exact", "FStar.Stubs.Reflection.Types.term", "FStar.Squash.return_squash" ]
[]
false
false
true
false
false
let lower_binrel_squashed (#a: Type u#a) (#r: binrel u#a u#r a) (x y: top u#a) (p: lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y)) =
FStar.Tactics.Effect.assert_by_tactic (dfst x == a /\ dfst y == a /\ squash (r (dsnd x) (dsnd y))) (fun _ -> (); let open FStar.Tactics in exact (quote (FStar.Squash.return_squash p)))
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.lift_binrel_squashed_well_founded
val lift_binrel_squashed_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded (lift_binrel_squashed r)
val lift_binrel_squashed_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded (lift_binrel_squashed r)
let lift_binrel_squashed_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded (lift_binrel_squashed r) = let rec aux (y:top{dfst y == a}) (pf:acc (squash_binrel r) (dsnd y)) : Tot (acc (lift_binrel_squashed r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel_squashed r z y) -> let p = lower_binrel_squashed z y p in aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel_squashed r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 17, "end_line": 96, "start_col": 0, "start_line": 76 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in () let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in () let lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y) = dsnd p let lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r) = let rec aux (y:top{dfst y == a}) (pf:acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x let lower_binrel_squashed (#a:Type u#a) (#r:binrel u#a u#r a) (x y:top u#a) (p:lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y)) = assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y))) by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p)))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wf_r: FStar.WellFounded.well_founded (FStar.WellFounded.Util.squash_binrel r) -> FStar.WellFounded.well_founded (FStar.WellFounded.Util.lift_binrel_squashed r)
Prims.Tot
[ "total" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.Util.squash_binrel", "FStar.WellFounded.Util.top", "FStar.Pervasives.dsnd", "Prims.bool", "FStar.WellFounded.acc", "FStar.WellFounded.Util.lift_binrel_squashed", "Prims.l_iff", "Prims.b2t", "Prims.op_Equality", "Prims.eq2", "FStar.Pervasives.dfst", "FStar.StrongExcludedMiddle.strong_excluded_middle", "Prims.l_not", "FStar.WellFounded.AccIntro", "FStar.Pervasives.false_elim", "FStar.WellFounded.__proj__AccIntro__item__access_smaller", "FStar.Squash.join_squash", "Prims.squash", "FStar.WellFounded.Util.lower_binrel_squashed" ]
[]
false
false
false
false
false
let lift_binrel_squashed_well_founded (#a: Type u#a) (#r: binrel u#a u#r a) (wf_r: well_founded (squash_binrel r)) : well_founded (lift_binrel_squashed r) =
let rec aux (y: top{dfst y == a}) (pf: acc (squash_binrel r) (dsnd y)) : Tot (acc (lift_binrel_squashed r) y) (decreases pf) = AccIntro (fun (z: top) (p: lift_binrel_squashed r z y) -> let p = lower_binrel_squashed z y p in aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p))) in let aux' (y: top{dfst y =!= a}) : acc (lift_binrel_squashed r) y = AccIntro (fun y p -> false_elim ()) in fun (x: top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.foldm_back_singleton
val foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x)
val foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x)
let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 22, "end_line": 258, "start_col": 0, "start_line": 256 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 0, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Algebra.CommMonoid.cm a -> x: a -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.singleton x) == x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Algebra.CommMonoid.cm", "FStar.Sequence.Permutation.elim_monoid_laws", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Sequence.Permutation.foldm_back", "FStar.Sequence.Base.singleton", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let foldm_back_singleton (#a: _) (m: CM.cm a) (x: a) : Lemma (foldm_back m (singleton x) == x) =
elim_monoid_laws m
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.foldm_back3
val foldm_back3 (#a: _) (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2)))
val foldm_back3 (#a: _) (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2)))
let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = calc (==) { foldm_back m (S.append s1 (cons x s2)); (==) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); (==) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); (==) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); (==) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); (==) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); }
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 278, "start_col": 0, "start_line": 262 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1 #push-options "--fuel 2" let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Algebra.CommMonoid.cm a -> s1: FStar.Sequence.Base.seq a -> x: a -> s2: FStar.Sequence.Base.seq a -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s1 (FStar.Sequence.Util.cons x s2)) == CM?.mult m x (FStar.Sequence.Permutation.foldm_back m (FStar.Sequence.Base.append s1 s2)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Algebra.CommMonoid.cm", "FStar.Sequence.Base.seq", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Sequence.Permutation.foldm_back", "FStar.Sequence.Base.append", "FStar.Sequence.Util.cons", "FStar.Algebra.CommMonoid.__proj__CM__item__mult", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Sequence.Base.singleton", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Sequence.Permutation.foldm_back_append", "Prims.squash", "FStar.Sequence.Permutation.foldm_back_singleton", "FStar.Sequence.Permutation.elim_monoid_laws", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let foldm_back3 #a (m: CM.cm a) (s1: seq a) (x: a) (s2: seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) =
calc ( == ) { foldm_back m (S.append s1 (cons x s2)); ( == ) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); ( == ) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); ( == ) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); ( == ) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); ( == ) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); }
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_bits
val bn_get_bits: #t:_ -> bn_get_bits_st t
val bn_get_bits: #t:_ -> bn_get_bits_st t
let bn_get_bits #t = match t with | U32 -> bn_get_bits_u32 | U64 -> bn_get_bits_u64
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 202, "start_col": 0, "start_line": 199 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64 inline_for_extraction noextract val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) let bn_get_bits_limb #t len n ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1 inline_for_extraction noextract let bn_get_bits_st (t:limb_t) = len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l)) inline_for_extraction noextract val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t let mk_bn_get_bits #t len b i l = [@inline_let] let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in bn_get_bits_limb len b i &. mask_l [@CInline] let bn_get_bits_u32: bn_get_bits_st U32 = mk_bn_get_bits [@CInline] let bn_get_bits_u64: bn_get_bits_st U64 = mk_bn_get_bits inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Bignum.Lib.bn_get_bits_st t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Hacl.Bignum.Lib.bn_get_bits_u32", "Hacl.Bignum.Lib.bn_get_bits_u64", "Hacl.Bignum.Lib.bn_get_bits_st" ]
[]
false
false
false
false
false
let bn_get_bits #t =
match t with | U32 -> bn_get_bits_u32 | U64 -> bn_get_bits_u64
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.mk_bn_get_bits
val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t
val mk_bn_get_bits: #t:limb_t -> bn_get_bits_st t
let mk_bn_get_bits #t len b i l = [@inline_let] let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in bn_get_bits_limb len b i &. mask_l
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 189, "start_col": 0, "start_line": 187 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64 inline_for_extraction noextract val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind)) let bn_get_bits_limb #t len n ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1 inline_for_extraction noextract let bn_get_bits_st (t:limb_t) = len:size_t -> b:lbignum t len -> i:size_t -> l:size_t{v l < bits t /\ v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits (as_seq h0 b) (v i) (v l)) inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Hacl.Bignum.Lib.bn_get_bits_st t
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.l_and", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Prims.op_Division", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.SEC", "Hacl.Bignum.Definitions.limb", "Lib.IntTypes.int_t", "Hacl.Bignum.Lib.bn_get_bits_limb", "Lib.IntTypes.op_Subtraction_Dot", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.uint" ]
[]
false
false
false
false
false
let mk_bn_get_bits #t len b i l =
[@@ inline_let ]let mask_l = (uint #t #SEC 1 <<. l) -. uint #t 1 in bn_get_bits_limb len b i &. mask_l
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.shift_perm'
val shift_perm': #a: _ -> s0: seq a -> s1: seq a -> squash (S.length s0 == S.length s1 /\ S.length s0 > 0) -> p: seqperm s0 s1 -> Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
val shift_perm': #a: _ -> s0: seq a -> s1: seq a -> squash (S.length s0 == S.length s1 /\ S.length s0 > 0) -> p: seqperm s0 s1 -> Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1)))))
let shift_perm' #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) = reveal_is_permutation s0 s1 p; let s0', last = un_build s0 in let n = S.length s0' in let p' (i:nat{ i < n }) : j:nat{ j < n } = if p i < p n then p i else p i - 1 in let _, s1' = remove_i s1 (p n) in reveal_is_permutation_nopats s0' s1' p'; p'
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 302, "start_col": 0, "start_line": 287 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1 #push-options "--fuel 2" let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m #pop-options #push-options "--fuel 0" let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = calc (==) { foldm_back m (S.append s1 (cons x s2)); (==) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); (==) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); (==) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); (==) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); (==) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); } #pop-options let remove_i #a (s:seq a) (i:nat{i < S.length s}) : a & seq a = let s0, s1 = split s i in head s1, append s0 (tail s1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> _: Prims.squash (FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\ FStar.Sequence.Base.length s0 > 0) -> p: FStar.Sequence.Permutation.seqperm s0 s1 -> FStar.Sequence.Permutation.seqperm (FStar.Pervasives.Native.fst (FStar.Sequence.Util.un_build s0 )) (FStar.Pervasives.Native.snd (FStar.Sequence.Permutation.remove_i s1 (p (FStar.Sequence.Base.length s0 - 1))))
Prims.Tot
[ "total" ]
[]
[ "FStar.Sequence.Base.seq", "Prims.squash", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Sequence.Base.length", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Sequence.Permutation.seqperm", "Prims.unit", "FStar.Sequence.Permutation.reveal_is_permutation_nopats", "FStar.Pervasives.Native.fst", "FStar.Sequence.Util.un_build", "FStar.Pervasives.Native.snd", "FStar.Sequence.Permutation.remove_i", "Prims.op_Subtraction", "FStar.Pervasives.Native.tuple2", "Prims.op_LessThan", "Prims.bool", "FStar.Sequence.Permutation.reveal_is_permutation" ]
[]
false
false
false
false
false
let shift_perm' #a (s0: seq a) (s1: seq a) (_: squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p: seqperm s0 s1) : Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) =
reveal_is_permutation s0 s1 p; let s0', last = un_build s0 in let n = S.length s0' in let p' (i: nat{i < n}) : j: nat{j < n} = if p i < p n then p i else p i - 1 in let _, s1' = remove_i s1 (p n) in reveal_is_permutation_nopats s0' s1' p'; p'
false
FStar.WellFounded.Util.fst
FStar.WellFounded.Util.lift_binrel_squashed_intro
val lift_binrel_squashed_intro (#a:Type) (#r:binrel a) (wf_r:well_founded (squash_binrel r)) (x y:a) (sqr:squash (r x y)) : Lemma (ensures lift_binrel_squashed r (|a, x|) (|a, y|))
val lift_binrel_squashed_intro (#a:Type) (#r:binrel a) (wf_r:well_founded (squash_binrel r)) (x y:a) (sqr:squash (r x y)) : Lemma (ensures lift_binrel_squashed r (|a, x|) (|a, y|))
let lift_binrel_squashed_intro (#a:Type) (#r:binrel a) (wf_r:well_founded (squash_binrel r)) (x y:a) (sqr:squash (r x y)) : Lemma (ensures lift_binrel_squashed r (|a, x|) (|a, y|)) = assert (lift_binrel_squashed r (| a, x |) (| a , y |)) by FStar.Tactics.( norm [delta_only [`%lift_binrel_squashed]]; split(); split(); trefl(); trefl(); mapply (`FStar.Squash.join_squash) )
{ "file_name": "ulib/FStar.WellFounded.Util.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 12, "end_line": 109, "start_col": 0, "start_line": 98 }
module FStar.WellFounded.Util open FStar.WellFounded #push-options "--warn_error -242" //inner let recs not encoded to SMT; ok let intro_lift_binrel (#a:Type) (r:binrel a) (y:a) (x:a) : Lemma (requires r y x) (ensures lift_binrel r (| a, y |) (| a, x |)) = let t0 : top = (| a, y |) in let t1 : top = (| a, x |) in let pf1 : squash (dfst t0 == a /\ dfst t1 == a) = () in let pf2 : squash (r (dsnd t0) (dsnd t1)) = () in let pf : squash (lift_binrel r t0 t1) = FStar.Squash.bind_squash pf1 (fun (pf1: (dfst t0 == a /\ dfst t1 == a)) -> FStar.Squash.bind_squash pf2 (fun (pf2: (r (dsnd t0) (dsnd t1))) -> let p : lift_binrel r t0 t1 = (| pf1, pf2 |) in FStar.Squash.return_squash p)) in () let elim_lift_binrel (#a:Type) (r:binrel a) (y:top) (x:a) : Lemma (requires lift_binrel r y (| a, x |)) (ensures dfst y == a /\ r (dsnd y) x) = let s : squash (lift_binrel r y (| a, x |)) = FStar.Squash.get_proof (lift_binrel r y (| a, x |)) in let s : squash (dfst y == a /\ r (dsnd y) x) = FStar.Squash.bind_squash s (fun (pf:lift_binrel r y (|a, x|)) -> let p1 : (dfst y == a /\ a == a) = dfst pf in let p2 : r (dsnd y) x = dsnd pf in introduce dfst y == a /\ r (dsnd y) x with eliminate dfst y == a /\ a == a returns _ with l r. l and FStar.Squash.return_squash p2) in () let lower_binrel (#a:Type) (#r:binrel a) (x y:top) (p:lift_binrel r x y) : r (dsnd x) (dsnd y) = dsnd p let lift_binrel_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded r) : well_founded (lift_binrel r) = let rec aux (y:top{dfst y == a}) (pf:acc r (dsnd y)) : Tot (acc (lift_binrel r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel r z y) -> aux z (pf.access_smaller (dsnd z) (lower_binrel z y p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x let lower_binrel_squashed (#a:Type u#a) (#r:binrel u#a u#r a) (x y:top u#a) (p:lift_binrel_squashed r x y) : squash (r (dsnd x) (dsnd y)) = assert (dfst x==a /\ dfst y==a /\ squash (r (dsnd x) (dsnd y))) by FStar.Tactics.(exact (quote (FStar.Squash.return_squash p))) let lift_binrel_squashed_well_founded (#a:Type u#a) (#r:binrel u#a u#r a) (wf_r:well_founded (squash_binrel r)) : well_founded (lift_binrel_squashed r) = let rec aux (y:top{dfst y == a}) (pf:acc (squash_binrel r) (dsnd y)) : Tot (acc (lift_binrel_squashed r) y) (decreases pf) = AccIntro (fun (z:top) (p:lift_binrel_squashed r z y) -> let p = lower_binrel_squashed z y p in aux z (pf.access_smaller (dsnd z) (FStar.Squash.join_squash p))) in let aux' (y:top{dfst y =!= a}) : acc (lift_binrel_squashed r) y = AccIntro (fun y p -> false_elim ()) in fun (x:top) -> let b = FStar.StrongExcludedMiddle.strong_excluded_middle (dfst x == a) in if b then aux x (wf_r (dsnd x)) else aux' x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.WellFounded.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.StrongExcludedMiddle.fst.checked", "FStar.Squash.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked" ], "interface_file": true, "source_file": "FStar.WellFounded.Util.fst" }
[ { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.WellFounded", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
wf_r: FStar.WellFounded.well_founded (FStar.WellFounded.Util.squash_binrel r) -> x: a -> y: a -> sqr: Prims.squash (r x y) -> FStar.Pervasives.Lemma (ensures FStar.WellFounded.Util.lift_binrel_squashed r (| a, x |) (| a, y |))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.WellFounded.binrel", "FStar.WellFounded.well_founded", "FStar.WellFounded.Util.squash_binrel", "Prims.squash", "FStar.Tactics.Effect.assert_by_tactic", "FStar.WellFounded.Util.lift_binrel_squashed", "Prims.Mkdtuple2", "Prims.unit", "FStar.Tactics.V1.Derived.mapply", "FStar.Tactics.V1.Derived.trefl", "FStar.Tactics.V1.Logic.split", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let lift_binrel_squashed_intro (#a: Type) (#r: binrel a) (wf_r: well_founded (squash_binrel r)) (x y: a) (sqr: squash (r x y)) : Lemma (ensures lift_binrel_squashed r (| a, x |) (| a, y |)) =
FStar.Tactics.Effect.assert_by_tactic (lift_binrel_squashed r (| a, x |) (| a, y |)) (fun _ -> (); let open FStar.Tactics in norm [delta_only [`%lift_binrel_squashed]]; split (); split (); trefl (); trefl (); mapply (`FStar.Squash.join_squash))
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.shift_perm
val shift_perm: #a: _ -> s0: seq a -> s1: seq a -> squash (S.length s0 == S.length s1 /\ S.length s0 > 0) -> p: seqperm s0 s1 -> Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) (requires True) (ensures fun _ -> let n = S.length s0 - 1 in S.index s1 (p n) == S.index s0 n)
val shift_perm: #a: _ -> s0: seq a -> s1: seq a -> squash (S.length s0 == S.length s1 /\ S.length s0 > 0) -> p: seqperm s0 s1 -> Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) (requires True) (ensures fun _ -> let n = S.length s0 - 1 in S.index s1 (p n) == S.index s0 n)
let shift_perm #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) (requires True) (ensures fun _ -> let n = S.length s0 - 1 in S.index s1 (p n) == S.index s0 n) = reveal_is_permutation s0 s1 p; shift_perm' s0 s1 () p
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 315, "start_col": 0, "start_line": 304 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1 #push-options "--fuel 2" let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m #pop-options #push-options "--fuel 0" let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = calc (==) { foldm_back m (S.append s1 (cons x s2)); (==) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); (==) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); (==) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); (==) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); (==) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); } #pop-options let remove_i #a (s:seq a) (i:nat{i < S.length s}) : a & seq a = let s0, s1 = split s i in head s1, append s0 (tail s1) let shift_perm' #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) = reveal_is_permutation s0 s1 p; let s0', last = un_build s0 in let n = S.length s0' in let p' (i:nat{ i < n }) : j:nat{ j < n } = if p i < p n then p i else p i - 1 in let _, s1' = remove_i s1 (p n) in reveal_is_permutation_nopats s0' s1' p'; p'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> _: Prims.squash (FStar.Sequence.Base.length s0 == FStar.Sequence.Base.length s1 /\ FStar.Sequence.Base.length s0 > 0) -> p: FStar.Sequence.Permutation.seqperm s0 s1 -> Prims.Pure (FStar.Sequence.Permutation.seqperm (FStar.Pervasives.Native.fst (FStar.Sequence.Util.un_build s0 )) (FStar.Pervasives.Native.snd (FStar.Sequence.Permutation.remove_i s1 (p (FStar.Sequence.Base.length s0 - 1)))))
Prims.Pure
[]
[]
[ "FStar.Sequence.Base.seq", "Prims.squash", "Prims.l_and", "Prims.eq2", "Prims.nat", "FStar.Sequence.Base.length", "Prims.b2t", "Prims.op_GreaterThan", "FStar.Sequence.Permutation.seqperm", "FStar.Sequence.Permutation.shift_perm'", "Prims.unit", "FStar.Sequence.Permutation.reveal_is_permutation", "FStar.Pervasives.Native.fst", "FStar.Sequence.Util.un_build", "FStar.Pervasives.Native.snd", "FStar.Sequence.Permutation.remove_i", "Prims.op_Subtraction", "Prims.l_True", "FStar.Sequence.Base.index", "Prims.int" ]
[]
false
false
false
false
false
let shift_perm #a (s0: seq a) (s1: seq a) (_: squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p: seqperm s0 s1) : Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) (requires True) (ensures fun _ -> let n = S.length s0 - 1 in S.index s1 (p n) == S.index s0 n) =
reveal_is_permutation s0 s1 p; shift_perm' s0 s1 () p
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.mk_bn_get_top_index
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len
let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 133, "start_col": 0, "start_line": 107 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t{0 < Lib.IntTypes.v len} -> Hacl.Bignum.Lib.bn_get_top_index_st t len
Prims.Tot
[ "total" ]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Prims.b2t", "Prims.op_LessThan", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Hacl.Bignum.Definitions.lbignum", "Hacl.Bignum.Definitions.limb", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "Lib.IntTypes.int_t", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t", "Lib.Loops.for", "Prims.l_and", "Prims.op_LessThanOrEqual", "Hacl.Spec.Bignum.Base.mask_select_lemma", "Lib.Sequence.index", "Lib.Buffer.as_seq", "Hacl.Spec.Bignum.Base.size_to_limb", "Lib.Buffer.op_Array_Assignment", "Hacl.Spec.Bignum.Base.mask_select", "Hacl.Spec.Bignum.Definitions.limb", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.IntTypes.eq_mask", "Lib.IntTypes.zeros", "Lib.LoopCombinators.unfold_repeat_gen", "Hacl.Spec.Bignum.Lib.bn_get_top_index_t", "Lib.LoopCombinators.eq_repeat_gen0", "Prims.nat", "Prims.logical", "Lib.Buffer.modifies1", "Lib.Buffer.live", "Lib.Buffer.disjoint", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "Lib.IntTypes.range", "Lib.LoopCombinators.repeat_gen", "Prims.op_Addition", "Hacl.Spec.Bignum.Lib.bn_get_top_index_f", "Lib.Buffer.lbuffer_t", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Buffer.create", "Lib.IntTypes.uint", "Lib.Buffer.lbuffer", "FStar.HyperStack.ST.push_frame" ]
[]
false
false
false
false
false
let mk_bn_get_top_index #t len b =
push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@@ inline_let ]let refl h i = v (LSeq.index (as_seq h priv) 0) in [@@ inline_let ]let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@@ inline_let ]let inv h (i: nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_set_ith_bit
val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j)
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 45, "end_line": 65, "start_col": 0, "start_line": 58 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> b: Hacl.Bignum.Definitions.lbignum t len -> i: Lib.IntTypes.size_t{Lib.IntTypes.v i / Lib.IntTypes.bits t < Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack Prims.unit
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Lib.Buffer.op_Array_Assignment", "Hacl.Bignum.Definitions.limb", "Prims.unit", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.SEC", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.uint", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.IntTypes.op_Percent_Dot", "Lib.IntTypes.op_Slash_Dot", "Lib.IntTypes.size" ]
[]
false
true
false
false
false
let bn_set_ith_bit #t len input ind =
[@@ inline_let ]let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j)
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if3
val test_if3 (b: bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r)
val test_if3 (b: bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r)
let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop ()
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 34, "end_line": 119, "start_col": 0, "start_line": 118 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.bool -> r: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.ref", "Steel.Effect.Atomic.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if3 (b: bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) =
if b then noop () else noop ()
false
Lib.NatMod.fst
Lib.NatMod.pow_mod
val pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> nat_mod m
val pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> nat_mod m
let pow_mod #m a b = pow_mod_ #m a b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 36, "end_line": 122, "start_col": 0, "start_line": 122 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Prims.nat -> Lib.NatMod.nat_mod m
Prims.Tot
[ "total" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Prims.nat", "Lib.NatMod.pow_mod_" ]
[]
false
false
false
false
false
let pow_mod #m a b =
pow_mod_ #m a b
false
FStar.Sequence.Permutation.fst
FStar.Sequence.Permutation.foldm_back_perm
val foldm_back_perm (#a:_) (m:CM.cm a) (s0:seq a) (s1:seq a) (p:seqperm s0 s1) : Lemma (ensures foldm_back m s0 == foldm_back m s1)
val foldm_back_perm (#a:_) (m:CM.cm a) (s0:seq a) (s1:seq a) (p:seqperm s0 s1) : Lemma (ensures foldm_back m s0 == foldm_back m s1)
let rec foldm_back_perm #a m s0 s1 p : Lemma (ensures foldm_back m s0 == foldm_back m s1) (decreases (S.length s0)) = seqperm_len s0 s1 p; if S.length s0 = 0 then ( assert (S.equal s0 s1) ) else ( let n0 = S.length s0 - 1 in let prefix, last = un_build s0 in let prefix', suffix' = split s1 (p n0) in let last', suffix' = suffix' $@ 0, drop suffix' 1 in let s1' = snd (remove_i s1 (p n0)) in let p' : seqperm prefix s1' = shift_perm s0 s1 () p in assert (last == last'); calc (==) { foldm_back m s1; (==) { assert (s1 `S.equal` S.append prefix' (cons last' suffix')) } foldm_back m (S.append prefix' (cons last' suffix')); (==) { foldm_back3 m prefix' last' suffix' } m.mult last' (foldm_back m (append prefix' suffix')); (==) { assert (S.equal (append prefix' suffix') s1') } m.mult last' (foldm_back m s1'); (==) { foldm_back_perm m prefix s1' p' } m.mult last' (foldm_back m prefix); (==) { } foldm_back m s0; } )
{ "file_name": "ulib/experimental/FStar.Sequence.Permutation.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 354, "start_col": 0, "start_line": 323 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: N. Swamy *) module FStar.Sequence.Permutation open FStar.Sequence open FStar.Calc open FStar.Sequence.Util module S = FStar.Sequence //////////////////////////////////////////////////////////////////////////////// [@@"opaque_to_smt"] let is_permutation (#a:Type) (s0:seq a) (s1:seq a) (f:index_fun s0) = S.length s0 == S.length s1 /\ (forall x y. // {:pattern f x; f y} x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). // {:pattern (S.index s1 (f i))} S.index s0 i == S.index s1 (f i)) let reveal_is_permutation #a (s0 s1:seq a) (f:index_fun s0) = reveal_opaque (`%is_permutation) (is_permutation s0 s1 f) let reveal_is_permutation_nopats (#a:Type) (s0 s1:seq a) (f:index_fun s0) : Lemma (is_permutation s0 s1 f <==> S.length s0 == S.length s1 /\ (forall x y. x <> y ==> f x <> f y) /\ (forall (i:nat{i < S.length s0}). S.index s0 i == S.index s1 (f i))) = reveal_is_permutation s0 s1 f let split3_index (#a:eqtype) (s0:seq a) (x:a) (s1:seq a) (j:nat) : Lemma (requires j < S.length (S.append s0 s1)) (ensures ( let s = S.append s0 (cons x s1) in let s' = S.append s0 s1 in let n = S.length s0 in if j < n then S.index s' j == S.index s j else S.index s' j == S.index s (j + 1) )) = let n = S.length (S.append s0 s1) in if j < n then () else () let rec find (#a:eqtype) (x:a) (s:seq a{ count x s > 0 }) : Tot (frags:(seq a & seq a) { let s' = S.append (fst frags) (snd frags) in let n = S.length (fst frags) in s `S.equal` S.append (fst frags) (cons x (snd frags)) }) (decreases (S.length s)) = reveal_opaque (`%count) (count #a); if head s = x then S.empty, tail s else ( let pfx, sfx = find x (tail s) in assert (S.equal (tail s) (S.append pfx (cons x sfx))); assert (S.equal s (cons (head s) (tail s))); cons (head s) pfx, sfx ) let count_singleton_one (#a:eqtype) (x:a) : Lemma (count x (singleton x) == 1) = reveal_opaque (`%count) (count #a) let count_singleton_zero (#a:eqtype) (x y:a) : Lemma (x =!= y ==> count x (singleton y) == 0) = reveal_opaque (`%count) (count #a) let equal_counts_empty (#a:eqtype) (s0 s1:seq a) : Lemma (requires S.length s0 == 0 /\ (forall x. count x s0 == count x s1)) (ensures S.length s1 == 0) = reveal_opaque (`%count) (count #a); if S.length s1 > 0 then assert (count (head s1) s1 > 0) let count_head (#a:eqtype) (x:seq a{ S.length x > 0 }) : Lemma (count (head x) x > 0) = reveal_opaque (`%count) (count #a) #push-options "--fuel 0 --ifuel 0 --z3rlimit_factor 2" let rec permutation_from_equal_counts (#a:eqtype) (s0:seq a) (s1:seq a{(forall x. count x s0 == count x s1)}) : Tot (seqperm s0 s1) (decreases (S.length s0)) = if S.length s0 = 0 then ( count_empty s0; assert (forall x. count x s0 = 0); let f : index_fun s0 = fun i -> i in reveal_is_permutation_nopats s0 s1 f; equal_counts_empty s0 s1; f ) else ( count_head s0; let pfx, sfx = find (head s0) s1 in introduce forall x. count x (tail s0) == count x (S.append pfx sfx) with ( if x = head s0 then ( calc (eq2 #int) { count x (tail s0) <: int; (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux (head s0) (S.singleton (head s0)) (tail s0); count_singleton_one x } count x s0 - 1 <: int; (==) {} count x s1 - 1 <: int; (==) {} count x (S.append pfx (cons (head s0) sfx)) - 1 <: int; (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx) - 1 <: int; (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) - 1 <: int; (==) { count_singleton_one x } count x pfx + count x sfx <: int; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx) <: int; } ) else ( calc (==) { count x (tail s0); (==) { assert (s0 `S.equal` cons (head s0) (tail s0)); lemma_append_count_aux x (S.singleton (head s0)) (tail s0); count_singleton_zero x (head s0) } count x s0; (==) { } count x s1; (==) { } count x (S.append pfx (cons (head s0) sfx)); (==) { lemma_append_count_aux x pfx (cons (head s0) sfx) } count x pfx + count x (cons (head s0) sfx); (==) { lemma_append_count_aux x (S.singleton (head s0)) sfx } count x pfx + (count x (S.singleton (head s0)) + count x sfx) ; (==) { count_singleton_zero x (head s0) } count x pfx + count x sfx; (==) { lemma_append_count_aux x pfx sfx } count x (S.append pfx sfx); } ) ); let s1' = (S.append pfx sfx) in let f' = permutation_from_equal_counts (tail s0) s1' in reveal_is_permutation_nopats (tail s0) s1' f'; let n = S.length pfx in let f : index_fun s0 = fun i -> if i = 0 then n else if f' (i - 1) < n then f' (i - 1) else f' (i - 1) + 1 in assert (S.length s0 == S.length s1); assert (forall x y. x <> y ==> f' x <> f' y); introduce forall x y. x <> y ==> f x <> f y with (introduce _ ==> _ with _. ( if f x = n || f y = n then () else if f' (x - 1) < n then ( assert (f x == f' (x - 1)); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) else ( assert (f x == f' (x - 1) + 1); if f' (y - 1) < n then assert (f y == f' (y - 1)) else assert (f y == f' (y - 1) + 1) ) ) ); reveal_is_permutation_nopats s0 s1 f; f) module CM = FStar.Algebra.CommMonoid let elim_monoid_laws #a (m:CM.cm a) : Lemma ( (forall x y. {:pattern m.mult x y} m.mult x y == m.mult y x) /\ (forall x y z.{:pattern (m.mult x (m.mult y z))} m.mult x (m.mult y z) == m.mult (m.mult x y) z) /\ (forall x.{:pattern (m.mult x m.unit)} m.mult x m.unit == x) ) = introduce forall x y. m.mult x y == m.mult y x with ( m.commutativity x y ); introduce forall x y z. m.mult x (m.mult y z) == m.mult (m.mult x y) z with ( m.associativity x y z ); introduce forall x. m.mult x m.unit == x with ( m.identity x ) #push-options "--fuel 1 --ifuel 0" let rec foldm_back_append #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == m.mult (foldm_back m s1) (foldm_back m s2)) (decreases (S.length s2)) = elim_monoid_laws m; if S.length s2 = 0 then ( assert (S.append s1 s2 `S.equal` s1); assert (foldm_back m s2 == m.unit) ) else ( let s2', last = un_build s2 in calc (==) { foldm_back m (append s1 s2); (==) { assert (S.equal (append s1 s2) (S.build (append s1 s2') last)) } foldm_back m (S.build (append s1 s2') last); (==) { assert (S.equal (fst (un_build (append s1 s2))) (append s1 s2')) } m.mult last (foldm_back m (append s1 s2')); (==) { foldm_back_append m s1 s2' } m.mult last (m.mult (foldm_back m s1) (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (m.mult last (foldm_back m s2')); (==) { } m.mult (foldm_back m s1) (foldm_back m s2); } ) let foldm_back_sym #a (m:CM.cm a) (s1 s2: seq a) : Lemma (ensures foldm_back m (append s1 s2) == foldm_back m (append s2 s1)) = elim_monoid_laws m; foldm_back_append m s1 s2; foldm_back_append m s2 s1 #push-options "--fuel 2" let foldm_back_singleton (#a:_) (m:CM.cm a) (x:a) : Lemma (foldm_back m (singleton x) == x) = elim_monoid_laws m #pop-options #push-options "--fuel 0" let foldm_back3 #a (m:CM.cm a) (s1:seq a) (x:a) (s2:seq a) : Lemma (foldm_back m (S.append s1 (cons x s2)) == m.mult x (foldm_back m (S.append s1 s2))) = calc (==) { foldm_back m (S.append s1 (cons x s2)); (==) { foldm_back_append m s1 (cons x s2) } m.mult (foldm_back m s1) (foldm_back m (cons x s2)); (==) { foldm_back_append m (singleton x) s2 } m.mult (foldm_back m s1) (m.mult (foldm_back m (singleton x)) (foldm_back m s2)); (==) { foldm_back_singleton m x } m.mult (foldm_back m s1) (m.mult x (foldm_back m s2)); (==) { elim_monoid_laws m } m.mult x (m.mult (foldm_back m s1) (foldm_back m s2)); (==) { foldm_back_append m s1 s2 } m.mult x (foldm_back m (S.append s1 s2)); } #pop-options let remove_i #a (s:seq a) (i:nat{i < S.length s}) : a & seq a = let s0, s1 = split s i in head s1, append s0 (tail s1) let shift_perm' #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Tot (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) = reveal_is_permutation s0 s1 p; let s0', last = un_build s0 in let n = S.length s0' in let p' (i:nat{ i < n }) : j:nat{ j < n } = if p i < p n then p i else p i - 1 in let _, s1' = remove_i s1 (p n) in reveal_is_permutation_nopats s0' s1' p'; p' let shift_perm #a (s0 s1:seq a) (_:squash (S.length s0 == S.length s1 /\ S.length s0 > 0)) (p:seqperm s0 s1) : Pure (seqperm (fst (un_build s0)) (snd (remove_i s1 (p (S.length s0 - 1))))) (requires True) (ensures fun _ -> let n = S.length s0 - 1 in S.index s1 (p n) == S.index s0 n) = reveal_is_permutation s0 s1 p; shift_perm' s0 s1 () p let seqperm_len #a (s0 s1:seq a) (p:seqperm s0 s1) : Lemma (ensures S.length s0 == S.length s1) = reveal_is_permutation s0 s1 p
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Sequence.Util.fst.checked", "FStar.Sequence.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Calc.fsti.checked", "FStar.Algebra.CommMonoid.fst.checked" ], "interface_file": true, "source_file": "FStar.Sequence.Permutation.fst" }
[ { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Algebra.CommMonoid", "short_module": "CM" }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Calc", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": true, "full_module": "FStar.Sequence", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Sequence.Util", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 2, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Algebra.CommMonoid.cm a -> s0: FStar.Sequence.Base.seq a -> s1: FStar.Sequence.Base.seq a -> p: FStar.Sequence.Permutation.seqperm s0 s1 -> FStar.Pervasives.Lemma (ensures FStar.Sequence.Permutation.foldm_back m s0 == FStar.Sequence.Permutation.foldm_back m s1) (decreases FStar.Sequence.Base.length s0)
FStar.Pervasives.Lemma
[ "", "lemma" ]
[]
[ "FStar.Algebra.CommMonoid.cm", "FStar.Sequence.Base.seq", "FStar.Sequence.Permutation.seqperm", "Prims.op_Equality", "Prims.int", "FStar.Sequence.Base.length", "Prims._assert", "FStar.Sequence.Base.equal", "Prims.bool", "FStar.Calc.calc_finish", "Prims.eq2", "FStar.Sequence.Permutation.foldm_back", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Algebra.CommMonoid.__proj__CM__item__mult", "FStar.Sequence.Base.append", "FStar.Sequence.Util.cons", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Sequence.Permutation.foldm_back3", "FStar.Sequence.Permutation.foldm_back_perm", "FStar.Sequence.Permutation.shift_perm", "FStar.Pervasives.Native.snd", "FStar.Sequence.Permutation.remove_i", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Mktuple2", "FStar.Sequence.Base.op_Dollar_At", "FStar.Sequence.Base.drop", "FStar.Sequence.Util.split", "FStar.Sequence.Util.un_build", "Prims.op_Subtraction", "FStar.Sequence.Permutation.seqperm_len", "Prims.l_True", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec foldm_back_perm #a m s0 s1 p : Lemma (ensures foldm_back m s0 == foldm_back m s1) (decreases (S.length s0)) =
seqperm_len s0 s1 p; if S.length s0 = 0 then (assert (S.equal s0 s1)) else (let n0 = S.length s0 - 1 in let prefix, last = un_build s0 in let prefix', suffix' = split s1 (p n0) in let last', suffix' = suffix' $@ 0, drop suffix' 1 in let s1' = snd (remove_i s1 (p n0)) in let p':seqperm prefix s1' = shift_perm s0 s1 () p in assert (last == last'); calc ( == ) { foldm_back m s1; ( == ) { assert (s1 `S.equal` (S.append prefix' (cons last' suffix'))) } foldm_back m (S.append prefix' (cons last' suffix')); ( == ) { foldm_back3 m prefix' last' suffix' } m.mult last' (foldm_back m (append prefix' suffix')); ( == ) { assert (S.equal (append prefix' suffix') s1') } m.mult last' (foldm_back m s1'); ( == ) { foldm_back_perm m prefix s1' p' } m.mult last' (foldm_back m prefix); ( == ) { () } foldm_back m s0; })
false
Hacl.Bignum.Lib.fst
Hacl.Bignum.Lib.bn_get_bits_limb
val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
let bn_get_bits_limb #t len n ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1
{ "file_name": "code/bignum/Hacl.Bignum.Lib.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 6, "end_line": 170, "start_col": 0, "start_line": 159 }
module Hacl.Bignum.Lib open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer open Hacl.Bignum.Base open Hacl.Bignum.Definitions module S = Hacl.Spec.Bignum.Lib module ST = FStar.HyperStack.ST module Loops = Lib.LoopCombinators module LSeq = Lib.Sequence #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" /// /// Get and set i-th bit of a bignum /// inline_for_extraction noextract val bn_get_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_ith_bit (as_seq h0 b) (v i)) let bn_get_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let tmp = input.(i) in (tmp >>. j) &. uint #t 1 inline_for_extraction noextract val bn_set_ith_bit: #t:limb_t -> len:size_t -> b:lbignum t len -> i:size_t{v i / bits t < v len} -> Stack unit (requires fun h -> live h b) (ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\ as_seq h1 b == S.bn_set_ith_bit (as_seq h0 b) (v i)) let bn_set_ith_bit #t len input ind = [@inline_let] let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); input.(i) <- input.(i) |. (uint #t 1 <<. j) inline_for_extraction noextract val cswap2_st: #t:limb_t -> len:size_t -> bit:limb t -> b1:lbignum t len -> b2:lbignum t len -> Stack unit (requires fun h -> live h b1 /\ live h b2 /\ disjoint b1 b2) (ensures fun h0 _ h1 -> modifies (loc b1 |+| loc b2) h0 h1 /\ (as_seq h1 b1, as_seq h1 b2) == S.cswap2 bit (as_seq h0 b1) (as_seq h0 b2)) let cswap2_st #t len bit b1 b2 = [@inline_let] let mask = uint #t 0 -. bit in [@inline_let] let spec h0 = S.cswap2_f mask in let h0 = ST.get () in loop2 h0 len b1 b2 spec (fun i -> Loops.unfold_repeati (v len) (spec h0) (as_seq h0 b1, as_seq h0 b2) (v i); let dummy = mask &. (b1.(i) ^. b2.(i)) in b1.(i) <- b1.(i) ^. dummy; b2.(i) <- b2.(i) ^. dummy ) inline_for_extraction noextract let bn_get_top_index_st (t:limb_t) (len:size_t{0 < v len}) = b:lbignum t len -> Stack (limb t) (requires fun h -> live h b) (ensures fun h0 r h1 -> modifies0 h0 h1 /\ v r == S.bn_get_top_index (as_seq h0 b)) inline_for_extraction noextract val mk_bn_get_top_index: #t:limb_t -> len:size_t{0 < v len} -> bn_get_top_index_st t len let mk_bn_get_top_index #t len b = push_frame (); let priv = create 1ul (uint #t 0) in let h0 = ST.get () in [@ inline_let] let refl h i = v (LSeq.index (as_seq h priv) 0) in [@ inline_let] let spec h0 = S.bn_get_top_index_f (as_seq h0 b) in [@ inline_let] let inv h (i:nat{i <= v len}) = modifies1 priv h0 h /\ live h priv /\ live h b /\ disjoint priv b /\ refl h i == Loops.repeat_gen i (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) in Loops.eq_repeat_gen0 (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0); Lib.Loops.for 0ul len inv (fun i -> Loops.unfold_repeat_gen (v len) (S.bn_get_top_index_t (v len)) (spec h0) (refl h0 0) (v i); let mask = eq_mask b.(i) (zeros t SEC) in let h1 = ST.get () in priv.(0ul) <- mask_select mask priv.(0ul) (size_to_limb i); mask_select_lemma mask (LSeq.index (as_seq h1 priv) 0) (size_to_limb i)); let res = priv.(0ul) in pop_frame (); res let bn_get_top_index_u32 len: bn_get_top_index_st U32 len = mk_bn_get_top_index #U32 len let bn_get_top_index_u64 len: bn_get_top_index_st U64 len = mk_bn_get_top_index #U64 len inline_for_extraction noextract val bn_get_top_index: #t:_ -> len:_ -> bn_get_top_index_st t len let bn_get_top_index #t = match t with | U32 -> bn_get_top_index_u32 | U64 -> bn_get_top_index_u64 inline_for_extraction noextract val bn_get_bits_limb: #t:limb_t -> len:size_t -> n:lbignum t len -> ind:size_t{v ind / bits t < v len} -> Stack (limb t) (requires fun h -> live h n) (ensures fun h0 r h1 -> h0 == h1 /\ r == S.bn_get_bits_limb (as_seq h0 n) (v ind))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.Loops.fsti.checked", "Lib.LoopCombinators.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Bignum.Lib.fst.checked", "Hacl.Bignum.Definitions.fst.checked", "Hacl.Bignum.Base.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.fst.checked" ], "interface_file": false, "source_file": "Hacl.Bignum.Lib.fst" }
[ { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "Lib.LoopCombinators", "short_module": "Loops" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Lib", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Bignum.Definitions", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum.Base", "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.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Bignum", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
len: Lib.IntTypes.size_t -> n: Hacl.Bignum.Definitions.lbignum t len -> ind: Lib.IntTypes.size_t{Lib.IntTypes.v ind / Lib.IntTypes.bits t < Lib.IntTypes.v len} -> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t)
FStar.HyperStack.ST.Stack
[]
[]
[ "Hacl.Bignum.Definitions.limb_t", "Lib.IntTypes.size_t", "Hacl.Bignum.Definitions.lbignum", "Prims.b2t", "Prims.op_LessThan", "Prims.op_Division", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "Lib.IntTypes.bits", "Prims.op_AmpAmp", "Lib.IntTypes.op_Less_Dot", "Lib.IntTypes.op_Plus_Bang", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.op_Bar_Dot", "Lib.IntTypes.SEC", "Hacl.Bignum.Definitions.limb", "Lib.IntTypes.int_t", "Lib.IntTypes.op_Less_Less_Dot", "Lib.IntTypes.op_Subtraction_Bang", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Prims.bool", "Lib.IntTypes.op_Greater_Greater_Dot", "Prims.unit", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "Lib.IntTypes.op_Percent_Dot", "Lib.IntTypes.op_Slash_Dot", "Lib.IntTypes.size" ]
[]
false
true
false
false
false
let bn_get_bits_limb #t len n ind =
[@@ inline_let ]let pbits = size (bits t) in let i = ind /. pbits in assert (v i == v ind / bits t); let j = ind %. pbits in assert (v j == v ind % bits t); let p1 = n.(i) >>. j in if i +! 1ul <. len && 0ul <. j then p1 |. (n.(i +! 1ul) <<. (pbits -! j)) else p1
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test5
val test5 (b1 b2 b3: ref) : SteelT unit (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3))
val test5 (b1 b2 b3: ref) : SteelT unit (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3))
let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1)
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 80, "start_col": 0, "start_line": 75 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "SteelFramingTestSuite.ref", "SteelFramingTestSuite.write", "Prims.op_Addition", "Prims.unit", "Prims.int", "SteelFramingTestSuite.read", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test5 (b1 b2 b3: ref) : SteelT unit (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b2) `star` (ptr b1)) `star` (ptr b3)) =
let x = read b3 in write b2 (x + 1)
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_nat_is_pow
val lemma_pow_nat_is_pow: a:int -> b:nat -> Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
val lemma_pow_nat_is_pow: a:int -> b:nat -> Lemma (pow a b == LE.pow mk_nat_comm_monoid a b)
let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 38, "start_col": 0, "start_line": 29 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.int -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b == Lib.Exponentiation.Definition.pow Lib.NatMod.mk_nat_comm_monoid a b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.nat", "Prims.op_Equality", "Lib.Exponentiation.Definition.lemma_pow0", "Prims.unit", "Lib.NatMod.lemma_pow0", "Prims.bool", "Lib.Exponentiation.Definition.lemma_pow_unfold", "Lib.NatMod.lemma_pow_nat_is_pow", "Prims.op_Subtraction", "Lib.NatMod.lemma_pow_unfold", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_comm_monoid" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_nat_is_pow a b =
let k = mk_nat_comm_monoid in if b = 0 then (lemma_pow0 a; LE.lemma_pow0 k a) else (lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; ())
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_gt_zero
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
val lemma_pow_gt_zero: a:pos -> b:nat -> Lemma (pow a b > 0) [SMTPat (pow a b)]
let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 19, "start_col": 0, "start_line": 15 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.pos -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b > 0) [SMTPat (Lib.NatMod.pow a b)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.nat", "Prims.op_Equality", "Prims.int", "Lib.NatMod.lemma_pow0", "Prims.bool", "Lib.NatMod.lemma_pow_gt_zero", "Prims.op_Subtraction", "Prims.unit", "Lib.NatMod.lemma_pow_unfold" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_gt_zero a b =
if b = 0 then lemma_pow0 a else (lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1))
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_zero
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
val lemma_pow_zero: b:pos -> Lemma (pow 0 b = 0)
let lemma_pow_zero b = lemma_pow_unfold 0 b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 22, "end_line": 42, "start_col": 0, "start_line": 41 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.pos -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow 0 b = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.lemma_pow_unfold", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_pow_zero b =
lemma_pow_unfold 0 b
false
Hacl.HPKE.Curve64_CP256_SHA256.fsti
Hacl.HPKE.Curve64_CP256_SHA256.cs
val cs:S.ciphersuite
val cs:S.ciphersuite
let cs:S.ciphersuite = (DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256)
{ "file_name": "code/hpke/Hacl.HPKE.Curve64_CP256_SHA256.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 102, "end_line": 10, "start_col": 0, "start_line": 10 }
module Hacl.HPKE.Curve64_CP256_SHA256 open Hacl.Impl.HPKE module S = Spec.Agile.HPKE module DH = Spec.Agile.DH module AEAD = Spec.Agile.AEAD module Hash = Spec.Agile.Hash
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.HPKE.fsti.checked", "Spec.Agile.Hash.fsti.checked", "Spec.Agile.DH.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "Hacl.Impl.HPKE.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "Hacl.HPKE.Curve64_CP256_SHA256.fsti" }
[ { "abbrev": true, "full_module": "Spec.Agile.Hash", "short_module": "Hash" }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "AEAD" }, { "abbrev": true, "full_module": "Spec.Agile.DH", "short_module": "DH" }, { "abbrev": true, "full_module": "Spec.Agile.HPKE", "short_module": "S" }, { "abbrev": false, "full_module": "Hacl.Impl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "Hacl.HPKE", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.Agile.HPKE.ciphersuite
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.Mktuple4", "Spec.Agile.DH.algorithm", "Spec.Agile.HPKE.hash_algorithm", "Spec.Agile.HPKE.aead", "Spec.Hash.Definitions.hash_alg", "Spec.Agile.DH.DH_Curve25519", "Spec.Hash.Definitions.SHA2_256", "Spec.Agile.HPKE.Seal", "Spec.Agile.AEAD.CHACHA20_POLY1305" ]
[]
false
false
false
true
false
let cs:S.ciphersuite =
(DH.DH_Curve25519, Hash.SHA2_256, S.Seal AEAD.CHACHA20_POLY1305, Hash.SHA2_256)
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_ge_zero
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
val lemma_pow_ge_zero: a:nat -> b:nat -> Lemma (pow a b >= 0) [SMTPat (pow a b)]
let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 35, "end_line": 26, "start_col": 0, "start_line": 22 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.nat -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b >= 0) [SMTPat (Lib.NatMod.pow a b)]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Lib.NatMod.lemma_pow0", "Prims.bool", "Lib.NatMod.lemma_pow_ge_zero", "Prims.op_Subtraction", "Prims.unit", "Lib.NatMod.lemma_pow_unfold" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_ge_zero a b =
if b = 0 then lemma_pow0 a else (lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1))
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_one
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
val lemma_pow_one: b:nat -> Lemma (pow 1 b = 1)
let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 26, "end_line": 48, "start_col": 0, "start_line": 45 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow 1 b = 1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Lib.NatMod.lemma_pow_nat_is_pow", "Prims.unit", "Lib.Exponentiation.Definition.lemma_pow_one", "Prims.int", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_comm_monoid" ]
[]
true
false
true
false
false
let lemma_pow_one b =
let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mul
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
val lemma_pow_mul: x:int -> n:nat -> m:nat -> Lemma (pow (pow x n) m = pow x (n * m))
let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m)
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 64, "start_col": 0, "start_line": 59 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> n: Prims.nat -> m: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow (Lib.NatMod.pow x n) m = Lib.NatMod.pow x (n * m))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.nat", "Lib.NatMod.lemma_pow_nat_is_pow", "FStar.Mul.op_Star", "Prims.unit", "Lib.NatMod.pow", "Lib.Exponentiation.Definition.lemma_pow_mul", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_comm_monoid" ]
[]
true
false
true
false
false
let lemma_pow_mul x n m =
let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m)
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mul_base
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
val lemma_pow_mul_base: a:int -> b:int -> n:nat -> Lemma (pow a n * pow b n == pow (a * b) n)
let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 79, "start_col": 0, "start_line": 74 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.int -> b: Prims.int -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a n * Lib.NatMod.pow b n == Lib.NatMod.pow (a * b) n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.nat", "Lib.NatMod.lemma_pow_nat_is_pow", "FStar.Mul.op_Star", "Prims.unit", "Lib.Exponentiation.Definition.lemma_pow_mul_base", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_comm_monoid" ]
[]
true
false
true
false
false
let lemma_pow_mul_base a b n =
let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_double
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
val lemma_pow_double: a:int -> b:nat -> Lemma (pow (a * a) b == pow a (b + b))
let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b)
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 71, "start_col": 0, "start_line": 67 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.int -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow (a * a) b == Lib.NatMod.pow a (b + b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.nat", "Lib.NatMod.lemma_pow_nat_is_pow", "Prims.op_Addition", "Prims.unit", "FStar.Mul.op_Star", "Lib.Exponentiation.Definition.lemma_pow_double", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_comm_monoid" ]
[]
true
false
true
false
false
let lemma_pow_double a b =
let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b)
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_add
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
val lemma_pow_add: x:int -> n:nat -> m:nat -> Lemma (pow x n * pow x m = pow x (n + m))
let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m)
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 32, "end_line": 56, "start_col": 0, "start_line": 51 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Prims.int -> n: Prims.nat -> m: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow x n * Lib.NatMod.pow x m = Lib.NatMod.pow x (n + m))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.nat", "Lib.NatMod.lemma_pow_nat_is_pow", "Prims.op_Addition", "Prims.unit", "Lib.Exponentiation.Definition.lemma_pow_add", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_comm_monoid" ]
[]
true
false
true
false
false
let lemma_pow_add x n m =
let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m)
false
LList.ST.fst
LList.ST.elim_aux
val elim_aux (#opened: _) (#a: Type0) (hd: G.erased a) (tl: G.erased (list a)) (ll: llist a) : STGhost (G.erased (llist_node a)) opened (is_list ll (G.reveal hd :: tl)) (fun node -> (pts_to ll full_perm node) `star` (is_list node.next tl)) (requires True) (ensures fun node -> eq2 #a node.data hd)
val elim_aux (#opened: _) (#a: Type0) (hd: G.erased a) (tl: G.erased (list a)) (ll: llist a) : STGhost (G.erased (llist_node a)) opened (is_list ll (G.reveal hd :: tl)) (fun node -> (pts_to ll full_perm node) `star` (is_list node.next tl)) (requires True) (ensures fun node -> eq2 #a node.data hd)
let elim_aux (#opened:_) (#a:Type0) (hd:G.erased a) (tl:G.erased (list a)) (ll:llist a) : STGhost (G.erased (llist_node a)) opened (is_list ll (G.reveal hd::tl)) (fun node -> pts_to ll full_perm node `star` is_list node.next tl) (requires True) (ensures fun node -> eq2 #a node.data hd) = assert (is_list ll (G.reveal hd::tl) == exists_ (fun node -> pts_to ll full_perm node `star` pure (eq2 #a node.data hd) `star` is_list node.next tl)) by (T.norm [delta_only [`%is_list]; zeta; iota]); rewrite (is_list ll (G.reveal hd::tl)) (exists_ (fun node -> pts_to ll full_perm node `star` pure (eq2 #a node.data hd) `star` is_list node.next tl)); let node = elim_exists () in elim_pure (eq2 _ _); node
{ "file_name": "share/steel/examples/steel/LList.ST.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 8, "end_line": 98, "start_col": 0, "start_line": 70 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Author: Aseem Rastogi *) module LList.ST open Steel.Memory open Steel.ST.Effect open Steel.ST.Util open Steel.ST.Reference #set-options "--ide_id_info_off" let rec is_list #a ll l : Tot vprop (decreases l) = match l with | [] -> pure (ll == null) | hd::tl -> exists_ (fun (node:llist_node a) -> pts_to ll full_perm node `star` pure (node.data == hd) `star` is_list node.next tl) let empty a = null module T = FStar.Tactics let intro #_ #_ l node ll _ = intro_pure (node.data == Cons?.hd l); intro_exists node (fun node -> pts_to ll full_perm node `star` pure (node.data == Cons?.hd l) `star` is_list node.next (Cons?.tl l)); assert (exists_ (fun node -> pts_to ll full_perm node `star` pure (node.data == Cons?.hd l) `star` is_list node.next (Cons?.tl l)) == is_list ll (Cons?.hd l::Cons?.tl l)) by (T.norm [delta_only [`%is_list]; zeta; iota]); rewrite (exists_ (fun node -> pts_to ll full_perm node `star` pure (node.data == Cons?.hd l) `star` is_list node.next (Cons?.tl l))) (is_list ll l)
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Reference.fsti.checked", "Steel.ST.Effect.fsti.checked", "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "LList.ST.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": false, "full_module": "Steel.ST.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "Steel.ST.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "LList", "short_module": null }, { "abbrev": false, "full_module": "LList", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
hd: FStar.Ghost.erased a -> tl: FStar.Ghost.erased (Prims.list a) -> ll: LList.ST.llist a -> Steel.ST.Effect.Ghost.STGhost (FStar.Ghost.erased (LList.ST.llist_node a))
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "FStar.Ghost.erased", "Prims.list", "LList.ST.llist", "LList.ST.llist_node", "Prims.unit", "Steel.ST.Util.elim_pure", "Prims.eq2", "LList.ST.__proj__Mkllist_node__item__data", "FStar.Ghost.reveal", "Steel.ST.Util.elim_exists", "Steel.Effect.Common.VStar", "Steel.ST.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.ST.Util.pure", "LList.ST.is_list", "LList.ST.__proj__Mkllist_node__item__next", "Steel.Effect.Common.vprop", "Steel.ST.Util.rewrite", "Prims.Cons", "Steel.ST.Util.exists_", "Steel.Effect.Common.star", "FStar.Tactics.Effect.assert_by_tactic", "FStar.Stubs.Tactics.V1.Builtins.norm", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta_only", "Prims.string", "Prims.Nil", "FStar.Pervasives.zeta", "FStar.Pervasives.iota", "Prims.l_True" ]
[]
false
true
false
false
false
let elim_aux (#opened: _) (#a: Type0) (hd: G.erased a) (tl: G.erased (list a)) (ll: llist a) : STGhost (G.erased (llist_node a)) opened (is_list ll (G.reveal hd :: tl)) (fun node -> (pts_to ll full_perm node) `star` (is_list node.next tl)) (requires True) (ensures fun node -> eq2 #a node.data hd) =
FStar.Tactics.Effect.assert_by_tactic (is_list ll (G.reveal hd :: tl) == exists_ (fun node -> ((pts_to ll full_perm node) `star` (pure (eq2 #a node.data hd))) `star` (is_list node.next tl))) (fun _ -> (); (T.norm [delta_only [`%is_list]; zeta; iota])); rewrite (is_list ll (G.reveal hd :: tl)) (exists_ (fun node -> ((pts_to ll full_perm node) `star` (pure (eq2 #a node.data hd))) `star` (is_list node.next tl))); let node = elim_exists () in elim_pure (eq2 _ _); node
false
Lib.NatMod.fst
Lib.NatMod.lemma_mul_mod_assoc
val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c))
val lemma_mul_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod (mul_mod a b) c == mul_mod a (mul_mod b c))
let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 118, "start_col": 0, "start_line": 109 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.mul_mod (Lib.NatMod.mul_mod a b) c == Lib.NatMod.mul_mod a (Lib.NatMod.mul_mod b c) )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "FStar.Calc.calc_finish", "Prims.int", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Prims.squash", "FStar.Math.Lemmas.paren_mul_right", "FStar.Math.Lemmas.lemma_mod_mul_distr_r" ]
[]
false
false
true
false
false
let lemma_mul_mod_assoc #m a b c =
calc ( == ) { (a * b % m) * c % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; ( == ) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; }
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if11
val test_if11: Prims.unit -> SteelT ref emp ptr
val test_if11: Prims.unit -> SteelT ref emp ptr
let test_if11 () : SteelT ref emp ptr = let r = alloc 0 in if true then return r else return r
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 37, "end_line": 166, "start_col": 0, "start_line": 164 }
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module SteelFramingTestSuite open Steel.Memory open Steel.Effect /// A collection of small unit tests for the framing tactic assume val p : vprop assume val f (x:int) : SteelT unit p (fun _ -> p) let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p) = f 0; () assume val ref : Type0 assume val ptr (_:ref) : vprop assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y) assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp) assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r) assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r) let unused x = x // work around another gensym heisenbug let test0 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = read b1 in x let test1 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b1 `star` ptr b2 `star` ptr b3) = let x = (let y = read b1 in y) in x let test2 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b3 `star` ptr b2 `star` ptr b1) = let x = read b1 in x let test3 (b1 b2 b3: ref) : SteelT int (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in x let test4 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 x let test5 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in write b2 (x + 1) let test6 (b1 b2 b3: ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = let x = read b3 in let b4 = alloc x in write b2 (x + 1); free b4 // With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification // When solving this equality, we have the goal // (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r) // with x and r in the context of ?u19 // Not normalizing allows us to solve it as a function applied to x and r // Normalizing would lead to solve it to an slprop with x and r in the context, // but which would later fail when trying to prove the equivalence with (fun r -> ptr r) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop () let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ()) let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r) = if b then alloc 0 else alloc 1 let test_if6 (b:bool) : SteelT ref emp (fun r -> ptr r) = let r = if b then alloc 0 else alloc 1 in let x = read r in write r 0; r (* First test with different (but equivalent) slprops in both branches *) let test_if7 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0 (* Test with different slprops in both branches. The second branch captures the outer frame in its context *) let test_if8 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0); write r2 0 let test_if9 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = write r1 0; if b then (write r1 0) else (write r2 0); write r2 0; if b then (write r1 0) else (write r2 0); write r1 0 (* Leave out some extra slprop outside of if_then_else *) let test_if10 (b:bool) (r1 r2 r3: ref) : SteelT unit (ptr r1 `star` ptr r2 `star` ptr r3) (fun _ -> ptr r1 `star` ptr r2 `star` ptr r3) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "SteelFramingTestSuite.fst" }
[ { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": 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 -> Steel.Effect.SteelT SteelFramingTestSuite.ref
Steel.Effect.SteelT
[]
[]
[ "Prims.unit", "Steel.Effect.Atomic.return", "SteelFramingTestSuite.ref", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop", "SteelFramingTestSuite.alloc", "Steel.Effect.Common.emp" ]
[]
false
true
false
false
false
let test_if11 () : SteelT ref emp ptr =
let r = alloc 0 in if true then return r else return r
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mod_base
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
val lemma_pow_mod_base: a:int -> b:nat -> n:pos -> Lemma (pow a b % n == pow (a % n) b % n)
let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 103, "start_col": 0, "start_line": 82 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.int -> b: Prims.nat -> n: Prims.pos -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b % n == Lib.NatMod.pow (a % n) b % n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.int", "Prims.nat", "Prims.pos", "Prims.op_Equality", "Lib.NatMod.lemma_pow0", "Prims.op_Modulus", "Prims.unit", "Prims.bool", "Prims._assert", "Prims.eq2", "Lib.NatMod.pow", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "Prims.op_Subtraction", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_pow_unfold", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Lib.NatMod.lemma_pow_mod_base", "FStar.Math.Lemmas.lemma_mod_mul_distr_l" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_mod_base a b n =
if b = 0 then (lemma_pow0 a; lemma_pow0 (a % n)) else (calc ( == ) { pow a b % n; ( == ) { lemma_pow_unfold a b } a * pow a (b - 1) % n; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; ( == ) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } (a % n) * pow (a % n) (b - 1) % n; ( == ) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n))
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mod
val lemma_pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow a b % m == pow_mod #m a b)
val lemma_pow_mod: #m:pos{1 < m} -> a:nat_mod m -> b:nat -> Lemma (pow a b % m == pow_mod #m a b)
let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 47, "end_line": 186, "start_col": 0, "start_line": 186 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b % m == Lib.NatMod.pow_mod a b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Prims.nat", "Lib.NatMod.lemma_pow_mod_", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_pow_mod #n a b =
lemma_pow_mod_ n a b
false
Lib.NatMod.fst
Lib.NatMod.lemma_add_mod_one
val lemma_add_mod_one: #m:pos -> a:nat_mod m -> Lemma (add_mod a 0 == a)
val lemma_add_mod_one: #m:pos -> a:nat_mod m -> Lemma (add_mod a 0 == a)
let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 211, "start_col": 0, "start_line": 210 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.add_mod a 0 == a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "FStar.Math.Lemmas.small_mod", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_add_mod_one #m a =
Math.Lemmas.small_mod a m
false
FStar.UInt8.fsti
FStar.UInt8.eq
val eq (a b: t) : Tot bool
val eq (a b: t) : Tot bool
let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 223, "start_col": 0, "start_line": 223 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt.eq", "FStar.UInt8.n", "FStar.UInt8.v", "Prims.bool" ]
[]
false
false
false
true
false
let eq (a b: t) : Tot bool =
eq #n (v a) (v b)
false
FStar.UInt8.fsti
FStar.UInt8.n
val n : Prims.int
let n = 8
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 16, "end_line": 20, "start_col": 7, "start_line": 20 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Prims.int
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let n =
8
false
FStar.UInt8.fsti
FStar.UInt8.gte
val gte (a b: t) : Tot bool
val gte (a b: t) : Tot bool
let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 229, "start_col": 0, "start_line": 229 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt.gte", "FStar.UInt8.n", "FStar.UInt8.v", "Prims.bool" ]
[]
false
false
false
true
false
let gte (a b: t) : Tot bool =
gte #n (v a) (v b)
false
Lib.NatMod.fst
Lib.NatMod.lemma_mod_distributivity_add_left
val lemma_mod_distributivity_add_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod (add_mod a b) c == add_mod (mul_mod a c) (mul_mod b c))
val lemma_mod_distributivity_add_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod (add_mod a b) c == add_mod (mul_mod a c) (mul_mod b c))
let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 244, "start_col": 0, "start_line": 243 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.mul_mod (Lib.NatMod.add_mod a b) c == Lib.NatMod.add_mod (Lib.NatMod.mul_mod a c) (Lib.NatMod.mul_mod b c))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "Lib.NatMod.lemma_mod_distributivity_add_right", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_mod_distributivity_add_left #m a b c =
lemma_mod_distributivity_add_right c a b
false
FStar.UInt8.fsti
FStar.UInt8.gt
val gt (a b: t) : Tot bool
val gt (a b: t) : Tot bool
let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 226, "start_col": 0, "start_line": 226 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt.gt", "FStar.UInt8.n", "FStar.UInt8.v", "Prims.bool" ]
[]
false
false
false
true
false
let gt (a b: t) : Tot bool =
gt #n (v a) (v b)
false
Lib.NatMod.fst
Lib.NatMod.lemma_add_mod_assoc
val lemma_add_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (add_mod (add_mod a b) c == add_mod a (add_mod b c))
val lemma_add_mod_assoc: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (add_mod (add_mod a b) c == add_mod a (add_mod b c))
let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 3, "end_line": 223, "start_col": 0, "start_line": 214 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.add_mod (Lib.NatMod.add_mod a b) c == Lib.NatMod.add_mod a (Lib.NatMod.add_mod b c) )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.add_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_plus_distr_r" ]
[]
false
false
true
false
false
let lemma_add_mod_assoc #m a b c =
calc ( == ) { add_mod (add_mod a b) c; ( == ) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; ( == ) { () } (a + (b + c)) % m; ( == ) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); }
false
Lib.NatMod.fst
Lib.NatMod.lemma_mod_distributivity_sub_left
val lemma_mod_distributivity_sub_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod (sub_mod a b) c == sub_mod (mul_mod a c) (mul_mod b c))
val lemma_mod_distributivity_sub_left: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod (sub_mod a b) c == sub_mod (mul_mod a c) (mul_mod b c))
let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 264, "start_col": 0, "start_line": 263 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.mul_mod (Lib.NatMod.sub_mod a b) c == Lib.NatMod.sub_mod (Lib.NatMod.mul_mod a c) (Lib.NatMod.mul_mod b c))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "Lib.NatMod.lemma_mod_distributivity_sub_right", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_mod_distributivity_sub_left #m a b c =
lemma_mod_distributivity_sub_right c a b
false
FStar.UInt8.fsti
FStar.UInt8.lte
val lte (a b: t) : Tot bool
val lte (a b: t) : Tot bool
let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 51, "end_line": 235, "start_col": 0, "start_line": 235 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt.lte", "FStar.UInt8.n", "FStar.UInt8.v", "Prims.bool" ]
[]
false
false
false
true
false
let lte (a b: t) : Tot bool =
lte #n (v a) (v b)
false
Lib.NatMod.fst
Lib.NatMod.lemma_mod_distributivity_add_right
val lemma_mod_distributivity_add_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod a (add_mod b c) == add_mod (mul_mod a b) (mul_mod a c))
val lemma_mod_distributivity_add_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod a (add_mod b c) == add_mod (mul_mod a b) (mul_mod a c))
let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 240, "start_col": 0, "start_line": 229 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.mul_mod a (Lib.NatMod.add_mod b c) == Lib.NatMod.add_mod (Lib.NatMod.mul_mod a b) (Lib.NatMod.mul_mod a c))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.mul_mod", "Lib.NatMod.add_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Modulus", "Prims.op_Addition", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.distributivity_add_right", "FStar.Math.Lemmas.modulo_distributivity" ]
[]
false
false
true
false
false
let lemma_mod_distributivity_add_right #m a b c =
calc ( == ) { mul_mod a (add_mod b c); ( == ) { () } a * ((b + c) % m) % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; ( == ) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; ( == ) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); }
false
FStar.UInt8.fsti
FStar.UInt8.lt
val lt (a b: t) : Tot bool
val lt (a b: t) : Tot bool
let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 49, "end_line": 232, "start_col": 0, "start_line": 232 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt.lt", "FStar.UInt8.n", "FStar.UInt8.v", "Prims.bool" ]
[]
false
false
false
true
false
let lt (a b: t) : Tot bool =
lt #n (v a) (v b)
false
Lib.NatMod.fst
Lib.NatMod.pow_eq
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n)
let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1)
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 23, "end_line": 292, "start_col": 0, "start_line": 290 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 0, "max_fuel": 1, "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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Prims.nat -> n: Prims.nat -> FStar.Pervasives.Lemma (ensures FStar.Math.Fermat.pow a n == Lib.NatMod.pow a n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.op_Equality", "Prims.int", "Prims.bool", "Lib.NatMod.pow_eq", "Prims.op_Subtraction", "Prims.unit" ]
[ "recursion" ]
false
false
true
false
false
let rec pow_eq a n =
if n = 0 then () else pow_eq a (n - 1)
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_nat_mod_is_pow
val lemma_pow_nat_mod_is_pow: #n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (pow a b % n == LE.pow (mk_nat_mod_comm_monoid n) a b)
val lemma_pow_nat_mod_is_pow: #n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (pow a b % n == LE.pow (mk_nat_mod_comm_monoid n) a b)
let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 15, "end_line": 207, "start_col": 0, "start_line": 189 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod n -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow a b % n == Lib.Exponentiation.Definition.pow (Lib.NatMod.mk_nat_mod_comm_monoid n) a b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Prims.nat", "Prims.op_Equality", "Prims.int", "Lib.Exponentiation.Definition.lemma_pow0", "Prims.unit", "Lib.NatMod.lemma_pow0", "Prims.bool", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "Lib.NatMod.pow", "Lib.Exponentiation.Definition.pow", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Lib.Exponentiation.Definition.__proj__Mkcomm_monoid__item__mul", "Prims.op_Subtraction", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_pow_unfold", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Lib.NatMod.lemma_pow_nat_mod_is_pow", "Lib.Exponentiation.Definition.lemma_pow_unfold", "Lib.Exponentiation.Definition.comm_monoid", "Lib.NatMod.mk_nat_mod_comm_monoid" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_nat_mod_is_pow #n a b =
let k = mk_nat_mod_comm_monoid n in if b = 0 then (lemma_pow0 a; LE.lemma_pow0 k a) else (calc ( == ) { pow a b % n; ( == ) { lemma_pow_unfold a b } a * pow a (b - 1) % n; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; ( == ) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; ( == ) { () } k.LE.mul a (LE.pow k a (b - 1)); ( == ) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; ())
false
FStar.UInt8.fsti
FStar.UInt8.op_Plus_Hat
val op_Plus_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Plus_Hat = add
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 316, "start_col": 7, "start_line": 316 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.add" ]
[]
false
false
false
false
false
let op_Plus_Hat =
add
false
Lib.NatMod.fst
Lib.NatMod.lemma_mod_distributivity_sub_right
val lemma_mod_distributivity_sub_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod a (sub_mod b c) == sub_mod (mul_mod a b) (mul_mod a c))
val lemma_mod_distributivity_sub_right: #m:pos -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m -> Lemma (mul_mod a (sub_mod b c) == sub_mod (mul_mod a b) (mul_mod a c))
let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 260, "start_col": 0, "start_line": 247 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.mul_mod a (Lib.NatMod.sub_mod b c) == Lib.NatMod.sub_mod (Lib.NatMod.mul_mod a b) (Lib.NatMod.mul_mod a c))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Lib.NatMod.nat_mod", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.mul_mod", "Lib.NatMod.sub_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Modulus", "Prims.op_Subtraction", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "FStar.Math.Lemmas.distributivity_sub_right", "FStar.Math.Lemmas.lemma_mod_plus_distr_l", "Prims.op_Minus", "FStar.Math.Lemmas.lemma_mod_sub_distr" ]
[]
false
false
true
false
false
let lemma_mod_distributivity_sub_right #m a b c =
calc ( == ) { mul_mod a (sub_mod b c); ( == ) { () } a * ((b - c) % m) % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; ( == ) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; ( == ) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; ( == ) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); }
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_prime_one
val lemma_div_mod_prime_one: #m:pos{1 < m} -> a:nat_mod m -> Lemma (div_mod a 1 == a)
val lemma_div_mod_prime_one: #m:pos{1 < m} -> a:nat_mod m -> Lemma (div_mod a 1 == a)
let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 319, "start_col": 0, "start_line": 316 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a 1 == a)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "FStar.Math.Lemmas.small_mod", "Prims.unit", "Lib.NatMod.lemma_pow_one", "Prims.op_Subtraction", "Lib.NatMod.lemma_pow_mod" ]
[]
true
false
true
false
false
let lemma_div_mod_prime_one #m a =
lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m
false
FStar.UInt8.fsti
FStar.UInt8.op_Plus_Percent_Hat
val op_Plus_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Plus_Percent_Hat = add_mod
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 318, "start_col": 7, "start_line": 318 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.add_mod" ]
[]
false
false
false
false
false
let op_Plus_Percent_Hat =
add_mod
false
FStar.UInt8.fsti
FStar.UInt8.op_Subtraction_Hat
val op_Subtraction_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Subtraction_Hat = sub
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 319, "start_col": 7, "start_line": 319 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.sub" ]
[]
false
false
false
false
false
let op_Subtraction_Hat =
sub
false
FStar.UInt8.fsti
FStar.UInt8.op_Plus_Question_Hat
val op_Plus_Question_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Plus_Question_Hat = add_underspec
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 317, "start_col": 7, "start_line": 317 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.add_underspec" ]
[]
false
false
false
false
false
let op_Plus_Question_Hat =
add_underspec
false
FStar.UInt8.fsti
FStar.UInt8.op_Subtraction_Percent_Hat
val op_Subtraction_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Subtraction_Percent_Hat = sub_mod
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 321, "start_col": 7, "start_line": 321 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.sub_mod" ]
[]
false
false
false
false
false
let op_Subtraction_Percent_Hat =
sub_mod
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_eq_mul_mod
val lemma_div_mod_eq_mul_mod: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma ((div_mod a b = c) == (a = mul_mod c b))
val lemma_div_mod_eq_mul_mod: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma ((div_mod a b = c) == (a = mul_mod c b))
let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 399, "start_col": 0, "start_line": 397 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m {b <> 0} -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a b = c == (a = Lib.NatMod.mul_mod c b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Lib.NatMod.lemma_div_mod_eq_mul_mod2", "Prims.unit", "Lib.NatMod.lemma_div_mod_eq_mul_mod1" ]
[]
true
false
true
false
false
let lemma_div_mod_eq_mul_mod #m a b c =
lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c
false
FStar.UInt8.fsti
FStar.UInt8.op_Subtraction_Question_Hat
val op_Subtraction_Question_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Subtraction_Question_Hat = sub_underspec
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 54, "end_line": 320, "start_col": 7, "start_line": 320 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.sub_underspec" ]
[]
false
false
false
false
false
let op_Subtraction_Question_Hat =
sub_underspec
false
Lib.NatMod.fst
Lib.NatMod.lemma_mul_mod_zero2
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0)
val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0)
let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 410, "start_col": 0, "start_line": 406 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos -> x: Prims.int -> y: Prims.int -> FStar.Pervasives.Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.int", "Prims.op_Equality", "Prims.op_Modulus", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Prims.bool", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Prims.unit" ]
[]
false
false
true
false
false
let lemma_mul_mod_zero2 n x y =
if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_prime
val lemma_div_mod_prime: #m:prime -> a:nat_mod m{a <> 0} -> Lemma (div_mod a a == 1)
val lemma_div_mod_prime: #m:prime -> a:nat_mod m{a <> 0} -> Lemma (div_mod a a == 1)
let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 313, "start_col": 0, "start_line": 296 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m {a <> 0} -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a a == 1)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Lib.NatMod.pow_mod", "Prims.op_Subtraction", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Math.Fermat.pow", "Lib.NatMod.pow", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_pow_mod", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "Lib.NatMod.lemma_pow_add", "Lib.NatMod.lemma_pow1", "Lib.NatMod.pow_eq", "FStar.Math.Fermat.fermat_alt", "Prims._assert", "Prims.l_and", "FStar.Math.Lemmas.small_mod" ]
[]
false
false
true
false
false
let lemma_div_mod_prime #m a =
Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc ( == ) { pow_mod #m a (m - 2) * a % m; ( == ) { lemma_pow_mod #m a (m - 2) } (pow a (m - 2) % m) * a % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; ( == ) { (lemma_pow1 a; lemma_pow_add a (m - 2) 1) } pow a (m - 1) % m; ( == ) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; ( == ) { Fermat.fermat_alt m a } 1; }
false
FStar.UInt8.fsti
FStar.UInt8.op_Slash_Hat
val op_Slash_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t
let op_Slash_Hat = div
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 325, "start_col": 7, "start_line": 325 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.div" ]
[]
false
false
false
false
false
let op_Slash_Hat =
div
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mod_prime_zero
val lemma_pow_mod_prime_zero: #m:prime -> a:nat_mod m -> b:pos -> Lemma (pow_mod #m a b = 0 <==> a = 0)
val lemma_pow_mod_prime_zero: #m:prime -> a:nat_mod m -> b:pos -> Lemma (pow_mod #m a b = 0 <==> a = 0)
let lemma_pow_mod_prime_zero #m a b = lemma_pow_mod #m a b; Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b; Classical.move_requires lemma_pow_zero b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 438, "start_col": 0, "start_line": 435 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n let lemma_mul_mod_prime_zero #m a b = Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0) #push-options "--z3rlimit 150" let rec lemma_pow_mod_prime_zero_ #m a b = if b = 1 then lemma_pow1 a else begin let r1 = pow a (b - 1) % m in lemma_pow_unfold a b; assert (a * pow a (b - 1) % m = 0); Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m; lemma_mul_mod_prime_zero #m a r1; //assert (a = 0 \/ r1 = 0); if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "Lib", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Prims.pos -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow_mod a b = 0 <==> a = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.pos", "FStar.Classical.move_requires", "Prims.l_True", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Lib.NatMod.pow", "Lib.NatMod.lemma_pow_zero", "Prims.unit", "FStar.Classical.move_requires_2", "Prims.op_Modulus", "Lib.NatMod.lemma_pow_mod_prime_zero_", "Lib.NatMod.lemma_pow_mod" ]
[]
false
false
true
false
false
let lemma_pow_mod_prime_zero #m a b =
lemma_pow_mod #m a b; Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b; Classical.move_requires lemma_pow_zero b
false